Re-implement ensureArray
Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
parent
49ad201522
commit
cf87c1a2b6
@ -1,6 +1,6 @@
|
|||||||
const version = {
|
const version = {
|
||||||
api: ['/api/v1/','/api/v2'],
|
api: ['/api/v1/','/api/v2'],
|
||||||
app: '2023.6.15'
|
app: '2023.7.1'
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = version;
|
module.exports = version;
|
@ -62,7 +62,10 @@ async function arrDepBoardStaff(CRS) {
|
|||||||
services: 'PBS'
|
services: 'PBS'
|
||||||
};
|
};
|
||||||
const api = new ldb(ldbsvKey,true);
|
const api = new ldb(ldbsvKey,true);
|
||||||
return await api.call('GetArrivalDepartureBoardByCRS',options,false,false);
|
let data = await api.call(
|
||||||
|
'GetArrivalDepartureBoardByCRS',
|
||||||
|
options, false, false);
|
||||||
|
return await util.cleanData(data);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
log.out(`ldbService.arrDepBoardStaff: Lookup Failed for: ${CRS}`, 'warn');
|
log.out(`ldbService.arrDepBoardStaff: Lookup Failed for: ${CRS}`, 'warn');
|
||||||
log.out(`ldbService.arrDepBoardStaff: ${err}`);
|
log.out(`ldbService.arrDepBoardStaff: ${err}`);
|
||||||
|
@ -4,6 +4,10 @@ const db = require('../services/dbAccess.services');
|
|||||||
const log = require('../utils/log.utils');
|
const log = require('../utils/log.utils');
|
||||||
const clean = require('../utils/sanitizer.utils');
|
const clean = require('../utils/sanitizer.utils');
|
||||||
|
|
||||||
|
const supported = [
|
||||||
|
'GW'
|
||||||
|
];
|
||||||
|
|
||||||
async function findPisByOrigDest(start,end) {
|
async function findPisByOrigDest(start,end) {
|
||||||
log.out('pisServices.findPisByOrigDest: Searching for PIS for Orig: ' +
|
log.out('pisServices.findPisByOrigDest: Searching for PIS for Orig: ' +
|
||||||
`${start}, Dest: ${end}`, 'dbug');
|
`${start}, Dest: ${end}`, 'dbug');
|
||||||
@ -46,6 +50,7 @@ async function findByTiplocArray(tiplocArray) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
supported,
|
||||||
findPisByOrigDest,
|
findPisByOrigDest,
|
||||||
findPisByCode,
|
findPisByCode,
|
||||||
findByTiplocArray
|
findByTiplocArray
|
||||||
|
@ -20,15 +20,17 @@ 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 (pis.supported.includes(trainData?.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 {
|
||||||
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.
|
// '0015' is a string becuase 0015 is not a valid number..
|
||||||
|
}
|
||||||
}
|
}
|
||||||
preparedData.push(trainData[trainService]);
|
preparedData.push(trainData[trainService]);
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ async function checkCrs(input){
|
|||||||
|
|
||||||
// Needs to be moved to the frontend `ensureArray() func`
|
// Needs to be moved to the frontend `ensureArray() func`
|
||||||
async function cleanMessages(input){
|
async function cleanMessages(input){
|
||||||
|
log.out('ldbUtils.cleanMessages: Deprecated function has been called', 'err');
|
||||||
var out = [];
|
var out = [];
|
||||||
if (typeof input.message == 'string') {
|
if (typeof input.message == 'string') {
|
||||||
out.push(await san.cleanNrcc(input.message));
|
out.push(await san.cleanNrcc(input.message));
|
||||||
@ -31,21 +32,40 @@ async function cleanMessages(input){
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Accepts an object but not an Array and returns it wrapped in an array.
|
// Accepts an object but not an Array and returns it wrapped in an array.
|
||||||
// Need to triple check but I don't think this is used anymore.
|
|
||||||
async function cleanServices(input){
|
async function cleanServices(input){
|
||||||
|
log.out('ldbUtils.cleanServices: Deprecated function has been called', 'err');
|
||||||
var out = [];
|
var out = [];
|
||||||
if (!Array.isArray(input)) {
|
if (!Array.isArray(input)) {
|
||||||
log.out(`ldbUtils.cleanServices: Transforming input: ${input}`, 'depr');
|
log.out(`ldbUtils.cleanServices: Transforming input: ${input}`, 'dbug');
|
||||||
out.push(input);
|
out.push(input);
|
||||||
log.out(`ldbUtils.cleanServices: Returning output: ${out}`, 'depr');
|
log.out(`ldbUtils.cleanServices: Returning output: ${out}`, 'dbug');
|
||||||
return out;
|
return out;
|
||||||
} else {
|
} else {
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function cleanData(input) {
|
||||||
|
if (!Array.isArray(input?.GetStationBoardResult?.trainServices.service)) {
|
||||||
|
log.out('ldbUtils.cleanData: Changing train service data to array', 'warn');
|
||||||
|
const trnServiceArray = [input.GetStationBoardResult.trainServices.service];
|
||||||
|
input.GetStationBoardResult.trainServices.service = trnServiceArray;
|
||||||
|
}
|
||||||
|
if (!Array.isArray(input?.GetStationBoardResult?.busServices.service)) {
|
||||||
|
log.out('ldbUtils.cleanData: Changing bus service data to array', 'warn');
|
||||||
|
const busServiceArray = [input.GetStationBoardResult.busServices.service];
|
||||||
|
input.GetStationBoardResult.busServices.service = busServiceArray;
|
||||||
|
}
|
||||||
|
if (!Array.isArray(input?.GetStationBoardResult?.ferryServices.service)) {
|
||||||
|
log.out('ldbUtils.cleanData: Changing ferry service data to array', 'warn');
|
||||||
|
const fryServiceArray = [input.GetStationBoardResult.ferryServices.service];
|
||||||
|
input.GetStationBoardResult.ferryServices.service = fryServiceArray;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
checkCrs,
|
checkCrs,
|
||||||
cleanMessages,
|
cleanMessages,
|
||||||
cleanServices
|
cleanServices,
|
||||||
|
cleanData
|
||||||
};
|
};
|
Loading…
Reference in New Issue
Block a user