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