Add basic sanitizing step to PIS API

Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
Fred Boniface 2023-04-22 22:32:55 +01:00
parent 417a88adb3
commit 0596bd48e6

View File

@ -2,11 +2,12 @@
const db = require('../services/dbAccess.services') const db = require('../services/dbAccess.services')
const log = require('../utils/log.utils') const log = require('../utils/log.utils')
const clean = require('../utils/sanitizer.utils')
async function findPisByOrigDest(start,end) { // Probably need to add a sanitize here async function findPisByOrigDest(start,end) {
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")
const firstCrs = start.toLowerCase() const firstCrs = clean.cleanApiEndpointTxt(start.toLowerCase())
const lastCrs = end.toLowerCase() const lastCrs = clean.cleanApiEndpointTxt(end.toLowerCase())
const search = db.query("pis", {$and:[{$expr:{$eq:[{$first:"$stops"},firstCrs]}},{$expr:{$eq:[{$last:"$stops"},lastCrs]}}]}) const search = db.query("pis", {$and:[{$expr:{$eq:[{$first:"$stops"},firstCrs]}},{$expr:{$eq:[{$last:"$stops"},lastCrs]}}]})
return search return search
} }