2023-02-09 20:34:53 +00:00
|
|
|
const log = require('../utils/log.utils'); // Log Helper
|
2023-05-06 21:54:49 +01:00
|
|
|
const db = require('../services/dbAccess.services'); // DB Access
|
|
|
|
const san = require('../utils/sanitizer.utils'); // Sanitiser
|
2023-02-09 20:34:53 +00:00
|
|
|
|
|
|
|
async function checkCrs(input){
|
2023-05-06 21:54:49 +01:00
|
|
|
var INPUT = input.toUpperCase();
|
|
|
|
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;
|
2023-02-09 20:34:53 +00:00
|
|
|
}
|
|
|
|
|
2023-02-16 10:39:19 +00:00
|
|
|
async function cleanMessages(input){ // Needs to be moved to the frontend `ensureArray() func`
|
2023-05-06 21:54:49 +01:00
|
|
|
var out = [];
|
|
|
|
if (typeof input.message == 'string') {
|
|
|
|
out.push(await san.cleanNrcc(input.message));
|
|
|
|
} else if (typeof input.message == 'object') {
|
|
|
|
for(var i = 0; i < input.message.length; i++) {
|
|
|
|
out.push(await san.cleanNrcc(input.message[i]));
|
2023-02-09 20:34:53 +00:00
|
|
|
}
|
2023-05-06 21:54:49 +01:00
|
|
|
}
|
|
|
|
return out;
|
2023-02-09 20:34:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Accepts an object but not an Array and returns it wrapped in an array.
|
2023-02-16 10:39:19 +00:00
|
|
|
async function cleanServices(input){ // Need to triple check but I don't think this is used anymore.
|
2023-05-06 21:54:49 +01:00
|
|
|
var out = [];
|
|
|
|
if (!Array.isArray(input)) {
|
|
|
|
log.out(`ldbUtils.cleanServices: Transforming input: ${input}`, 'depr');
|
|
|
|
out.push(input);
|
|
|
|
log.out(`ldbUtils.cleanServices: Returning output: ${out}`, 'depr');
|
|
|
|
return out;
|
|
|
|
} else {
|
|
|
|
return input;
|
|
|
|
}
|
2023-02-09 20:34:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
2023-05-06 21:54:49 +01:00
|
|
|
checkCrs,
|
|
|
|
cleanMessages,
|
|
|
|
cleanServices
|
|
|
|
};
|