Find by headcode is ready
Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
parent
c0f0591866
commit
66b2ba002b
@ -4,7 +4,7 @@ const clean = require('../utils/sanitizer.utils');
|
|||||||
const pis = require('../services/pis.services');
|
const pis = require('../services/pis.services');
|
||||||
|
|
||||||
async function findByHeadcodeToday(headcode) {
|
async function findByHeadcodeToday(headcode) {
|
||||||
const sanitizedHeadcode = clean.removeNonAlphanumeric(headcode);
|
const sanitizedHeadcode = clean.removeNonAlphanumeric(headcode).toUpperCase();
|
||||||
log.out(`trainServiceServices.findByHeadcode: Searching for headcode ${sanitizedHeadcode}`, 'dbug');
|
log.out(`trainServiceServices.findByHeadcode: Searching for headcode ${sanitizedHeadcode}`, 'dbug');
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const dayMap = ['su', 'm', 't', 'w', 'th', 'f', 's'];
|
const dayMap = ['su', 'm', 't', 'w', 'th', 'f', 's'];
|
||||||
@ -20,11 +20,6 @@ async function findByHeadcodeToday(headcode) {
|
|||||||
let preparedData = [];
|
let preparedData = [];
|
||||||
for (let trainService in trainData) {
|
for (let trainService in trainData) {
|
||||||
// Search for PIS Code for each service
|
// 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']);
|
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) {
|
||||||
@ -32,6 +27,7 @@ async function findByHeadcodeToday(headcode) {
|
|||||||
trainData[trainService]['pis'] = pisDetail?.[0]?.['code'] ?? 'None';
|
trainData[trainService]['pis'] = pisDetail?.[0]?.['code'] ?? 'None';
|
||||||
} else {
|
} else {
|
||||||
trainData[trainService]['pis'] = '0015'; // Not in Service code
|
trainData[trainService]['pis'] = '0015'; // Not in Service code
|
||||||
|
// '0015' is a string otherwise it is interpreted as octal 13.
|
||||||
}
|
}
|
||||||
preparedData.push(trainData[trainService]);
|
preparedData.push(trainData[trainService]);
|
||||||
}
|
}
|
||||||
@ -112,14 +108,18 @@ async function findByTrainUid(uid, date = new Date()) { // Date defaults to toda
|
|||||||
const stpIndicator = serviceDetail['stpIndicator'];
|
const stpIndicator = serviceDetail['stpIndicator'];
|
||||||
|
|
||||||
if (stpIndicator === 'C') {
|
if (stpIndicator === 'C') {
|
||||||
continue;
|
return;
|
||||||
|
//continue;
|
||||||
}
|
}
|
||||||
if (stpIndicator === 'N' && !thisStpIndicators.hasC) {
|
if (stpIndicator === 'N' && !thisStpIndicators.hasC) {
|
||||||
preparedData.push(serviceDetail);
|
return serviceDetail;
|
||||||
|
//preparedData.push(serviceDetail);
|
||||||
} else if (stpIndicator === 'O' && !thisStpIndicators.hasC && !thisStpIndicators.hasN) {
|
} 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) {
|
} else if (stpIndicator === 'P' && !thisStpIndicators.hasC && !thisStpIndicators.hasN && !thisStpIndicators.hasO) {
|
||||||
preparedData.push(serviceDetail);
|
return serviceDetail;
|
||||||
|
//preparedData.push(serviceDetail);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return preparedData;
|
return preparedData;
|
||||||
|
Loading…
Reference in New Issue
Block a user