Add endpoints for LDBSVWS

This commit is contained in:
Fred Boniface 2023-06-11 21:43:01 +01:00
parent 43fd6db4b9
commit 4916c377c6
4 changed files with 97 additions and 7 deletions

View File

@ -1,6 +1,6 @@
const version = {
api: ['/api/v1/',],
app: '2023.6.3'
app: '2023.6.5'
};
module.exports = version;

View File

@ -11,6 +11,41 @@ async function get(req, res, next){
}
}
async function getReasonCodeList(req, res, next) {
try {
res.json(await ldb.getReasonCodeList());
} catch (err) {
console.error('ERROR', err.message);
err.status = 500;
next(err);
}
}
async function getReasonCode(req, res, next) {
try {
const code = req.params.code;
res.json(await ldb.getReasonCode(code));
} catch (err) {
console.error('ERROR', err.message);
err.status = 500;
next(err);
}
}
async function getTrainByRID(req, res, next) {
try {
const rid = req.params.rid;
res.json(await ldb.getServiceByRID(rid));
} catch (err) {
console.error('ERROR', err);
err.status = 500;
next(err);
}
}
module.exports = {
get
get,
getReasonCodeList,
getReasonCode,
getTrainByRID
};

View File

@ -14,6 +14,9 @@ const ldbsController = require('../controllers/ldbs.controllers');
/* DELETE programming language */
//router.delete('/:id', programmingLanguagesController.remove);
router.get('/:id', ldbsController.get);
router.get('/arrdep/:id', ldbsController.get);
router.get('/reasonCode', ldbsController.getReasonCodeList);
router.get('/reasonCode/:code', ldbsController.getReasonCode);
router.get('/service/rid/:rid', ldbsController.getTrainByRID);
module.exports = router;

View File

@ -56,12 +56,15 @@ async function arrDepBoardStaff(CRS) {
const options = {
numRows: 25,
crs: CRS.toUpperCase(),
getNonPassengerServices: true
getNonPassengerServices: true,
time: await getDateTimeString(new Date),
timeWindow: 120
};
const api = new ldb(ldbsvKey,true);
return await api.call('GetArrDepBoardWithDetails', options, false, false);
return await api.call('GetArrivalDepartureBoardByCRS',options,false,false);
} catch (err) {
log.out(`ldbService.arrDepBoardStaff: Lookup Failed for: ${CRS}, "warn`);
log.out(`ldbService.arrDepBoardStaff: Lookup Failed for: ${CRS}`, 'warn');
log.out(`ldbService.arrDepBoardStaff: ${err}`);
return {
GetStationBoardResult: 'not available',
Reason: `The CRS code ${CRS} is not valid`
@ -69,6 +72,55 @@ async function arrDepBoardStaff(CRS) {
}
}
async function getServiceByRID(rid) {
log.out(`ldbService.getServiceByRID: Finding RID: ${rid}`, 'dbug');
try {
const options = {
rid: String(rid)
};
const api = new ldb(ldbsvKey,true);
return await api.call('GetServiceDetailsByRID', options,false,false);
} catch (err) {
log.out(`ldbService.queryService: ${err}`, 'EROR');
}
}
async function getReasonCodeList() {
log.out('ldbService.getReasonCodeList: Fetching reason code list', 'eror');
try {
const api = new ldb(ldbsvKey,true);
const options = {};
return await api.call('GetReasonCodeList', options, true, false);
} catch (err) {
log.out(`ldbService.getReasonCodeList: ${err}`, 'eror');
}
}
async function getReasonCode(code) {
log.out(`ldbService.getReasonCode: Fetching reason code ${code}`, 'dbug');
try {
const api = new ldb(ldbsvKey, true);
return await api.call('GetReasonCode', {reasonCode: code}, true, false);
} catch (err) {
log.out(`ldbService.getReasonCode: ${err}`, 'eror');
}
}
async function getDateTimeString(date) {
const year = date.getFullYear(),
month = String(date.getMonth() + 1).padStart(2,'0'),
day = String(date.getDate()).padStart(2,'0'),
hour = String(date.getHours()).padStart(2,'0'),
minute = String(date.getMinutes()).padStart(2,'0'),
second = String(date.getSeconds()).padStart(2,'0');
const format = `${year}-${month}-${day}T${hour}:${minute}:${second}`;
return format;
}
module.exports = {
get
get,
getServiceByRID,
getReasonCodeList,
getReasonCode
};