diff --git a/src/configs/version.configs.js b/src/configs/version.configs.js index 8990c71..c11bbc9 100644 --- a/src/configs/version.configs.js +++ b/src/configs/version.configs.js @@ -1,6 +1,6 @@ const version = { api: ['/api/v1/',], - app: '2023.6.3' + app: '2023.6.5' }; module.exports = version; \ No newline at end of file diff --git a/src/controllers/ldbs.controllers.js b/src/controllers/ldbs.controllers.js index c4eae71..10bd31a 100644 --- a/src/controllers/ldbs.controllers.js +++ b/src/controllers/ldbs.controllers.js @@ -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 }; \ No newline at end of file diff --git a/src/routes/ldbs.routes.js b/src/routes/ldbs.routes.js index 2727ba0..632f2e2 100644 --- a/src/routes/ldbs.routes.js +++ b/src/routes/ldbs.routes.js @@ -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; \ No newline at end of file diff --git a/src/services/ldb.services.js b/src/services/ldb.services.js index 3e1b49e..0c6c824 100644 --- a/src/services/ldb.services.js +++ b/src/services/ldb.services.js @@ -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 }; \ No newline at end of file