From 90baf1b13a8099dd4117b5a85ad028e157fcdf01 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Tue, 10 Oct 2023 12:53:01 +0100 Subject: [PATCH] Prepare for PIS Search upgrade Signed-off-by: Fred Boniface --- .../{pis.services.js => pis.services.ts} | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) rename src/services/{pis.services.js => pis.services.ts} (66%) diff --git a/src/services/pis.services.js b/src/services/pis.services.ts similarity index 66% rename from src/services/pis.services.js rename to src/services/pis.services.ts index ead675d..b974cf3 100644 --- a/src/services/pis.services.js +++ b/src/services/pis.services.ts @@ -7,7 +7,7 @@ import { logger } from "../utils/logger.utils"; const supported = ["GW", "UK"]; -async function findPisByOrigDest(start, end) { +async function findPisByOrigDest(start: string, end: string) { logger.debug( `pisServices.findPisByOrigDest: Searching for Orig: ${start}, Dest: ${end}` ); @@ -31,7 +31,7 @@ async function findPisByOrigDest(start, end) { return await search; } -async function findPisByCode(code) { +async function findPisByCode(code: string) { logger.debug(`pisServices.findPisByCode: Searching for PIS code: ${code}`); const cleanCode = clean.removeNonNumeric(code); const query = { @@ -41,14 +41,27 @@ async function findPisByCode(code) { return await search; } -async function findByTiplocArray(tiplocArray) { +async function findByTiplocArray(tiplocArray: string[]) { const query = { tiplocs: tiplocArray, }; - const res = db.query("pis", query); + const res = await db.query("pis", query); + // If res is empty then try to find partial match + /* if (res.length) { + return res; + } else { + let partial = await findPartialMatchByTiploc(tiplocArray); + return partial + } */ return await res; } +async function findPartialMatchByTiploc(tiplocArray: string[]) { + // Do some magic here, similar to findPisByOrigDest but + // ensuring that the stops in the array match the last + // x number of items in the array. +} + module.exports = { supported, findPisByOrigDest,