Lower case the API input

Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
Fred Boniface 2023-04-22 22:30:00 +01:00
parent 121528c413
commit 417a88adb3
1 changed files with 4 additions and 8 deletions

View File

@ -3,15 +3,11 @@
const db = require('../services/dbAccess.services') const db = require('../services/dbAccess.services')
const log = require('../utils/log.utils') const log = require('../utils/log.utils')
async function findPisByOrigDest(start,end) { async function findPisByOrigDest(start,end) { // Probably need to add a sanitize here
log.out(`pisServices.findPisByOrigDest: Searching for PIS for Orig: ${start}, Dest: ${end}`, "dbug") log.out(`pisServices.findPisByOrigDest: Searching for PIS for Orig: ${start}, Dest: ${end}`, "dbug")
/* Here, I need to query the collection for a document with a stops array starting with $start const firstCrs = start.toLowerCase()
and ending with $end. This will return an array of one or more pis codes and stopping patterns*/ const lastCrs = end.toLowerCase()
// Query to find first stop: {$expr:{$eq:[{$first:"$stops"},start]}} const search = db.query("pis", {$and:[{$expr:{$eq:[{$first:"$stops"},firstCrs]}},{$expr:{$eq:[{$last:"$stops"},lastCrs]}}]})
// Query to find end stop: {$expr:{$eq:[{$last:"$stops"},end]}}
// Attempt at combining the queries:
// {$and:[{$expr:{$eq:[{$first:"$stops"},start]}},{$expr:{$eq:[{$last:"$stops"},end]}}]}
const search = db.query("pis", {$and:[{$expr:{$eq:[{$first:"$stops"},start]}},{$expr:{$eq:[{$last:"$stops"},end]}}]})
return search return search
} }