Bugfix: PIS Codes not being found for GW services

Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
Fred Boniface 2023-07-11 22:33:10 +01:00
parent e79985cb5a
commit 24b882ce5f
2 changed files with 5 additions and 5 deletions

View File

@ -1,6 +1,6 @@
const version = { const version = {
api: ['/api/v1/','/api/v2'], api: ['/api/v1/','/api/v2'],
app: '2023.7.3' app: '2023.7.4'
}; };
module.exports = version; module.exports = version;

View File

@ -20,14 +20,14 @@ async function findByHeadcodeToday(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) {
if (trainData /* CONDTION NEEDS CHANGIN WHEN DBMAN UPDATED /*pis.supported.includes(trainData?.operator)*/) { if (pis.supported.includes(trainData[trainService]['operator'])) {
// Search for PIS Code for each service // Search for PIS Code for each service
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[trainService]['operator'] === 'GW') {
trainData[trainService]['pis'] = '0015'; // Not in Service code trainData[trainService]['pis'] = '0015'; // Not in Service code
// '0015' is a string becuase 0015 is not a valid number.. // '0015' is a string becuase 0015 is not a valid number..
} }
@ -61,13 +61,13 @@ async function findByHeadcode(date, headcode) {
let preparedData = []; let preparedData = [];
for (let trainService in trainData) { for (let trainService in trainData) {
// Search for PIS Code for each service if supported by PIS services // Search for PIS Code for each service if supported by PIS services
if (pis.supported.includes(trainData?.operator)) { if (pis.supported.includes(trainData[trainService]['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 if (trainData?.operator === 'GW' && !tiplocList.length) { } else if (trainData[trainService]['operator'] === 'GW' && !tiplocList.length) {
// Not in Service code - for GWR Only // Not in Service code - for GWR Only
trainData[trainService]['pis'] = '0015'; trainData[trainService]['pis'] = '0015';
} }