Add pis lookup by TIPLOC array

Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
Fred Boniface 2023-06-01 00:10:14 +01:00
parent e2cba37938
commit 7f3d4780ff
2 changed files with 10 additions and 10 deletions

View File

@ -37,15 +37,12 @@ async function findPisByCode(code) {
return await search;
}
async function findRandom() {
log.out('pisServices.findRandom: Finding five random PIS Codes', 'dbug');
const query = { // Doesn't work, need aggregation
$sample: {
size: 5
}
async function findByTiplocArray(tiplocArray) {
const query = {
'tiplocs': tiplocArray
};
const results = db.query('pis', query);
return results;
const res = db.query('pis', query);
return res;
}
// Hopefully at some point, I will also be able to implement a find PIS code by headcode option.
@ -53,5 +50,5 @@ async function findRandom() {
module.exports = {
findPisByOrigDest,
findPisByCode,
findRandom
findByTiplocArray
};

View File

@ -1,6 +1,7 @@
const log = require('../utils/log.utils');
const db = require('./dbAccess.services');
const clean = require('../utils/sanitizer.utils');
const pis = require('../services/pis.services');
async function findByHeadcode(headcode) {
const sanitizedHeadcode = clean.removeNonAlphanumeric(headcode);
@ -16,7 +17,9 @@ async function findByHeadcode(headcode) {
};
// At this point, the returned objects need sorting to ensure the correct object is returned.
// C, N, O, P is the order - C being the preferred, then N, then O and finally P.
return db.query('timetable', query);
const trainData = db.query('timetable', query);
return trainData; // Use pis.findByTiplocArray() to return a PIS code alongside the data
// eg. {trainData: {}, pis:5001}
}
module.exports = {