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;
|
return await search;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function findRandom() {
|
async function findByTiplocArray(tiplocArray) {
|
||||||
log.out('pisServices.findRandom: Finding five random PIS Codes', 'dbug');
|
const query = {
|
||||||
const query = { // Doesn't work, need aggregation
|
'tiplocs': tiplocArray
|
||||||
$sample: {
|
|
||||||
size: 5
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
const results = db.query('pis', query);
|
const res = db.query('pis', query);
|
||||||
return results;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hopefully at some point, I will also be able to implement a find PIS code by headcode option.
|
// 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 = {
|
module.exports = {
|
||||||
findPisByOrigDest,
|
findPisByOrigDest,
|
||||||
findPisByCode,
|
findPisByCode,
|
||||||
findRandom
|
findByTiplocArray
|
||||||
};
|
};
|
@ -1,6 +1,7 @@
|
|||||||
const log = require('../utils/log.utils');
|
const log = require('../utils/log.utils');
|
||||||
const db = require('./dbAccess.services');
|
const db = require('./dbAccess.services');
|
||||||
const clean = require('../utils/sanitizer.utils');
|
const clean = require('../utils/sanitizer.utils');
|
||||||
|
const pis = require('../services/pis.services');
|
||||||
|
|
||||||
async function findByHeadcode(headcode) {
|
async function findByHeadcode(headcode) {
|
||||||
const sanitizedHeadcode = clean.removeNonAlphanumeric(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.
|
// 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.
|
// 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 = {
|
module.exports = {
|
||||||
|
Loading…
Reference in New Issue
Block a user