LDB is now working for CRS only and no auth

This commit is contained in:
Fred Boniface 2022-12-08 21:08:54 +00:00
parent ca90da651d
commit 72a43a6cf0
6 changed files with 66 additions and 21 deletions

View File

@ -23,6 +23,9 @@ Whilst the application is open source, the webservice (owlboard.fb-infra.uk) is
- Returns JSON: `{"STATION NAME":{"CRS":"code","TIPLOC":"code"}}`
- /ldb:
- /{crs}:
- GET: Get departure board for {crs}
- Returns JSON: Formatted as per ldb-json module.SS
## Stack:
- app.js -> Launches server, Entry Point, defines routers and middlewares.

2
app.js
View File

@ -10,6 +10,7 @@ const config = require('./src/configs/server.configs');
const version = require('./src/configs/version.configs');
const testRtr = require('./src/routes/test.routes');
const listRtr = require('./src/routes/list.routes');
const ldbRtr = require('./src/routes/ldb.routes');
// Print version number:
console.log(`Starting OwlBoard - App Version: ${version.app} - API versions: ${version.api}`);
@ -29,6 +30,7 @@ app.use(express.static('static')); //Serve static content from static
// Express Routes
app.use('/api/v1/test', testRtr);
app.use('/api/v1/list', listRtr);
app.use('/api/v1/ldb', ldbRtr);
// Start Express
app.listen(config.port, config.listen, (error) =>{

View File

@ -0,0 +1,15 @@
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))
} catch (err) {
console.error(`Unknown Error`, err.message);
next(err);
}
}
module.exports = {
get
}

View File

@ -0,0 +1,19 @@
const express = require('express');
const router = express.Router();
const ldbController = require('../controllers/ldb.controllers');
/* GET programming languages. */
//router.get('/', programmingLanguagesController.get);
/* POST programming language */
//router.post('/', programmingLanguagesController.create);
/* PUT programming language */
//router.put('/:id', programmingLanguagesController.update);
/* DELETE programming language */
//router.delete('/:id', programmingLanguagesController.remove);
router.get('/:id', ldbController.get);
module.exports = router;

View File

@ -1,28 +1,30 @@
// Parse and return an LDB Request
// FUNCTIONS
// findBoard(input, staff): Exported:
// input: [str, CRS or TIPLOC, staff: BOOL, use staff API or not]
// Runs checks on input data and calls an internal function to get data.
// post(body, id): Exported:
// body: [req.body from controller]
// id : [req.params.id from controller - this is expected to be CRS or TIPLOC]
// convertTiploc(TIPLOC) : Exported: Looks up CRS, Name & STANOX for Tiploc
const ldb = require('ldbs-json')
const keys = require('/srv/keys/owlboard/keys.configs')
const util = require('../utils/ldb.utils')
async function findBoard(input, staff){
// Check whether input is CRS or TIPLOC
async function get(body, id){
// Read request body for information on request
// Check whether input is CRS or TIPLOC with util.checkInput(input)
// if TIPLOC then convert to CRS,
// then check whether staff is true or false,
// then call the correct function and
// return that output to calling function
// for now, just call arrDepBoard(CRS)
var output = await arrDepBoard(input)
// for now, just call arrDepBoard(CRS) with the id from the url directly used - UNSAFE
var output = await arrDepBoard(id)
return output
}
async function arrDepBoard(CRS){
var valid = await checkCrs(CRS)
var valid = await util.checkCrs(CRS)
if (valid != false){
var options = {
numRows: 10,
@ -36,18 +38,6 @@ async function arrDepBoard(CRS){
}
};
async function checkCrs(input){
// Check whether CRS is valid
// Until implemented always return true
return true
}
async function convertTiploc(TIPLOC){
// Convert TIPLOC to CRS with DBLookup
return TIPLOC
}
module.exports = {
convertTiploc,
findBoard
get
}

16
src/utils/ldb.utils.js Normal file
View File

@ -0,0 +1,16 @@
async function checkCrs(input){
// Check whether CRS is valid
// if not, try to get tiploc
// Until implemented always return true
return true
}
async function convertTiploc(input){
// Convert TIPLOC to CRS with DBLookup
return input
}
module.exports = {
checkCrs,
convertTiploc
}