Add endpoints for LDBSVWS
This commit is contained in:
parent
43fd6db4b9
commit
4916c377c6
@ -1,6 +1,6 @@
|
|||||||
const version = {
|
const version = {
|
||||||
api: ['/api/v1/',],
|
api: ['/api/v1/',],
|
||||||
app: '2023.6.3'
|
app: '2023.6.5'
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = version;
|
module.exports = version;
|
@ -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 = {
|
module.exports = {
|
||||||
get
|
get,
|
||||||
|
getReasonCodeList,
|
||||||
|
getReasonCode,
|
||||||
|
getTrainByRID
|
||||||
};
|
};
|
@ -14,6 +14,9 @@ const ldbsController = require('../controllers/ldbs.controllers');
|
|||||||
/* DELETE programming language */
|
/* DELETE programming language */
|
||||||
//router.delete('/:id', programmingLanguagesController.remove);
|
//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;
|
module.exports = router;
|
@ -56,12 +56,15 @@ async function arrDepBoardStaff(CRS) {
|
|||||||
const options = {
|
const options = {
|
||||||
numRows: 25,
|
numRows: 25,
|
||||||
crs: CRS.toUpperCase(),
|
crs: CRS.toUpperCase(),
|
||||||
getNonPassengerServices: true
|
getNonPassengerServices: true,
|
||||||
|
time: await getDateTimeString(new Date),
|
||||||
|
timeWindow: 120
|
||||||
};
|
};
|
||||||
const api = new ldb(ldbsvKey,true);
|
const api = new ldb(ldbsvKey,true);
|
||||||
return await api.call('GetArrDepBoardWithDetails', options, false, false);
|
return await api.call('GetArrivalDepartureBoardByCRS',options,false,false);
|
||||||
} catch (err) {
|
} 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 {
|
return {
|
||||||
GetStationBoardResult: 'not available',
|
GetStationBoardResult: 'not available',
|
||||||
Reason: `The CRS code ${CRS} is not valid`
|
Reason: `The CRS code ${CRS} is not valid`
|
||||||
@ -69,6 +72,55 @@ async function arrDepBoardStaff(CRS) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
async function getServiceByRID(rid) {
|
||||||
get
|
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,
|
||||||
|
getServiceByRID,
|
||||||
|
getReasonCodeList,
|
||||||
|
getReasonCode
|
||||||
};
|
};
|
Loading…
Reference in New Issue
Block a user