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 = {
|
||||
api: ['/api/v1/','/api/v2'],
|
||||
app: '2023.6.15'
|
||||
app: '2023.7.1'
|
||||
};
|
||||
|
||||
module.exports = version;
|
@ -62,7 +62,10 @@ async function arrDepBoardStaff(CRS) {
|
||||
services: 'PBS'
|
||||
};
|
||||
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) {
|
||||
log.out(`ldbService.arrDepBoardStaff: Lookup Failed for: ${CRS}`, 'warn');
|
||||
log.out(`ldbService.arrDepBoardStaff: ${err}`);
|
||||
|
@ -4,6 +4,10 @@ const db = require('../services/dbAccess.services');
|
||||
const log = require('../utils/log.utils');
|
||||
const clean = require('../utils/sanitizer.utils');
|
||||
|
||||
const supported = [
|
||||
'GW'
|
||||
];
|
||||
|
||||
async function findPisByOrigDest(start,end) {
|
||||
log.out('pisServices.findPisByOrigDest: Searching for PIS for Orig: ' +
|
||||
`${start}, Dest: ${end}`, 'dbug');
|
||||
@ -46,6 +50,7 @@ async function findByTiplocArray(tiplocArray) {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
supported,
|
||||
findPisByOrigDest,
|
||||
findPisByCode,
|
||||
findByTiplocArray
|
||||
|
@ -20,6 +20,7 @@ async function findByHeadcodeToday(headcode) {
|
||||
let trainData = await parseTrains(queryData);
|
||||
let preparedData = [];
|
||||
for (let trainService in trainData) {
|
||||
if (pis.supported.includes(trainData?.operator)) {
|
||||
// Search for PIS Code for each service
|
||||
const tiplocList = await getPublicStops(trainData[trainService]['stops']);
|
||||
//console.log(tiplocList.length); console.log(tiplocList);
|
||||
@ -28,7 +29,8 @@ 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.
|
||||
// '0015' is a string becuase 0015 is not a valid number..
|
||||
}
|
||||
}
|
||||
preparedData.push(trainData[trainService]);
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ async function checkCrs(input){
|
||||
|
||||
// Needs to be moved to the frontend `ensureArray() func`
|
||||
async function cleanMessages(input){
|
||||
log.out('ldbUtils.cleanMessages: Deprecated function has been called', 'err');
|
||||
var out = [];
|
||||
if (typeof input.message == 'string') {
|
||||
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.
|
||||
// Need to triple check but I don't think this is used anymore.
|
||||
async function cleanServices(input){
|
||||
log.out('ldbUtils.cleanServices: Deprecated function has been called', 'err');
|
||||
var out = [];
|
||||
if (!Array.isArray(input)) {
|
||||
log.out(`ldbUtils.cleanServices: Transforming input: ${input}`, 'depr');
|
||||
log.out(`ldbUtils.cleanServices: Transforming input: ${input}`, 'dbug');
|
||||
out.push(input);
|
||||
log.out(`ldbUtils.cleanServices: Returning output: ${out}`, 'depr');
|
||||
log.out(`ldbUtils.cleanServices: Returning output: ${out}`, 'dbug');
|
||||
return out;
|
||||
} else {
|
||||
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 = {
|
||||
checkCrs,
|
||||
cleanMessages,
|
||||
cleanServices
|
||||
cleanServices,
|
||||
cleanData
|
||||
};
|
Loading…
Reference in New Issue
Block a user