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")
|
log.out(`pisServices.findPisByOrigDest: Searching for PIS for Orig: ${start}, Dest: ${end}`, "dbug")
|
||||||
const firstCrs = clean.cleanApiEndpointTxt(start.toLowerCase())
|
const firstCrs = clean.cleanApiEndpointTxt(start.toLowerCase())
|
||||||
const lastCrs = clean.cleanApiEndpointTxt(end.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 oldQuery = {$and:[{$expr:{$eq:[{$first:"$stops"},firstCrs]}},{$expr:{$eq:[{$last:"$stops"},lastCrs]}}]}
|
||||||
const search = db.query("pis", query)
|
const search = db.query("pis", query)
|
||||||
return search
|
return search
|
||||||
|
@ -4,8 +4,14 @@ const san = require('../utils/sanitizer.utils') // Sanitiser
|
|||||||
|
|
||||||
async function checkCrs(input){
|
async function checkCrs(input){
|
||||||
var INPUT = input.toUpperCase()
|
var INPUT = input.toUpperCase()
|
||||||
log.out(`ldbUtils.checkCrs: Building database query to find: '${INPUT}'`, "dbug")
|
log.out(`ldbUtils.checkCrs: Building database query to find: '${INPUT}'`, "info")
|
||||||
var query = {'$or':[{'3ALPHA':INPUT},{'TIPLOC':INPUT},{'STANOX':INPUT}]};
|
var query = {
|
||||||
|
'$or':[
|
||||||
|
{'3ALPHA':INPUT},
|
||||||
|
{'TIPLOC':INPUT},
|
||||||
|
{'STANOX':INPUT}
|
||||||
|
]
|
||||||
|
};
|
||||||
var result = await db.query("stations", query)
|
var result = await db.query("stations", query)
|
||||||
log.out(`ldbUtils.checkCrs: Query results: ${JSON.stringify(result)}`, "dbug")
|
log.out(`ldbUtils.checkCrs: Query results: ${JSON.stringify(result)}`, "dbug")
|
||||||
return result
|
return result
|
||||||
|
@ -16,6 +16,14 @@ string.addDash("@abcd efgh"); // @abcd-efgh
|
|||||||
string.removeSpace("@abcd efgh"); // @abcdefgh
|
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) {
|
function cleanApiEndpointTxt(input) {
|
||||||
var output = clean.sanitize.keepSpace(input)
|
var output = clean.sanitize.keepSpace(input)
|
||||||
if (output != input){
|
if (output != input){
|
||||||
@ -32,11 +40,10 @@ function cleanApiEndpointNum(input) {
|
|||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
|
|
||||||
function cleanNrcc(input) {
|
function cleanNrcc(input) { // Remove newlines and then <p> tags from input
|
||||||
var rmNewline = input.replace(/[\n\r]/g, ""); // Remove newlines
|
const cleanInput = input.replace(/[\n\r]/g, '').replace(/<\/?p[^>]*>/g, '');
|
||||||
var rmPara = rmNewline.replace(/<\/?p[^>]*>/g, ""); // Remove <p> & </p>
|
return cleanInput;
|
||||||
return rmPara;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
async function getDomainFromEmail(mail) { // Needs testing
|
async function getDomainFromEmail(mail) { // Needs testing
|
||||||
split = mail.split("@")
|
split = mail.split("@")
|
||||||
|
Loading…
Reference in New Issue
Block a user