From 7f3d4780ffd9465f9eb228a402e16a74b704137a Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Thu, 1 Jun 2023 00:10:14 +0100 Subject: [PATCH] Add pis lookup by TIPLOC array Signed-off-by: Fred Boniface --- src/services/pis.services.js | 15 ++++++--------- src/services/trainService.services.js | 5 ++++- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/services/pis.services.js b/src/services/pis.services.js index f37cfc3..427b561 100644 --- a/src/services/pis.services.js +++ b/src/services/pis.services.js @@ -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 }; \ No newline at end of file diff --git a/src/services/trainService.services.js b/src/services/trainService.services.js index ddd55e9..ced4991 100644 --- a/src/services/trainService.services.js +++ b/src/services/trainService.services.js @@ -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 = {