Find by headcode is ready

Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
Fred Boniface 2023-06-07 21:27:28 +01:00
parent c0f0591866
commit 66b2ba002b

View File

@ -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;