Add resources for the ldbs endpoint

Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
Fred Boniface 2023-04-12 13:09:33 +01:00
parent 6c754255f6
commit f1c616e9e0
4 changed files with 37 additions and 7 deletions

View File

@ -3,7 +3,7 @@ const ldb = require('../services/ldb.services');
async function get(req, res, next){ async function get(req, res, next){
try { try {
var id = req.params.id var id = req.params.id
res.json(await ldb.get(req.body, id)) res.json(await ldb.get(id))
} catch (err) { } catch (err) {
console.error(`Unknown Error`, err.message); console.error(`Unknown Error`, err.message);
err.status = 500 err.status = 500

View File

@ -0,0 +1,16 @@
const ldb = require('../services/ldb.services');
async function get(req, res, next){
try {
var id = req.params.id
res.json(await ldb.get(id, true))
} catch (err) {
console.error(`Unknown Error`, err.message);
err.status = 500
next(err);
}
}
module.exports = {
get
}

View File

@ -1,6 +1,6 @@
const express = require('express'); const express = require('express');
const router = express.Router(); const router = express.Router();
const ldbController = require('../controllers/ldb.controllers'); const ldbsController = require('../controllers/ldbs.controllers');
/* GET programming languages. */ /* GET programming languages. */
//router.get('/', programmingLanguagesController.get); //router.get('/', programmingLanguagesController.get);
@ -14,6 +14,6 @@ const ldbController = require('../controllers/ldb.controllers');
/* DELETE programming language */ /* DELETE programming language */
//router.delete('/:id', programmingLanguagesController.remove); //router.delete('/:id', programmingLanguagesController.remove);
router.get('/:id', ldbController.get); router.get('/:id', ldbsController.get);
module.exports = router; module.exports = router;

View File

@ -9,7 +9,7 @@ const db = require('../services/dbAccess.services')
const ldbKey = process.env.OWL_LDB_KEY const ldbKey = process.env.OWL_LDB_KEY
const ldbsvKey = process.env.OWL_LDB_SVKEY const ldbsvKey = process.env.OWL_LDB_SVKEY
async function get(body, id){ async function get(id, staff=false){
var cleanId = san.cleanApiEndpointTxt(id); var cleanId = san.cleanApiEndpointTxt(id);
var obj = await util.checkCrs(cleanId); var obj = await util.checkCrs(cleanId);
try { try {
@ -33,13 +33,27 @@ async function arrDepBoard(CRS){
crs: CRS.toUpperCase() crs: CRS.toUpperCase()
} }
var api = new ldb(ldbKey,false) var api = new ldb(ldbKey,false)
var reply = api.call("GetArrDepBoardWithDetails", options, false, false) return await api.call("GetArrDepBoardWithDetails", options, false, false)
return await reply
} catch (err) { } catch (err) {
log.out(`ldbService.arrDepBoard: Lookup Failed for: ${CRS}`, "warn") log.out(`ldbService.arrDepBoard: Lookup Failed for: ${CRS}`, "warn")
return {GetStationBoardResult: "not available", Reason: `The CRS code ${CRS} is not valid`, Why: `Sometimes a station will have more than one CRS - for example Filton Abbey Wood has FIT and FAW however schedules are only available when looking up with FIT - this is how the National Rail Enquiries systems work.`}; return {GetStationBoardResult: "not available", Reason: `The CRS code ${CRS} is not valid`, Why: `Sometimes a station will have more than one CRS - for example Filton Abbey Wood has FIT and FAW however schedules are only available when looking up with FIT - this is how the National Rail Enquiries systems work.`};
} }
}; }
async function arrDepBoardStaff(CRS) {
log.out(`ldbService.arrDepBoardStaff: Trying to fetch ArrDep Board for ${CRS}`, "dbug")
try {
const options = {
numRows: 25,
crs: CRS.toUpperCase()
}
const api = new ldb(ldbsvKey,true)
return await api.call("Unknown") // Need to find out the syntax of this!
} catch (err) {
log.out(`ldbService.arrDepBoardStaff: Lookup Failed for: ${CRS}, "warn`)
return {GetStationBoardResult: "not available", Reason: `The CRS code ${CRS} is not valid`, Why: `Sometimes a station will have more than one CRS - for example Filton Abbey Wood has FIT and FAW however schedules are only available when looking up with FIT - this is how the National Rail Enquiries systems work.`};
}
}
module.exports = { module.exports = {
get get