Compare commits
2 Commits
aab3e00eac
...
4916c377c6
Author | SHA1 | Date |
---|---|---|
Fred Boniface | 4916c377c6 | |
Fred Boniface | 43fd6db4b9 |
|
@ -1,4 +0,0 @@
|
|||
# What to do next:
|
||||
|
||||
* Rewrite sanitizing functions to remove external dependancy.
|
||||
* Change /api/v1/auth endpoints to /api/v1/register endpoints - auth is done in middleware
|
12
app.js
12
app.js
|
@ -4,8 +4,6 @@
|
|||
// licensed separately, each folder contains a license file where a
|
||||
// different license applies.
|
||||
|
||||
/* global process */
|
||||
|
||||
console.log('Initialising OwlBoard');
|
||||
const mode = process.env.NODE_ENV || 'development';
|
||||
|
||||
|
@ -23,6 +21,7 @@ const log = require('./src/utils/log.utils');
|
|||
const version = require('./src/configs/version.configs');
|
||||
const listRtr = require('./src/routes/list.routes');
|
||||
const ldbRtr = require('./src/routes/ldb.routes');
|
||||
const ldbsRtr = require('./src/routes/ldbs.routes');
|
||||
const kubeRtr = require('./src/routes/kube.routes');
|
||||
const findRtr = require('./src/routes/find.routes');
|
||||
const issueRtr = require('./src/routes/issue.routes');
|
||||
|
@ -79,10 +78,13 @@ app.use('/api/v1/stats', statRtr);
|
|||
app.use('/api/v1/register', regRtr);
|
||||
|
||||
// Authented Routes
|
||||
app.use('/api/v1/ldbs', authenticate, (req, res) => res.status(501).json({status: 'not implemented'}));
|
||||
app.use('/api/v1/ldbs', authenticate, ldbsRtr);
|
||||
app.use('/api/v1/pis', authenticate, pisRtr);
|
||||
app.use('/api/v1/auth/test', authenticate, (req, res) => res.status(200).json({status: 'ok', message: 'Authentication successful'})); // Returns 401 if auth failed, 200 if successful.
|
||||
app.use('/api/v1/train', /*authenticate,*/ trainRtr); // Disable authentication during testing
|
||||
app.use('/api/v1/auth/test', authenticate, (req, res) => res.status(200).json({
|
||||
status: 'ok',
|
||||
message: 'Authentication successful'
|
||||
})); // Returns 401 if auth failed, 200 if successful.
|
||||
app.use('/api/v1/train', authenticate, trainRtr);
|
||||
|
||||
// Number of proxies:
|
||||
app.set('trust proxy', 4);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
const version = {
|
||||
api: ['/api/v1/',],
|
||||
app: '2023.6.3'
|
||||
app: '2023.6.5'
|
||||
};
|
||||
|
||||
module.exports = version;
|
|
@ -1,16 +0,0 @@
|
|||
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
|
||||
};
|
|
@ -0,0 +1,51 @@
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
getReasonCodeList,
|
||||
getReasonCode,
|
||||
getTrainByRID
|
||||
};
|
|
@ -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;
|
|
@ -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
|
||||
};
|
Loading…
Reference in New Issue