Adjust sanitizer functions, tidy mongo queries.
Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
parent
b66254213e
commit
201f1d0642
@ -8,7 +8,22 @@ async function findPisByOrigDest(start,end) {
|
||||
log.out(`pisServices.findPisByOrigDest: Searching for PIS for Orig: ${start}, Dest: ${end}`, "dbug")
|
||||
const firstCrs = clean.cleanApiEndpointTxt(start.toLowerCase())
|
||||
const lastCrs = clean.cleanApiEndpointTxt(end.toLowerCase())
|
||||
const query = {stops: {$elemMatch: {$eq: firstCrs, $position: 0}}, stops: {$elemMatch: {$eq: lastCrs, $position: {$exists: false}}}}
|
||||
const query = {
|
||||
stops: {
|
||||
$elemMatch: {
|
||||
$eq: firstCrs,
|
||||
$position: 0
|
||||
}
|
||||
},
|
||||
stops: {
|
||||
$elemMatch: {
|
||||
$eq: lastCrs,
|
||||
$position: {
|
||||
$exists: false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const oldQuery = {$and:[{$expr:{$eq:[{$first:"$stops"},firstCrs]}},{$expr:{$eq:[{$last:"$stops"},lastCrs]}}]}
|
||||
const search = db.query("pis", query)
|
||||
return search
|
||||
|
@ -4,8 +4,14 @@ const san = require('../utils/sanitizer.utils') // Sanitiser
|
||||
|
||||
async function checkCrs(input){
|
||||
var INPUT = input.toUpperCase()
|
||||
log.out(`ldbUtils.checkCrs: Building database query to find: '${INPUT}'`, "dbug")
|
||||
var query = {'$or':[{'3ALPHA':INPUT},{'TIPLOC':INPUT},{'STANOX':INPUT}]};
|
||||
log.out(`ldbUtils.checkCrs: Building database query to find: '${INPUT}'`, "info")
|
||||
var query = {
|
||||
'$or':[
|
||||
{'3ALPHA':INPUT},
|
||||
{'TIPLOC':INPUT},
|
||||
{'STANOX':INPUT}
|
||||
]
|
||||
};
|
||||
var result = await db.query("stations", query)
|
||||
log.out(`ldbUtils.checkCrs: Query results: ${JSON.stringify(result)}`, "dbug")
|
||||
return result
|
||||
|
@ -16,6 +16,14 @@ string.addDash("@abcd efgh"); // @abcd-efgh
|
||||
string.removeSpace("@abcd efgh"); // @abcdefgh
|
||||
*/
|
||||
|
||||
function removeNonAlphanumeric(inputString) { // Should be able to replace sanitizer module
|
||||
return inputString.replace(/[^a-zA-Z0-9]/g, '');
|
||||
}
|
||||
|
||||
function removeNonAlpha(inputString) { // Should be able to replace sanitizer module
|
||||
return inputString.replace(/[^a-zA-Z]/g, '');
|
||||
}
|
||||
|
||||
function cleanApiEndpointTxt(input) {
|
||||
var output = clean.sanitize.keepSpace(input)
|
||||
if (output != input){
|
||||
@ -32,11 +40,10 @@ function cleanApiEndpointNum(input) {
|
||||
return output
|
||||
}
|
||||
|
||||
function cleanNrcc(input) {
|
||||
var rmNewline = input.replace(/[\n\r]/g, ""); // Remove newlines
|
||||
var rmPara = rmNewline.replace(/<\/?p[^>]*>/g, ""); // Remove <p> & </p>
|
||||
return rmPara;
|
||||
}
|
||||
function cleanNrcc(input) { // Remove newlines and then <p> tags from input
|
||||
const cleanInput = input.replace(/[\n\r]/g, '').replace(/<\/?p[^>]*>/g, '');
|
||||
return cleanInput;
|
||||
}
|
||||
|
||||
async function getDomainFromEmail(mail) { // Needs testing
|
||||
split = mail.split("@")
|
||||
|
Loading…
Reference in New Issue
Block a user