Backend: Make API Response consistent.
Ensure API Response for nrccMessages.message always an array ([]) Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
parent
d8e37f1b6d
commit
eece49a2e3
@ -22,6 +22,10 @@ async function get(body, id){
|
|||||||
var crs = obj[0]['3ALPHA'];
|
var crs = obj[0]['3ALPHA'];
|
||||||
log.out(`ldbService.get: Determined CRS for lookup to be: ${crs}`);
|
log.out(`ldbService.get: Determined CRS for lookup to be: ${crs}`);
|
||||||
var data = await arrDepBoard(crs);
|
var data = await arrDepBoard(crs);
|
||||||
|
if (data.GetStationBoardResult.nrccMessages) {
|
||||||
|
var msg = await util.cleanMessages(data.GetStationBoardResult.nrccMessages);
|
||||||
|
data.GetStationBoardResult.nrccMessages.message = msg;
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
log.out(`ldbService.get: Error, Unable to find CRS: ${err}`)
|
log.out(`ldbService.get: Error, Unable to find CRS: ${err}`)
|
||||||
var data = {ERROR:'NOT_FOUND',description:'The entered station was not found. Please check and try again.'};
|
var data = {ERROR:'NOT_FOUND',description:'The entered station was not found. Please check and try again.'};
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
const log = require('../utils/log.utils'); // Log Helper
|
const log = require('../utils/log.utils'); // Log Helper
|
||||||
const db = require('../services/dbAccess.services') // DB Access
|
const db = require('../services/dbAccess.services') // DB Access
|
||||||
|
const san = require('../utils/sanitizer.utils') // Sanitiser
|
||||||
|
|
||||||
async function checkCrs(input){
|
async function checkCrs(input){
|
||||||
var INPUT = input.toUpperCase()
|
var INPUT = input.toUpperCase()
|
||||||
@ -10,6 +11,19 @@ async function checkCrs(input){
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
async function cleanMessages(input){
|
||||||
checkCrs
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
checkCrs,
|
||||||
|
cleanMessages
|
||||||
}
|
}
|
@ -32,7 +32,14 @@ function cleanApiEndpointNum(input) {
|
|||||||
return output
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
cleanApiEndpointTxt,
|
cleanApiEndpointTxt,
|
||||||
cleanApiEndpointNum
|
cleanApiEndpointNum,
|
||||||
|
cleanNrcc
|
||||||
}
|
}
|
Reference in New Issue
Block a user