Only return 'Not in Service' code 0015 for GW services

Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
Fred Boniface 2023-07-02 21:18:44 +01:00
parent ea8dd65a8d
commit 45d0e0a2c0

View File

@ -47,6 +47,7 @@ async function findByHeadcode(date, headcode) {
} else {
searchDate = new Date(date);
}
searchDate.setHours(12,0,0); // Set to midday to avoid any timezone issues
const dayMap = ['su', 'm', 't', 'w', 'th', 'f', 's'];
const shortDay = dayMap[searchDate.getDay()]; // Fetch short day from map
const query = {
@ -59,15 +60,17 @@ async function findByHeadcode(date, headcode) {
let trainData = await parseTrains(queryData);
let preparedData = [];
for (let trainService in trainData) {
// Search for PIS Code for each service
const tiplocList = await getPublicStops(trainData[trainService]['stops']);
//console.log(tiplocList.length); console.log(tiplocList);
if (tiplocList.length) {
const pisDetail = await pis.findByTiplocArray(tiplocList);
trainData[trainService]['pis'] = pisDetail?.[0]?.['code'] ?? 'None';
} else {
trainData[trainService]['pis'] = '0015'; // Not in Service code
// '0015' is a string otherwise it is interpreted as octal 13.
// Search for PIS Code for each service if supported by PIS services
if (pis.supported.includes(trainData?.operator)) {
const tiplocList = await getPublicStops(trainData[trainService]['stops']);
//console.log(tiplocList.length); console.log(tiplocList);
if (tiplocList.length) {
const pisDetail = await pis.findByTiplocArray(tiplocList);
trainData[trainService]['pis'] = pisDetail?.[0]?.['code'] ?? 'None';
} else if (trainData?.operator === 'GW' && !tiplocList.length) {
// Not in Service code - for GWR Only
trainData[trainService]['pis'] = '0015';
}
}
preparedData.push(trainData[trainService]);
}