From f1c616e9e0edbecbafd5f2159408478bde1e47d3 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Wed, 12 Apr 2023 13:09:33 +0100 Subject: [PATCH] Add resources for the ldbs endpoint Signed-off-by: Fred Boniface --- src/controllers/ldb.controllers.js | 2 +- src/controllers/ldbs.controllers copy.js | 16 ++++++++++++++++ src/routes/ldbs.routes.js | 4 ++-- src/services/ldb.services.js | 22 ++++++++++++++++++---- 4 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 src/controllers/ldbs.controllers copy.js diff --git a/src/controllers/ldb.controllers.js b/src/controllers/ldb.controllers.js index 0261c67..019cc95 100644 --- a/src/controllers/ldb.controllers.js +++ b/src/controllers/ldb.controllers.js @@ -3,7 +3,7 @@ const ldb = require('../services/ldb.services'); async function get(req, res, next){ try { var id = req.params.id - res.json(await ldb.get(req.body, id)) + res.json(await ldb.get(id)) } catch (err) { console.error(`Unknown Error`, err.message); err.status = 500 diff --git a/src/controllers/ldbs.controllers copy.js b/src/controllers/ldbs.controllers copy.js new file mode 100644 index 0000000..aa652c6 --- /dev/null +++ b/src/controllers/ldbs.controllers copy.js @@ -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 +} \ No newline at end of file diff --git a/src/routes/ldbs.routes.js b/src/routes/ldbs.routes.js index 591bd45..2727ba0 100644 --- a/src/routes/ldbs.routes.js +++ b/src/routes/ldbs.routes.js @@ -1,6 +1,6 @@ const express = require('express'); const router = express.Router(); -const ldbController = require('../controllers/ldb.controllers'); +const ldbsController = require('../controllers/ldbs.controllers'); /* GET programming languages. */ //router.get('/', programmingLanguagesController.get); @@ -14,6 +14,6 @@ const ldbController = require('../controllers/ldb.controllers'); /* DELETE programming language */ //router.delete('/:id', programmingLanguagesController.remove); -router.get('/:id', ldbController.get); +router.get('/:id', ldbsController.get); module.exports = router; \ No newline at end of file diff --git a/src/services/ldb.services.js b/src/services/ldb.services.js index 13cde66..fa4b0d1 100644 --- a/src/services/ldb.services.js +++ b/src/services/ldb.services.js @@ -9,7 +9,7 @@ const db = require('../services/dbAccess.services') const ldbKey = process.env.OWL_LDB_KEY const ldbsvKey = process.env.OWL_LDB_SVKEY -async function get(body, id){ +async function get(id, staff=false){ var cleanId = san.cleanApiEndpointTxt(id); var obj = await util.checkCrs(cleanId); try { @@ -33,13 +33,27 @@ async function arrDepBoard(CRS){ crs: CRS.toUpperCase() } var api = new ldb(ldbKey,false) - var reply = api.call("GetArrDepBoardWithDetails", options, false, false) - return await reply + return await api.call("GetArrDepBoardWithDetails", options, false, false) } catch (err) { 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.`}; } -}; +} + +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 = { get