diff --git a/src/configs/version.configs.js b/src/configs/version.configs.js index a530202..092689a 100644 --- a/src/configs/version.configs.js +++ b/src/configs/version.configs.js @@ -1,6 +1,6 @@ const version = { api: ['/api/v1/','/api/v2'], - app: '2023.7.4' + app: '2023.7.5' }; module.exports = version; \ No newline at end of file diff --git a/src/services/trainService.services.js b/src/services/trainService.services.js index 55e1c7f..c10a055 100644 --- a/src/services/trainService.services.js +++ b/src/services/trainService.services.js @@ -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; }