From 66b2ba002b8be4229c6f8b99e6c4e46065df1073 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Wed, 7 Jun 2023 21:27:28 +0100 Subject: [PATCH] Find by headcode is ready Signed-off-by: Fred Boniface --- src/services/trainService.services.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/services/trainService.services.js b/src/services/trainService.services.js index cfc0d3d..23c304d 100644 --- a/src/services/trainService.services.js +++ b/src/services/trainService.services.js @@ -4,7 +4,7 @@ const clean = require('../utils/sanitizer.utils'); const pis = require('../services/pis.services'); async function findByHeadcodeToday(headcode) { - const sanitizedHeadcode = clean.removeNonAlphanumeric(headcode); + const sanitizedHeadcode = clean.removeNonAlphanumeric(headcode).toUpperCase(); log.out(`trainServiceServices.findByHeadcode: Searching for headcode ${sanitizedHeadcode}`, 'dbug'); const now = new Date(); const dayMap = ['su', 'm', 't', 'w', 'th', 'f', 's']; @@ -20,11 +20,6 @@ async function findByHeadcodeToday(headcode) { let preparedData = []; for (let trainService in trainData) { // Search for PIS Code for each service - console.log(JSON.stringify(trainData)); - // tiplocList seems to be empty - trainData[trainService] is an array, should be an object! - // Check the parseTrains it seems to be encapsulating an array in an array. - // meaning that trainData[trainService]['stops'] doesn't exist. - // I THINK: the findByTrainUid function should return a single object rather than an array const tiplocList = await getPublicStops(trainData[trainService]['stops']); //console.log(tiplocList.length); console.log(tiplocList); if (tiplocList.length) { @@ -32,6 +27,7 @@ async function findByHeadcodeToday(headcode) { 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. } preparedData.push(trainData[trainService]); } @@ -112,14 +108,18 @@ async function findByTrainUid(uid, date = new Date()) { // Date defaults to toda const stpIndicator = serviceDetail['stpIndicator']; if (stpIndicator === 'C') { - continue; + return; + //continue; } if (stpIndicator === 'N' && !thisStpIndicators.hasC) { - preparedData.push(serviceDetail); + return serviceDetail; + //preparedData.push(serviceDetail); } else if (stpIndicator === 'O' && !thisStpIndicators.hasC && !thisStpIndicators.hasN) { - preparedData.push(serviceDetail); + return serviceDetail; + //preparedData.push(serviceDetail); } else if (stpIndicator === 'P' && !thisStpIndicators.hasC && !thisStpIndicators.hasN && !thisStpIndicators.hasO) { - preparedData.push(serviceDetail); + return serviceDetail; + //preparedData.push(serviceDetail); } } return preparedData;