Bugfix: Cases where operator does not exist
Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
parent
24b882ce5f
commit
86e5c34e7f
@ -1,6 +1,6 @@
|
||||
const version = {
|
||||
api: ['/api/v1/','/api/v2'],
|
||||
app: '2023.7.4'
|
||||
app: '2023.7.5'
|
||||
};
|
||||
|
||||
module.exports = version;
|
@ -20,19 +20,19 @@ async function findByHeadcodeToday(headcode) {
|
||||
let trainData = await parseTrains(queryData);
|
||||
let preparedData = [];
|
||||
for (let trainService in trainData) {
|
||||
if (pis.supported.includes(trainData[trainService]['operator'])) {
|
||||
if (pis.supported.includes(trainService?.operator)) {
|
||||
// Search for PIS Code for each service
|
||||
const tiplocList = await getPublicStops(trainData[trainService]['stops']);
|
||||
const tiplocList = await getPublicStops(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[trainService]['operator'] === 'GW') {
|
||||
trainData[trainService]['pis'] = '0015'; // Not in Service code
|
||||
trainService['pis'] = pisDetail?.[0]?.['code'] ?? 'None';
|
||||
} else if (trainService?.operator === 'GW') {
|
||||
trainService['pis'] = '0015'; // Not in Service code
|
||||
// '0015' is a string becuase 0015 is not a valid number..
|
||||
}
|
||||
}
|
||||
preparedData.push(trainData[trainService]);
|
||||
preparedData.push(trainService);
|
||||
}
|
||||
return preparedData;
|
||||
}
|
||||
@ -59,20 +59,20 @@ async function findByHeadcode(date, headcode) {
|
||||
const queryData = await db.query('timetable', query);
|
||||
let trainData = await parseTrains(queryData);
|
||||
let preparedData = [];
|
||||
for (let trainService in trainData) {
|
||||
for (let trainService of trainData) {
|
||||
// Search for PIS Code for each service if supported by PIS services
|
||||
if (pis.supported.includes(trainData[trainService]['operator'])) {
|
||||
const tiplocList = await getPublicStops(trainData[trainService]['stops']);
|
||||
if (pis.supported.includes(trainService?.operator)) {
|
||||
const tiplocList = await getPublicStops(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[trainService]['operator'] === 'GW' && !tiplocList.length) {
|
||||
trainService.pis = pisDetail?.[0]?.['code'] ?? 'None';
|
||||
} else if (trainService.operator === 'GW' && !tiplocList.length) {
|
||||
// Not in Service code - for GWR Only
|
||||
trainData[trainService]['pis'] = '0015';
|
||||
trainService.pis = '0015';
|
||||
}
|
||||
}
|
||||
preparedData.push(trainData[trainService]);
|
||||
preparedData.push(trainService);
|
||||
}
|
||||
return preparedData;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user