Prepare for PIS Search upgrade

Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
Fred Boniface 2023-10-10 12:53:01 +01:00
parent 0a25ae85f5
commit 90baf1b13a

View File

@ -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,