Add find PIS by code functionality
Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
parent
b119f126b9
commit
11ece9c80e
@ -11,7 +11,18 @@ async function byOrigDest(req, res, next){
|
||||
}
|
||||
}
|
||||
|
||||
async function byCode(req, res, next){
|
||||
try {
|
||||
let code = req.params.code;
|
||||
res.json(await pis.findPisByCode(code));
|
||||
} catch (err) {
|
||||
console.error('Unknown Error', err.message);
|
||||
next(err);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
byOrigDest
|
||||
byOrigDest,
|
||||
byCode
|
||||
};
|
@ -3,5 +3,6 @@ const router = express.Router();
|
||||
const pisController = require('../controllers/pis.controllers');
|
||||
|
||||
router.get('/origdest/:start/:end', pisController.byOrigDest);
|
||||
router.get('/code/:code', pisController.byCode);
|
||||
|
||||
module.exports = router;
|
@ -24,11 +24,22 @@ async function findPisByOrigDest(start,end) {
|
||||
};
|
||||
//const oldQuery = {$and:[{$expr:{$eq:[{$first:"$stops"},firstCrs]}},{$expr:{$eq:[{$last:"$stops"},lastCrs]}}]}
|
||||
const search = db.query('pis', query);
|
||||
return search;
|
||||
return await search;
|
||||
}
|
||||
|
||||
async function findPisByCode(code) {
|
||||
log.out(`pisServices.findPisByCode: Searching for PIS code: ${code}`);
|
||||
const cleanCode = clean.removeNonNumeric(code);
|
||||
const query = {
|
||||
code: cleanCode
|
||||
};
|
||||
const search = db.query('pis', query);
|
||||
return await search;
|
||||
}
|
||||
|
||||
// Hopefully at some point, I will also be able to implement a find PIS code by headcode option.
|
||||
|
||||
module.exports = {
|
||||
findPisByOrigDest
|
||||
findPisByOrigDest,
|
||||
findPisByCode
|
||||
};
|
@ -8,6 +8,10 @@ function removeNonAlpha(inputString) { // Should be able to replace sanitizer m
|
||||
return inputString.replace(/[^a-zA-Z]/g, '');
|
||||
}
|
||||
|
||||
function removeNonNumeric(inputString) {
|
||||
return inputString.replace(/[^0-9]/g, '');
|
||||
}
|
||||
|
||||
const cleanApiEndpointTxt = removeNonAlpha;
|
||||
const cleanApiEndpointNum = removeNonAlphanumeric;
|
||||
|
||||
@ -26,6 +30,7 @@ module.exports = {
|
||||
cleanApiEndpointNum,
|
||||
removeNonAlpha,
|
||||
removeNonAlphanumeric,
|
||||
removeNonNumeric,
|
||||
cleanNrcc,
|
||||
getDomainFromEmail,
|
||||
};
|
Loading…
Reference in New Issue
Block a user