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,