Add pis lookup by TIPLOC array
Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
parent
e2cba37938
commit
7f3d4780ff
@ -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
|
||||
};
|
@ -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 = {
|
||||
|
Loading…
Reference in New Issue
Block a user