backend/src/utils/ldb.utils.js
Fred Boniface 849c31af36 Add eslint rule: max line length (80)
Signed-off-by: Fred Boniface <fred@fjla.uk>
2023-06-07 21:53:56 +01:00

51 lines
1.4 KiB
JavaScript

const log = require('../utils/log.utils'); // Log Helper
const db = require('../services/dbAccess.services'); // DB Access
const san = require('../utils/sanitizer.utils'); // Sanitiser
async function checkCrs(input){
var INPUT = input.toUpperCase();
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;
}
// Needs to be moved to the frontend `ensureArray() func`
async function cleanMessages(input){
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]));
}
}
return out;
}
// Accepts an object but not an Array and returns it wrapped in an array.
// Need to triple check but I don't think this is used anymore.
async function cleanServices(input){
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;
}
}
module.exports = {
checkCrs,
cleanMessages,
cleanServices
};