From 417a88adb32933d57f61107ae1417d337dc237f5 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Sat, 22 Apr 2023 22:30:00 +0100 Subject: [PATCH] Lower case the API input Signed-off-by: Fred Boniface --- src/services/pis.services.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/services/pis.services.js b/src/services/pis.services.js index 54cea13..1f224a4 100644 --- a/src/services/pis.services.js +++ b/src/services/pis.services.js @@ -3,15 +3,11 @@ const db = require('../services/dbAccess.services') 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") - /* Here, I need to query the collection for a document with a stops array starting with $start - and ending with $end. This will return an array of one or more pis codes and stopping patterns*/ - // Query to find first stop: {$expr:{$eq:[{$first:"$stops"},start]}} - // 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]}}]}) + const firstCrs = start.toLowerCase() + const lastCrs = end.toLowerCase() + const search = db.query("pis", {$and:[{$expr:{$eq:[{$first:"$stops"},firstCrs]}},{$expr:{$eq:[{$last:"$stops"},lastCrs]}}]}) return search }