Compare commits

..

No commits in common. "4916c377c6e83c868856afa85987c5e4b08f56d6" and "aab3e00eac23b2bb85f784b5092a419551eab145" have entirely different histories.

7 changed files with 31 additions and 119 deletions

4
UpNext.md Normal file
View File

@ -0,0 +1,4 @@
# 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
View File

@ -4,6 +4,8 @@
// 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';
@ -21,7 +23,6 @@ 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');
@ -78,13 +79,10 @@ app.use('/api/v1/stats', statRtr);
app.use('/api/v1/register', regRtr);
// Authented Routes
app.use('/api/v1/ldbs', authenticate, ldbsRtr);
app.use('/api/v1/ldbs', authenticate, (req, res) => res.status(501).json({status: 'not implemented'}));
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);
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
// Number of proxies:
app.set('trust proxy', 4);

View File

@ -1,6 +1,6 @@
const version = {
api: ['/api/v1/',],
app: '2023.6.5'
app: '2023.6.3'
};
module.exports = version;

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,51 +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);
}
}
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
};

View File

@ -14,9 +14,6 @@ const ldbsController = require('../controllers/ldbs.controllers');
/* DELETE programming language */
//router.delete('/:id', programmingLanguagesController.remove);
router.get('/arrdep/:id', ldbsController.get);
router.get('/reasonCode', ldbsController.getReasonCodeList);
router.get('/reasonCode/:code', ldbsController.getReasonCode);
router.get('/service/rid/:rid', ldbsController.getTrainByRID);
router.get('/:id', ldbsController.get);
module.exports = router;

View File

@ -56,15 +56,12 @@ async function arrDepBoardStaff(CRS) {
const options = {
numRows: 25,
crs: CRS.toUpperCase(),
getNonPassengerServices: true,
time: await getDateTimeString(new Date),
timeWindow: 120
getNonPassengerServices: true
};
const api = new ldb(ldbsvKey,true);
return await api.call('GetArrivalDepartureBoardByCRS',options,false,false);
return await api.call('GetArrDepBoardWithDetails', options, false, false);
} catch (err) {
log.out(`ldbService.arrDepBoardStaff: Lookup Failed for: ${CRS}`, 'warn');
log.out(`ldbService.arrDepBoardStaff: ${err}`);
log.out(`ldbService.arrDepBoardStaff: Lookup Failed for: ${CRS}, "warn`);
return {
GetStationBoardResult: 'not available',
Reason: `The CRS code ${CRS} is not valid`
@ -72,55 +69,6 @@ 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,
getServiceByRID,
getReasonCodeList,
getReasonCode
get
};