eslint fixes
Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
parent
57fe392e8c
commit
c9b307b697
98
app.js
98
app.js
@ -4,12 +4,14 @@
|
|||||||
// licensed separately, each folder contains a license file where a
|
// licensed separately, each folder contains a license file where a
|
||||||
// different license applies.
|
// different license applies.
|
||||||
|
|
||||||
console.log(`Initialising OwlBoard`)
|
/* global process */
|
||||||
const mode = process.env.NODE_ENV || "development"
|
|
||||||
|
console.log('Initialising OwlBoard')
|
||||||
|
const mode = process.env.NODE_ENV || 'development'
|
||||||
|
|
||||||
// External Requires
|
// External Requires
|
||||||
const express = require('express');
|
const express = require('express')
|
||||||
const app = express();
|
const app = express()
|
||||||
|
|
||||||
// Middleware
|
// Middleware
|
||||||
const compression = require('compression')
|
const compression = require('compression')
|
||||||
@ -17,80 +19,80 @@ const rateLimit = require('express-rate-limit')
|
|||||||
const authenticate= require('./src/middlewares/auth.middlewares')
|
const authenticate= require('./src/middlewares/auth.middlewares')
|
||||||
|
|
||||||
// Internal Requires
|
// Internal Requires
|
||||||
const log = require('./src/utils/log.utils'); // Log Helper
|
const log = require('./src/utils/log.utils') // Log Helper
|
||||||
const version = require('./src/configs/version.configs'); // Version Strings
|
const version = require('./src/configs/version.configs') // Version Strings
|
||||||
const listRtr = require('./src/routes/list.routes'); // /list endpoints
|
const listRtr = require('./src/routes/list.routes') // /list endpoints
|
||||||
const ldbRtr = require('./src/routes/ldb.routes'); // /ldb endpoints
|
const ldbRtr = require('./src/routes/ldb.routes') // /ldb endpoints
|
||||||
const kubeRtr = require('./src/routes/kube.routes'); // /kube endpoints
|
const kubeRtr = require('./src/routes/kube.routes') // /kube endpoints
|
||||||
const findRtr = require('./src/routes/find.routes'); // /find endpoints
|
const findRtr = require('./src/routes/find.routes') // /find endpoints
|
||||||
const issueRtr = require('./src/routes/issue.routes'); // /issue endpoints
|
const issueRtr = require('./src/routes/issue.routes') // /issue endpoints
|
||||||
const statRtr = require('./src/routes/stats.routes'); // /stat endpoints
|
const statRtr = require('./src/routes/stats.routes') // /stat endpoints
|
||||||
const regRtr = require('./src/routes/registration.routes'); // /registration endpoints
|
const regRtr = require('./src/routes/registration.routes') // /registration endpoints
|
||||||
const pisRtr = require('./src/routes/pis.routes'); // /pis endpoints
|
const pisRtr = require('./src/routes/pis.routes') // /pis endpoints
|
||||||
|
|
||||||
// Set Server Configurations
|
// Set Server Configurations
|
||||||
const srvListen = process.env.OWL_SRV_LISTEN || "0.0.0.0"
|
const srvListen = process.env.OWL_SRV_LISTEN || '0.0.0.0'
|
||||||
const srvPort = process.env.OWL_SRV_PORT || 8460
|
const srvPort = process.env.OWL_SRV_PORT || 8460
|
||||||
|
|
||||||
const limiter = rateLimit({
|
const limiter = rateLimit({
|
||||||
windowMs: 15 * (60 * 1000), // 15 minutes
|
windowMs: 15 * (60 * 1000), // 15 minutes
|
||||||
max: 100, // Limit each IP to 100 requests per `window` (here, per 15 minutes)
|
max: 100, // Limit each IP to 100 requests per `window` (here, per 15 minutes)
|
||||||
standardHeaders: true, // Return rate limit info in the `RateLimit-*` headers
|
standardHeaders: true, // Return rate limit info in the `RateLimit-*` headers
|
||||||
legacyHeaders: true, // Disable the `X-RateLimit-*` headers
|
legacyHeaders: true, // Disable the `X-RateLimit-*` headers
|
||||||
})
|
})
|
||||||
|
|
||||||
// Print version number:
|
// Print version number:
|
||||||
log.out(`app: Starting OwlBoard in ${mode} mode`, "init")
|
log.out(`app: Starting OwlBoard in ${mode} mode`, 'init')
|
||||||
log.out(`app: Starting OwlBoard - Backend Version: ${version.app} - API versions: ${version.api}`, "init");
|
log.out(`app: Starting OwlBoard - Backend Version: ${version.app} - API versions: ${version.api}`, 'init')
|
||||||
|
|
||||||
// Test for required vars:
|
// Test for required vars:
|
||||||
// const varTest = require('./src/utils/varTest.utils');
|
// const varTest = require('./src/utils/varTest.utils');
|
||||||
// var startTest = await varTest.varTest();
|
// var startTest = await varTest.varTest();
|
||||||
//console.log("Required Vars Missing:", startTest.missing_required);
|
//console.log("Required Vars Missing:", startTest.missing_required);
|
||||||
//console.log("Desired Vars Missing:", startTest.missing_desired);
|
//console.log("Desired Vars Missing:", startTest.missing_desired);
|
||||||
// if startTest.pass == false
|
// if startTest.pass == false
|
||||||
// console.log("Unable to start, missing required vars")
|
// console.log("Unable to start, missing required vars")
|
||||||
// exit app
|
// exit app
|
||||||
|
|
||||||
// Express Error Handling:
|
// Express Error Handling:
|
||||||
app.use((err, req, res, next) => {
|
app.use((err, req, res, next) => {
|
||||||
const statusCode = err.statuscode || 500;
|
const statusCode = err.statuscode || 500
|
||||||
console.error(err.message, err.stack);
|
console.error(err.message, err.stack)
|
||||||
res.status(statusCode).json({'message': err.message});
|
res.status(statusCode).json({'message': err.message})
|
||||||
return;
|
return
|
||||||
});
|
})
|
||||||
|
|
||||||
// Global Middleware:
|
// Global Middleware:
|
||||||
app.use(express.json()); //JSON Parsing for POST Requests
|
app.use(express.json()) //JSON Parsing for POST Requests
|
||||||
app.use(compression()) // Compress API Data if supported by client
|
app.use(compression()) // Compress API Data if supported by client
|
||||||
app.use(limiter)
|
app.use(limiter)
|
||||||
|
|
||||||
// Unauthenticated Routes
|
// Unauthenticated Routes
|
||||||
app.use('/api/v1/list', listRtr);
|
app.use('/api/v1/list', listRtr)
|
||||||
app.use('/api/v1/ldb', ldbRtr);
|
app.use('/api/v1/ldb', ldbRtr)
|
||||||
app.use('/api/v1/kube', kubeRtr);
|
app.use('/api/v1/kube', kubeRtr)
|
||||||
app.use('/api/v1/find', findRtr);
|
app.use('/api/v1/find', findRtr)
|
||||||
app.use('/api/v1/issue', issueRtr);
|
app.use('/api/v1/issue', issueRtr)
|
||||||
app.use('/api/v1/stats', statRtr);
|
app.use('/api/v1/stats', statRtr)
|
||||||
app.use('/api/v1/register', regRtr);
|
app.use('/api/v1/register', regRtr)
|
||||||
|
|
||||||
// Authented Routes
|
// Authented Routes
|
||||||
app.use('/api/v1/ldbs', authenticate, (req, res) => res.status(501).json({status: "Not Implemented", message: "This feature is not yet implemented due to upstream issues"}))
|
app.use('/api/v1/ldbs', authenticate, (req, res) => res.status(501).json({status: 'Not Implemented', message: 'This feature is not yet implemented due to upstream issues'}))
|
||||||
app.use('/api/v1/pis', authenticate, pisRtr)
|
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/auth/test', authenticate, (req, res) => res.status(200).json({status: 'ok', message: 'Authentication successful'})) // Returns 401 if auth failed, 200 if successful.
|
||||||
|
|
||||||
// Number of proxies:
|
// Number of proxies:
|
||||||
app.set('trust proxy', 4)
|
app.set('trust proxy', 4)
|
||||||
mode === "development"
|
mode === 'development'
|
||||||
? app.get('/api/v1/ip', (req, res) => res.send(req.ip))
|
? app.get('/api/v1/ip', (req, res) => res.send(req.ip))
|
||||||
: null
|
: null
|
||||||
|
|
||||||
// Start Express
|
// Start Express
|
||||||
app.listen(srvPort, srvListen, (error) =>{
|
app.listen(srvPort, srvListen, (error) =>{
|
||||||
if(!error) {
|
if(!error) {
|
||||||
log.out(`app.listen: Listening on http://${srvListen}:${srvPort}`, "init");
|
log.out(`app.listen: Listening on http://${srvListen}:${srvPort}`, 'init')
|
||||||
log.out("app.listen: State - alive", "init")
|
log.out('app.listen: State - alive', 'init')
|
||||||
} else {
|
} else {
|
||||||
log.out(`app.listen: Error occurred, server can't start ${error}`, "err");
|
log.out(`app.listen: Error occurred, server can't start ${error}`, 'err')
|
||||||
}
|
}
|
||||||
});
|
})
|
@ -1,10 +1,10 @@
|
|||||||
module.exports = statusCodes = {
|
module.exports = statusCodes = {
|
||||||
700: "no authentication attempt",
|
700: 'no authentication attempt',
|
||||||
701: "invalid credentials",
|
701: 'invalid credentials',
|
||||||
702: "domain not whitelisted",
|
702: 'domain not whitelisted',
|
||||||
703: "registration request not found, maybe expired",
|
703: 'registration request not found, maybe expired',
|
||||||
800: "location code not found",
|
800: 'location code not found',
|
||||||
801: "unable to fetch location data",
|
801: 'unable to fetch location data',
|
||||||
900: "invalid request format",
|
900: 'invalid request format',
|
||||||
950: "upstream server error",
|
950: 'upstream server error',
|
||||||
}
|
}
|
||||||
|
@ -1,58 +1,58 @@
|
|||||||
const find = require('../services/find.services');
|
const find = require('../services/find.services')
|
||||||
|
|
||||||
async function findName(req, res, next){
|
async function findName(req, res, next){
|
||||||
try {
|
try {
|
||||||
var id = req.params.id
|
var id = req.params.id
|
||||||
res.json(await find.name(id))
|
res.json(await find.name(id))
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`Unknown Error`, err.message);
|
console.error('Unknown Error', err.message)
|
||||||
next(err);
|
next(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function findCrs(req, res, next){
|
async function findCrs(req, res, next){
|
||||||
try {
|
try {
|
||||||
var id = req.params.id
|
var id = req.params.id
|
||||||
res.json(await find.crs(id))
|
res.json(await find.crs(id))
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`Unknown Error`, err.message);
|
console.error('Unknown Error', err.message)
|
||||||
next(err);
|
next(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function findNlc(req, res, next){
|
async function findNlc(req, res, next){
|
||||||
try {
|
try {
|
||||||
var id = req.params.id
|
var id = req.params.id
|
||||||
res.json(await find.nlc(id))
|
res.json(await find.nlc(id))
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`Unknown Error`, err.message);
|
console.error('Unknown Error', err.message)
|
||||||
next(err);
|
next(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function findTiploc(req, res, next){
|
async function findTiploc(req, res, next){
|
||||||
try {
|
try {
|
||||||
var id = req.params.id
|
var id = req.params.id
|
||||||
res.json(await find.tiploc(id))
|
res.json(await find.tiploc(id))
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`Unknown Error`, err.message);
|
console.error('Unknown Error', err.message)
|
||||||
next(err);
|
next(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function findStanox(req, res, next){
|
async function findStanox(req, res, next){
|
||||||
try {
|
try {
|
||||||
var id = req.params.id
|
var id = req.params.id
|
||||||
res.json(await find.stanox(id))
|
res.json(await find.stanox(id))
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`Unknown Error`, err.message);
|
console.error('Unknown Error', err.message)
|
||||||
next(err);
|
next(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
module.exports = {
|
module.exports = {
|
||||||
findName,
|
findName,
|
||||||
findCrs,
|
findCrs,
|
||||||
findNlc,
|
findNlc,
|
||||||
findTiploc,
|
findTiploc,
|
||||||
findStanox
|
findStanox
|
||||||
}
|
}
|
@ -1,14 +1,14 @@
|
|||||||
const issue = require('../services/issue.services');
|
const issue = require('../services/issue.services')
|
||||||
|
|
||||||
async function post(req, res, next){
|
async function post(req, res, next){
|
||||||
try {
|
try {
|
||||||
res.json(await issue.processor(req.body))
|
res.json(await issue.processor(req.body))
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`Controller Error`, err.message);
|
console.error('Controller Error', err.message)
|
||||||
next(err);
|
next(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
post
|
post
|
||||||
}
|
}
|
@ -1,35 +1,35 @@
|
|||||||
const kube = require('../services/kube.services');
|
const kube = require('../services/kube.services')
|
||||||
|
|
||||||
async function getAlive(req, res, next){
|
async function getAlive(req, res, next){
|
||||||
try {
|
try {
|
||||||
var state = kube.getAlive()
|
var state = kube.getAlive()
|
||||||
res.status((await state).code).send((await state).state)
|
res.status((await state).code).send((await state).state)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
res.status("503").send({state: "error"})
|
res.status('503').send({state: 'error'})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getReady(req, res, next){
|
async function getReady(req, res, next){
|
||||||
try {
|
try {
|
||||||
res.json(await kube.getReady(req.body))
|
res.json(await kube.getReady(req.body))
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`Unknown Error`, err.message);
|
console.error('Unknown Error', err.message)
|
||||||
next(err);
|
next(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getTime(req, res, next){
|
async function getTime(req, res, next){
|
||||||
try {
|
try {
|
||||||
res.json(await kube.getTime(req.body))
|
res.json(await kube.getTime(req.body))
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`Unknown Error`, err.message);
|
console.error('Unknown Error', err.message)
|
||||||
err.status = 503
|
err.status = 503
|
||||||
next(err);
|
next(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getAlive,
|
getAlive,
|
||||||
getReady,
|
getReady,
|
||||||
getTime
|
getTime
|
||||||
}
|
}
|
@ -1,16 +1,16 @@
|
|||||||
const ldb = require('../services/ldb.services');
|
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(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
|
||||||
next(err);
|
next(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
get
|
get
|
||||||
}
|
}
|
@ -1,16 +1,16 @@
|
|||||||
const ldb = require('../services/ldb.services');
|
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(id, true))
|
res.json(await ldb.get(id, true))
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`Unknown Error`, err.message);
|
console.error('Unknown Error', err.message)
|
||||||
err.status = 500
|
err.status = 500
|
||||||
next(err);
|
next(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
get
|
get
|
||||||
}
|
}
|
@ -1,37 +1,37 @@
|
|||||||
const list = require('../services/list.services');
|
const list = require('../services/list.services')
|
||||||
|
|
||||||
async function getStations(req, res, next){
|
async function getStations(req, res, next){
|
||||||
try {
|
try {
|
||||||
res.json(await list.getStations(req.body))
|
res.json(await list.getStations(req.body))
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`Controller Error`, err.message);
|
console.error('Controller Error', err.message)
|
||||||
err.status = 500
|
err.status = 500
|
||||||
next(err);
|
next(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getCorpus(req, res, next){
|
async function getCorpus(req, res, next){
|
||||||
try {
|
try {
|
||||||
res.json(await list.getCorpus(req.body))
|
res.json(await list.getCorpus(req.body))
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`Controller Error`, err.message);
|
console.error('Controller Error', err.message)
|
||||||
err.status = 500
|
err.status = 500
|
||||||
next(err);
|
next(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function hits(req, res, next) {
|
async function hits(req, res, next) {
|
||||||
try {
|
try {
|
||||||
res.json(await list.hits())
|
res.json(await list.hits())
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`Controller Error`, err);
|
console.error('Controller Error', err)
|
||||||
err.status = 500
|
err.status = 500
|
||||||
next(err);
|
next(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getStations,
|
getStations,
|
||||||
getCorpus,
|
getCorpus,
|
||||||
hits
|
hits
|
||||||
}
|
}
|
@ -1,17 +1,17 @@
|
|||||||
const pis = require('../services/pis.services');
|
const pis = require('../services/pis.services')
|
||||||
|
|
||||||
async function byOrigDest(req, res, next){
|
async function byOrigDest(req, res, next){
|
||||||
try {
|
try {
|
||||||
let start = req.params.start
|
let start = req.params.start
|
||||||
let end = req.params.end
|
let end = req.params.end
|
||||||
res.json(await pis.findPisByOrigDest(start,end))
|
res.json(await pis.findPisByOrigDest(start,end))
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`Unknown Error`, err.message);
|
console.error('Unknown Error', err.message)
|
||||||
next(err);
|
next(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
byOrigDest
|
byOrigDest
|
||||||
}
|
}
|
@ -1,26 +1,26 @@
|
|||||||
const reg = require('../services/registration.services');
|
const reg = require('../services/registration.services')
|
||||||
|
|
||||||
async function register(req, res, next) {
|
async function register(req, res, next) {
|
||||||
try {
|
try {
|
||||||
let response = await reg.regUser(req.body)
|
let response = await reg.regUser(req.body)
|
||||||
res.status(response.status).json(response)
|
res.status(response.status).json(response)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`Controller Error`, err.message)
|
console.error('Controller Error', err.message)
|
||||||
next(err)
|
next(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function request(req, res, next) {
|
async function request(req, res, next) {
|
||||||
try {
|
try {
|
||||||
let response = await reg.createRegKey(req.body)
|
let response = await reg.createRegKey(req.body)
|
||||||
res.status(response.status).json(response)
|
res.status(response.status).json(response)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
next(err)
|
next(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
register,
|
register,
|
||||||
request
|
request
|
||||||
}
|
}
|
@ -1,15 +1,15 @@
|
|||||||
const stat = require('../services/stats.services');
|
const stat = require('../services/stats.services')
|
||||||
|
|
||||||
async function get(req, res, next) {
|
async function get(req, res, next) {
|
||||||
try {
|
try {
|
||||||
res.json(await stat.hits())
|
res.json(await stat.hits())
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`Controller Error`, err);
|
console.error('Controller Error', err)
|
||||||
err.status = 500
|
err.status = 500
|
||||||
next(err);
|
next(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
get
|
get
|
||||||
}
|
}
|
@ -2,26 +2,26 @@ const utils = require('../utils/auth.utils')
|
|||||||
const log = require('../utils/log.utils')
|
const log = require('../utils/log.utils')
|
||||||
|
|
||||||
module.exports = async function authCheck(req, res, next) {
|
module.exports = async function authCheck(req, res, next) {
|
||||||
log.out(`authMiddlewares: Checking authentication`, "dbug")
|
log.out('authMiddlewares: Checking authentication', 'dbug')
|
||||||
try {
|
try {
|
||||||
var uuid = req.headers.uuid
|
var uuid = req.headers.uuid
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
log.out(`authMiddlewares: No authentication attempted`, "dbug")
|
log.out('authMiddlewares: No authentication attempted', 'dbug')
|
||||||
err.status = 401
|
err.status = 401
|
||||||
return next(err)
|
return next(err)
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
var result = await utils.isAuthed(uuid) || false
|
var result = await utils.isAuthed(uuid) || false
|
||||||
if (!result) {
|
if (!result) {
|
||||||
const err = new Error("Unauthorised");
|
const err = new Error('Unauthorised')
|
||||||
err.status = 401
|
err.status = 401
|
||||||
log.out(`authMiddlewares: Authentication attempted with incorrect key`, "warn")
|
log.out('authMiddlewares: Authentication attempted with incorrect key', 'warn')
|
||||||
return next(err)
|
return next(err)
|
||||||
} else {
|
} else {
|
||||||
log.out(`authMiddlewares: User authenticated`, "dbug")
|
log.out('authMiddlewares: User authenticated', 'dbug')
|
||||||
return next()
|
return next()
|
||||||
}
|
|
||||||
} catch(err) {
|
|
||||||
return next(err)
|
|
||||||
}
|
}
|
||||||
|
} catch(err) {
|
||||||
|
return next(err)
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,12 +1,12 @@
|
|||||||
const log = require('../utils/log.utils')
|
const log = require('../utils/log.utils')
|
||||||
|
|
||||||
module.exports = async function requireJson(req, res, next) {
|
module.exports = async function requireJson(req, res, next) {
|
||||||
if (req.headers['content-type'] !== 'application/json') {
|
if (req.headers['content-type'] !== 'application/json') {
|
||||||
log.out(`requireJson.middlewares: Bad Request: Not in JSON format`)
|
log.out('requireJson.middlewares: Bad Request: Not in JSON format')
|
||||||
res.status(400).send({status: 400, message: "Server requires JSON"})
|
res.status(400).send({status: 400, message: 'Server requires JSON'})
|
||||||
} else {
|
} else {
|
||||||
next()
|
next()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Possibly want to check the req type?
|
// Possibly want to check the req type?
|
@ -1,6 +1,6 @@
|
|||||||
const express = require('express');
|
const express = require('express')
|
||||||
const router = express.Router();
|
const router = express.Router()
|
||||||
const findController = require('../controllers/find.controllers');
|
const findController = require('../controllers/find.controllers')
|
||||||
|
|
||||||
/* GET programming languages. */
|
/* GET programming languages. */
|
||||||
//router.get('/', programmingLanguagesController.get);
|
//router.get('/', programmingLanguagesController.get);
|
||||||
@ -14,10 +14,10 @@ const findController = require('../controllers/find.controllers');
|
|||||||
/* DELETE programming language */
|
/* DELETE programming language */
|
||||||
//router.delete('/:id', programmingLanguagesController.remove);
|
//router.delete('/:id', programmingLanguagesController.remove);
|
||||||
|
|
||||||
router.get('/name/:id', findController.findName);
|
router.get('/name/:id', findController.findName)
|
||||||
router.get('/crs/:id', findController.findCrs);
|
router.get('/crs/:id', findController.findCrs)
|
||||||
router.get('/nlc/:id', findController.findNlc);
|
router.get('/nlc/:id', findController.findNlc)
|
||||||
router.get('/tiploc/:id', findController.findTiploc);
|
router.get('/tiploc/:id', findController.findTiploc)
|
||||||
router.get('/stanox/:id', findController.findStanox);
|
router.get('/stanox/:id', findController.findStanox)
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router
|
@ -1,7 +1,7 @@
|
|||||||
const express = require('express');
|
const express = require('express')
|
||||||
const router = express.Router();
|
const router = express.Router()
|
||||||
const issueController = require('../controllers/issue.controllers');
|
const issueController = require('../controllers/issue.controllers')
|
||||||
|
|
||||||
router.post('/', issueController.post);
|
router.post('/', issueController.post)
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router
|
@ -1,9 +1,9 @@
|
|||||||
const express = require('express');
|
const express = require('express')
|
||||||
const router = express.Router();
|
const router = express.Router()
|
||||||
const kubeController = require('../controllers/kube.controllers');
|
const kubeController = require('../controllers/kube.controllers')
|
||||||
|
|
||||||
router.get('/alive', kubeController.getAlive);
|
router.get('/alive', kubeController.getAlive)
|
||||||
router.get('/ready', kubeController.getReady);
|
router.get('/ready', kubeController.getReady)
|
||||||
router.get('/time', kubeController.getTime);
|
router.get('/time', kubeController.getTime)
|
||||||
|
|
||||||
module.exports = router
|
module.exports = router
|
@ -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 ldbController = require('../controllers/ldb.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', ldbController.get)
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router
|
@ -1,6 +1,6 @@
|
|||||||
const express = require('express');
|
const express = require('express')
|
||||||
const router = express.Router();
|
const router = express.Router()
|
||||||
const ldbsController = require('../controllers/ldbs.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 ldbsController = require('../controllers/ldbs.controllers');
|
|||||||
/* DELETE programming language */
|
/* DELETE programming language */
|
||||||
//router.delete('/:id', programmingLanguagesController.remove);
|
//router.delete('/:id', programmingLanguagesController.remove);
|
||||||
|
|
||||||
router.get('/:id', ldbsController.get);
|
router.get('/:id', ldbsController.get)
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router
|
@ -1,6 +1,6 @@
|
|||||||
const express = require('express');
|
const express = require('express')
|
||||||
const router = express.Router();
|
const router = express.Router()
|
||||||
const listController = require('../controllers/list.controllers');
|
const listController = require('../controllers/list.controllers')
|
||||||
|
|
||||||
/* GET programming languages. */
|
/* GET programming languages. */
|
||||||
//router.get('/', programmingLanguagesController.get);
|
//router.get('/', programmingLanguagesController.get);
|
||||||
@ -14,7 +14,7 @@ const listController = require('../controllers/list.controllers');
|
|||||||
/* DELETE programming language */
|
/* DELETE programming language */
|
||||||
//router.delete('/:id', programmingLanguagesController.remove);
|
//router.delete('/:id', programmingLanguagesController.remove);
|
||||||
|
|
||||||
router.get('/stations', listController.getStations);
|
router.get('/stations', listController.getStations)
|
||||||
router.get('/corpus', listController.getCorpus);
|
router.get('/corpus', listController.getCorpus)
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router
|
@ -1,7 +1,7 @@
|
|||||||
const express = require('express');
|
const express = require('express')
|
||||||
const router = express.Router();
|
const router = express.Router()
|
||||||
const pisController = require('../controllers/pis.controllers');
|
const pisController = require('../controllers/pis.controllers')
|
||||||
|
|
||||||
router.get('/origdest/:start/:end', pisController.byOrigDest);
|
router.get('/origdest/:start/:end', pisController.byOrigDest)
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router
|
@ -1,8 +1,8 @@
|
|||||||
const express = require('express');
|
const express = require('express')
|
||||||
const router = express.Router();
|
const router = express.Router()
|
||||||
const regController = require('../controllers/registration.controllers');
|
const regController = require('../controllers/registration.controllers')
|
||||||
|
|
||||||
router.post('/request', regController.request);
|
router.post('/request', regController.request)
|
||||||
router.post('/register', regController.register)
|
router.post('/register', regController.register)
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router
|
@ -1,8 +1,8 @@
|
|||||||
const express = require('express');
|
const express = require('express')
|
||||||
const router = express.Router();
|
const router = express.Router()
|
||||||
const statsController = require('../controllers/stats.controllers');
|
const statsController = require('../controllers/stats.controllers')
|
||||||
|
|
||||||
|
|
||||||
router.get('/', statsController.get);
|
router.get('/', statsController.get)
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router
|
@ -1,14 +1,10 @@
|
|||||||
|
/* global process */
|
||||||
const log = require('../utils/log.utils') // Log Helper
|
const log = require('../utils/log.utils') // Log Helper
|
||||||
|
|
||||||
// eslint-disable-next-line no-undef
|
|
||||||
const dbUser = process.env.OWL_DB_USER || 'owl'
|
const dbUser = process.env.OWL_DB_USER || 'owl'
|
||||||
// eslint-disable-next-line no-undef
|
|
||||||
const dbPass = process.env.OWL_DB_PASS || 'twittwoo'
|
const dbPass = process.env.OWL_DB_PASS || 'twittwoo'
|
||||||
// eslint-disable-next-line no-undef
|
|
||||||
const dbName = process.env.OWL_DB_NAME || 'owlboard'
|
const dbName = process.env.OWL_DB_NAME || 'owlboard'
|
||||||
// eslint-disable-next-line no-undef
|
|
||||||
const dbPort = process.env.OWL_DB_PORT || 27017
|
const dbPort = process.env.OWL_DB_PORT || 27017
|
||||||
// eslint-disable-next-line no-undef
|
|
||||||
const dbHost = process.env.OWL_DB_HOST || 'localhost'
|
const dbHost = process.env.OWL_DB_HOST || 'localhost'
|
||||||
const uri = `mongodb://${dbUser}:${dbPass}@${dbHost}:${dbPort}`
|
const uri = `mongodb://${dbUser}:${dbPass}@${dbHost}:${dbPort}`
|
||||||
|
|
||||||
|
@ -1,59 +1,59 @@
|
|||||||
// Parse and return a find request
|
// Parse and return a find request
|
||||||
|
|
||||||
const log = require('../utils/log.utils'); // Log Helper
|
const log = require('../utils/log.utils') // Log Helper
|
||||||
const db = require('../services/dbAccess.services');
|
const db = require('../services/dbAccess.services')
|
||||||
const san = require('../utils/sanitizer.utils')
|
const san = require('../utils/sanitizer.utils')
|
||||||
|
|
||||||
// DB Query: query(collection, query)
|
// DB Query: query(collection, query)
|
||||||
|
|
||||||
// Define collection as all queries are for the "corpus" collection.
|
// Define collection as all queries are for the "corpus" collection.
|
||||||
const col = "corpus"
|
const col = 'corpus'
|
||||||
|
|
||||||
async function name(id){
|
async function name(id){
|
||||||
log.out(`findServices.name: Finding station name: ${id}`, "info")
|
log.out(`findServices.name: Finding station name: ${id}`, 'info')
|
||||||
var name = san.cleanApiEndpointTxt(id.toUpperCase())
|
var name = san.cleanApiEndpointTxt(id.toUpperCase())
|
||||||
query = {NLCDESC: name}
|
let query = {NLCDESC: name}
|
||||||
//var data = await db.query(col,query)
|
//var data = await db.query(col,query)
|
||||||
return await db.query(col,query)
|
return await db.query(col,query)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function crs(id){
|
async function crs(id){
|
||||||
log.out(`findServices.crs: Finding crs: ${id}`, "info")
|
log.out(`findServices.crs: Finding crs: ${id}`, 'info')
|
||||||
var crs = san.cleanApiEndpointTxt(id.toUpperCase())
|
var crs = san.cleanApiEndpointTxt(id.toUpperCase())
|
||||||
query = {'3ALPHA': crs}
|
let query = {'3ALPHA': crs}
|
||||||
//var data = await db.query(col,query)
|
//var data = await db.query(col,query)
|
||||||
return await db.query(col,query)
|
return await db.query(col,query)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function nlc(id){
|
async function nlc(id){
|
||||||
log.out(`findServices.nlc: Finding nlc: ${id}`, "info")
|
log.out(`findServices.nlc: Finding nlc: ${id}`, 'info')
|
||||||
var nlc = san.cleanApiEndpointNum(id)
|
var nlc = san.cleanApiEndpointNum(id)
|
||||||
query = {NLC: parseInt(nlc)}
|
let query = {NLC: parseInt(nlc)}
|
||||||
log.out(`findServices.nlc: NLC Converted to int: ${query}`, "info")
|
log.out(`findServices.nlc: NLC Converted to int: ${query}`, 'info')
|
||||||
//var data = await db.query(col,query)
|
//var data = await db.query(col,query)
|
||||||
return await db.query(col,query)
|
return await db.query(col,query)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function tiploc(id){
|
async function tiploc(id){
|
||||||
log.out(`findServices.tiploc: Finding tiploc: ${id}`, "info")
|
log.out(`findServices.tiploc: Finding tiploc: ${id}`, 'info')
|
||||||
var tiploc = san.cleanApiEndpointTxt(id.toUpperCase())
|
var tiploc = san.cleanApiEndpointTxt(id.toUpperCase())
|
||||||
query = {TIPLOC: tiploc}
|
let query = {TIPLOC: tiploc}
|
||||||
//var data = await db.query(col,query)
|
//var data = await db.query(col,query)
|
||||||
return await db.query(col,query)
|
return await db.query(col,query)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function stanox(id){
|
async function stanox(id){
|
||||||
log.out(`findServices.stanox: Finding stanox: ${id}`, "info")
|
log.out(`findServices.stanox: Finding stanox: ${id}`, 'info')
|
||||||
var stanox = san.cleanApiEndpointNum(id)
|
var stanox = san.cleanApiEndpointNum(id)
|
||||||
query = {STANOX: String(stanox)}
|
let query = {STANOX: String(stanox)}
|
||||||
//var data = await db.query(col,query)
|
//var data = await db.query(col,query)
|
||||||
return await db.query(col,query)
|
return await db.query(col,query)
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name,
|
name,
|
||||||
crs,
|
crs,
|
||||||
nlc,
|
nlc,
|
||||||
tiploc,
|
tiploc,
|
||||||
stanox
|
stanox
|
||||||
}
|
}
|
@ -1,33 +1,35 @@
|
|||||||
|
/* eslint-disable no-useless-escape */
|
||||||
|
/* global process */
|
||||||
const axios = require('axios')
|
const axios = require('axios')
|
||||||
const log = require('../utils/log.utils')
|
const log = require('../utils/log.utils')
|
||||||
|
|
||||||
async function processor(data) {
|
async function processor(data) {
|
||||||
log.out(`issueService.processor: Issue received`, "info")
|
log.out('issueService.processor: Issue received', 'info')
|
||||||
let out = {}
|
let out = {}
|
||||||
out.title = data.subject.replace(/<[^>]+>|[\*\$]/g, '');
|
out.title = data.subject.replace(/<[^>]+>|[\*\$]/g, '')
|
||||||
out.body = data.msg.replace(/<[^>]+>|[\*\$]/g, '')
|
out.body = data.msg.replace(/<[^>]+>|[\*\$]/g, '')
|
||||||
return await sendToGitea(out);
|
return await sendToGitea(out)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function sendToGitea(body) {
|
async function sendToGitea(body) {
|
||||||
let key = process.env.OWL_GIT_ISSUEBOT
|
let key = process.env.OWL_GIT_ISSUEBOT
|
||||||
let url = process.env.OWL_GIT_APIENDPOINT
|
let url = process.env.OWL_GIT_APIENDPOINT
|
||||||
let opts = {
|
let opts = {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: key
|
Authorization: key
|
||||||
}
|
|
||||||
}
|
|
||||||
var res = await axios.post(url, body, opts)
|
|
||||||
// Need to read the output from the POST and pass the result upwards to the client.
|
|
||||||
if (res.status == 201) {
|
|
||||||
log.out("issueService.sendToGitea: Issue sent to Gitea", "info")
|
|
||||||
return {status: res.status,message:"issue created"}
|
|
||||||
} else {
|
|
||||||
log.out(`issueService.sendToGitea: Failed to send issue to Gitea: ${res.body}`, "err")
|
|
||||||
return {status: res.status,message:"issue not created"}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
var res = await axios.post(url, body, opts)
|
||||||
|
// Need to read the output from the POST and pass the result upwards to the client.
|
||||||
|
if (res.status == 201) {
|
||||||
|
log.out('issueService.sendToGitea: Issue sent to Gitea', 'info')
|
||||||
|
return {status: res.status,message:'issue created'}
|
||||||
|
} else {
|
||||||
|
log.out(`issueService.sendToGitea: Failed to send issue to Gitea: ${res.body}`, 'err')
|
||||||
|
return {status: res.status,message:'issue not created'}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
processor
|
processor
|
||||||
}
|
}
|
@ -2,27 +2,27 @@ const testing = require('../services/mail.services')
|
|||||||
const log = require('../utils/log.utils')
|
const log = require('../utils/log.utils')
|
||||||
|
|
||||||
async function getAlive(){
|
async function getAlive(){
|
||||||
log.out(`kubeServices.getAlive: alive hook checked`, "info")
|
log.out('kubeServices.getAlive: alive hook checked', 'info')
|
||||||
return {code: 200, state: {state: "alive",noise: "twit-twoo"}}
|
return {code: 200, state: {state: 'alive',noise: 'twit-twoo'}}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getReady(){
|
async function getReady(){
|
||||||
log.out(`kubeServices.getReady: ready hook checked`, "info")
|
log.out('kubeServices.getReady: ready hook checked', 'info')
|
||||||
testing.send({
|
testing.send({
|
||||||
to: "fred@fjla.uk",
|
to: 'fred@fjla.uk',
|
||||||
subject: "OwlBoard Test",
|
subject: 'OwlBoard Test',
|
||||||
txt: "This is a test message from OwlBoard (testing)"
|
txt: 'This is a test message from OwlBoard (testing)'
|
||||||
});
|
})
|
||||||
return "not_implemented";
|
return 'not_implemented'
|
||||||
};
|
}
|
||||||
|
|
||||||
async function getTime(){
|
async function getTime(){
|
||||||
var now = new Date()
|
var now = new Date()
|
||||||
return {responseGenerated: now}
|
return {responseGenerated: now}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getAlive,
|
getAlive,
|
||||||
getReady,
|
getReady,
|
||||||
getTime
|
getTime
|
||||||
}
|
}
|
@ -1,6 +1,7 @@
|
|||||||
|
/* global process */
|
||||||
// Parse and return an LDB Request
|
// Parse and return an LDB Request
|
||||||
|
|
||||||
const log = require('../utils/log.utils'); // Log Helper
|
const log = require('../utils/log.utils') // Log Helper
|
||||||
const ldb = require('ldbs-json')
|
const ldb = require('ldbs-json')
|
||||||
const util = require('../utils/ldb.utils')
|
const util = require('../utils/ldb.utils')
|
||||||
const san = require('../utils/sanitizer.utils')
|
const san = require('../utils/sanitizer.utils')
|
||||||
@ -10,57 +11,57 @@ const ldbKey = process.env.OWL_LDB_KEY
|
|||||||
const ldbsvKey = process.env.OWL_LDB_SVKEY
|
const ldbsvKey = process.env.OWL_LDB_SVKEY
|
||||||
|
|
||||||
async function get(id, staff=false){
|
async function get(id, staff=false){
|
||||||
const cleanId = san.cleanApiEndpointTxt(id);
|
const cleanId = san.cleanApiEndpointTxt(id)
|
||||||
const obj = await util.checkCrs(cleanId);
|
const obj = await util.checkCrs(cleanId)
|
||||||
try {
|
try {
|
||||||
const crs = obj[0]['3ALPHA'];
|
const crs = obj[0]['3ALPHA']
|
||||||
log.out(`ldbService.get: Determined CRS for lookup to be: ${crs}`, "info");
|
log.out(`ldbService.get: Determined CRS for lookup to be: ${crs}`, 'info')
|
||||||
if (staff) {
|
if (staff) {
|
||||||
const data = arrDepBoardStaff(crs)
|
const data = arrDepBoardStaff(crs)
|
||||||
db.increment("ldbsvws")
|
db.increment('ldbsvws')
|
||||||
return await data
|
return await data
|
||||||
} else {
|
} else {
|
||||||
const data = arrDepBoard(crs);
|
const data = arrDepBoard(crs)
|
||||||
db.increment("ldbws");
|
db.increment('ldbws')
|
||||||
return await data
|
return await data
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
log.out(`ldbService.get: Error, Unable to find CRS: ${err}`, "info")
|
|
||||||
return {ERROR:'NOT_FOUND',description:'The entered station was not found. Please check and try again.'};
|
|
||||||
}
|
}
|
||||||
|
} catch (err) {
|
||||||
|
log.out(`ldbService.get: Error, Unable to find CRS: ${err}`, 'info')
|
||||||
|
return {ERROR:'NOT_FOUND',description:'The entered station was not found. Please check and try again.'}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function arrDepBoard(CRS){
|
async function arrDepBoard(CRS){
|
||||||
log.out(`ldbService.arrDepBoard: Trying to fetch ArrDep Board for ${CRS}`, "info")
|
log.out(`ldbService.arrDepBoard: Trying to fetch ArrDep Board for ${CRS}`, 'info')
|
||||||
try {
|
try {
|
||||||
const options = {
|
const options = {
|
||||||
numRows: 10,
|
numRows: 10,
|
||||||
crs: CRS.toUpperCase()
|
crs: CRS.toUpperCase()
|
||||||
}
|
|
||||||
const api = new ldb(ldbKey,false)
|
|
||||||
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.`};
|
|
||||||
}
|
}
|
||||||
|
const api = new ldb(ldbKey,false)
|
||||||
|
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) {
|
async function arrDepBoardStaff(CRS) {
|
||||||
log.out(`ldbService.arrDepBoardStaff: Trying to fetch ArrDep Board for ${CRS}`, "dbug")
|
log.out(`ldbService.arrDepBoardStaff: Trying to fetch ArrDep Board for ${CRS}`, 'dbug')
|
||||||
try {
|
try {
|
||||||
const options = {
|
const options = {
|
||||||
numRows: 25,
|
numRows: 25,
|
||||||
crs: CRS.toUpperCase(),
|
crs: CRS.toUpperCase(),
|
||||||
getNonPassengerServices: true
|
getNonPassengerServices: true
|
||||||
}
|
|
||||||
const api = new ldb(ldbsvKey,true)
|
|
||||||
return await api.call("GetArrDepBoardWithDetails", options, false, false)
|
|
||||||
} 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.`};
|
|
||||||
}
|
}
|
||||||
|
const api = new ldb(ldbsvKey,true)
|
||||||
|
return await api.call('GetArrDepBoardWithDetails', options, false, false)
|
||||||
|
} 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
|
||||||
}
|
}
|
@ -1,20 +1,19 @@
|
|||||||
const log = require('../utils/log.utils'); // Log Helper
|
const log = require('../utils/log.utils') // Log Helper
|
||||||
const db = require('../services/dbAccess.services')
|
const db = require('../services/dbAccess.services')
|
||||||
const os = require('os')
|
|
||||||
|
|
||||||
async function getStations(){
|
async function getStations(){
|
||||||
var out = db.query("stations")
|
var out = db.query('stations')
|
||||||
log.out(`listServices.getStations: Fetching stations list`, "info")
|
log.out('listServices.getStations: Fetching stations list', 'info')
|
||||||
return await out;
|
return await out
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getCorpus(){
|
async function getCorpus(){
|
||||||
var out = db.query("corpus")
|
var out = db.query('corpus')
|
||||||
log.out(`listServices.getCorpus: Fetching CORPUS list`, "info")
|
log.out('listServices.getCorpus: Fetching CORPUS list', 'info')
|
||||||
return await out;
|
return await out
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getStations,
|
getStations,
|
||||||
getCorpus
|
getCorpus
|
||||||
}
|
}
|
@ -1,3 +1,4 @@
|
|||||||
|
/* global process */
|
||||||
const log = require('../utils/log.utils')
|
const log = require('../utils/log.utils')
|
||||||
const mail = require('nodemailer') //>> Probs wrong
|
const mail = require('nodemailer') //>> Probs wrong
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ async function createRegKey(body) {
|
|||||||
if (!message) {
|
if (!message) {
|
||||||
const err = new Error('Message generation error')
|
const err = new Error('Message generation error')
|
||||||
log.out('registerServices.createRegKey: Error generating registration email', 'err')
|
log.out('registerServices.createRegKey: Error generating registration email', 'err')
|
||||||
|
log.out(err, 'err')
|
||||||
return 500
|
return 500
|
||||||
}
|
}
|
||||||
if (await mail.send(message) == true) {
|
if (await mail.send(message) == true) {
|
||||||
|
@ -1,49 +1,49 @@
|
|||||||
const log = require('../utils/log.utils'); // Log Helper
|
const log = require('../utils/log.utils') // Log Helper
|
||||||
const db = require('../services/dbAccess.services') // DB Access
|
const db = require('../services/dbAccess.services') // DB Access
|
||||||
const san = require('../utils/sanitizer.utils') // Sanitiser
|
const san = require('../utils/sanitizer.utils') // Sanitiser
|
||||||
|
|
||||||
async function checkCrs(input){
|
async function checkCrs(input){
|
||||||
var INPUT = input.toUpperCase()
|
var INPUT = input.toUpperCase()
|
||||||
log.out(`ldbUtils.checkCrs: Building database query to find: '${INPUT}'`, "info")
|
log.out(`ldbUtils.checkCrs: Building database query to find: '${INPUT}'`, 'info')
|
||||||
var query = {
|
var query = {
|
||||||
'$or':[
|
'$or':[
|
||||||
{'3ALPHA':INPUT},
|
{'3ALPHA':INPUT},
|
||||||
{'TIPLOC':INPUT},
|
{'TIPLOC':INPUT},
|
||||||
{'STANOX':INPUT}
|
{'STANOX':INPUT}
|
||||||
]
|
]
|
||||||
};
|
}
|
||||||
var result = await db.query("stations", query)
|
var result = await db.query('stations', query)
|
||||||
log.out(`ldbUtils.checkCrs: Query results: ${JSON.stringify(result)}`, "dbug")
|
log.out(`ldbUtils.checkCrs: Query results: ${JSON.stringify(result)}`, 'dbug')
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
async function cleanMessages(input){ // Needs to be moved to the frontend `ensureArray() func`
|
async function cleanMessages(input){ // Needs to be moved to the frontend `ensureArray() func`
|
||||||
var out = []
|
var out = []
|
||||||
if (typeof input.message == "string") {
|
if (typeof input.message == 'string') {
|
||||||
out.push(await san.cleanNrcc(input.message))
|
out.push(await san.cleanNrcc(input.message))
|
||||||
} else if (typeof input.message == "object") {
|
} else if (typeof input.message == 'object') {
|
||||||
for(var i = 0; i < input.message.length; i++) {
|
for(var i = 0; i < input.message.length; i++) {
|
||||||
out.push(await san.cleanNrcc(input.message[i]))
|
out.push(await san.cleanNrcc(input.message[i]))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return out;
|
}
|
||||||
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
// Accepts an object but not an Array and returns it wrapped in an array.
|
// Accepts an object but not an Array and returns it wrapped in an array.
|
||||||
async function cleanServices(input){ // Need to triple check but I don't think this is used anymore.
|
async function cleanServices(input){ // Need to triple check but I don't think this is used anymore.
|
||||||
var out = []
|
var out = []
|
||||||
if (!Array.isArray(input)) {
|
if (!Array.isArray(input)) {
|
||||||
log.out(`ldbUtils.cleanServices: Transforming input: ${input}`, "depr")
|
log.out(`ldbUtils.cleanServices: Transforming input: ${input}`, 'depr')
|
||||||
out.push(input)
|
out.push(input)
|
||||||
log.out(`ldbUtils.cleanServices: Returning output: ${out}`, "depr")
|
log.out(`ldbUtils.cleanServices: Returning output: ${out}`, 'depr')
|
||||||
return out;
|
return out
|
||||||
} else {
|
} else {
|
||||||
return input;
|
return input
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
checkCrs,
|
checkCrs,
|
||||||
cleanMessages,
|
cleanMessages,
|
||||||
cleanServices
|
cleanServices
|
||||||
}
|
}
|
@ -1,16 +1,17 @@
|
|||||||
const environment = process.env.NODE_ENV;
|
/* global process */
|
||||||
|
const environment = process.env.NODE_ENV
|
||||||
|
|
||||||
const hideInProduction = ["info", "dbug"]
|
const hideInProduction = ['info', 'dbug']
|
||||||
|
|
||||||
async function out(msg, level = 'othr') {
|
async function out(msg, level = 'othr') {
|
||||||
if (environment === "production" && hideInProduction.includes(level.toLowerCase())) {
|
if (environment === 'production' && hideInProduction.includes(level.toLowerCase())) {
|
||||||
return;
|
return
|
||||||
} else {
|
} else {
|
||||||
const time = new Date().toISOString();
|
const time = new Date().toISOString()
|
||||||
console.log(`${time} - ${level.toUpperCase()} - ${msg}`);
|
console.log(`${time} - ${level.toUpperCase()} - ${msg}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
out
|
out
|
||||||
}
|
}
|
@ -1,12 +1,12 @@
|
|||||||
//const clean = require('string-sanitizer-fix');
|
//const clean = require('string-sanitizer-fix');
|
||||||
const log = require('../utils/log.utils');
|
const log = require('../utils/log.utils')
|
||||||
|
|
||||||
function removeNonAlphanumeric(inputString) { // Should be able to replace sanitizer module
|
function removeNonAlphanumeric(inputString) { // Should be able to replace sanitizer module
|
||||||
return inputString.replace(/[^a-zA-Z0-9]/g, '');
|
return inputString.replace(/[^a-zA-Z0-9]/g, '')
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeNonAlpha(inputString) { // Should be able to replace sanitizer module
|
function removeNonAlpha(inputString) { // Should be able to replace sanitizer module
|
||||||
return inputString.replace(/[^a-zA-Z]/g, '');
|
return inputString.replace(/[^a-zA-Z]/g, '')
|
||||||
}
|
}
|
||||||
|
|
||||||
const cleanApiEndpointTxt = removeNonAlpha
|
const cleanApiEndpointTxt = removeNonAlpha
|
||||||
@ -30,20 +30,20 @@ function cleanApiEndpointNum(input) {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
function cleanNrcc(input) { // Remove newlines and then <p> tags from input
|
function cleanNrcc(input) { // Remove newlines and then <p> tags from input
|
||||||
const cleanInput = input.replace(/[\n\r]/g, '').replace(/<\/?p[^>]*>/g, '');
|
const cleanInput = input.replace(/[\n\r]/g, '').replace(/<\/?p[^>]*>/g, '')
|
||||||
return cleanInput;
|
return cleanInput
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getDomainFromEmail(mail) { // Needs testing
|
async function getDomainFromEmail(mail) { // Needs testing
|
||||||
split = mail.split("@")
|
let split = mail.split('@')
|
||||||
return split[1]
|
return split[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
cleanApiEndpointTxt,
|
cleanApiEndpointTxt,
|
||||||
cleanApiEndpointNum,
|
cleanApiEndpointNum,
|
||||||
removeNonAlpha,
|
removeNonAlpha,
|
||||||
removeNonAlphanumeric,
|
removeNonAlphanumeric,
|
||||||
cleanNrcc,
|
cleanNrcc,
|
||||||
getDomainFromEmail,
|
getDomainFromEmail,
|
||||||
}
|
}
|
@ -1,15 +1,15 @@
|
|||||||
function unixLocal(unix) {
|
function unixLocal(unix) {
|
||||||
var jsTime = unix*1000
|
var jsTime = unix*1000
|
||||||
var dt = new Date(jsTime)
|
var dt = new Date(jsTime)
|
||||||
return dt.toLocaleString()
|
return dt.toLocaleString()
|
||||||
}
|
}
|
||||||
|
|
||||||
function jsUnix(js) {
|
function jsUnix(js) {
|
||||||
var preRound = js / 1000
|
var preRound = js / 1000
|
||||||
return Math.round(preRound)
|
return Math.round(preRound)
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
unixLocal,
|
unixLocal,
|
||||||
jsUnix,
|
jsUnix,
|
||||||
}
|
}
|
@ -1,27 +1,28 @@
|
|||||||
|
/* global process */
|
||||||
// Checks that all required environment variables are present.
|
// Checks that all required environment variables are present.
|
||||||
// Returns True or False and offers an object detailing what is missing.
|
// Returns True or False and offers an object detailing what is missing.
|
||||||
|
|
||||||
async function varTest(){
|
async function varTest(){
|
||||||
var required = {
|
var required = {
|
||||||
OWL_LDB_KEY: process.env.OWL_LDB_KEY,
|
OWL_LDB_KEY: process.env.OWL_LDB_KEY,
|
||||||
OWL_LDB_CORPUSUSER: process.env.OWL_LDB_CORPUSUSER,
|
OWL_LDB_CORPUSUSER: process.env.OWL_LDB_CORPUSUSER,
|
||||||
OWL_LDB_CORPUSPASS: process.env.OWL_LDB_CORPUSPASS,
|
OWL_LDB_CORPUSPASS: process.env.OWL_LDB_CORPUSPASS,
|
||||||
OWL_NOT_USED: process.env.OWL_NOT_USED
|
OWL_NOT_USED: process.env.OWL_NOT_USED
|
||||||
}
|
}
|
||||||
var desired = {
|
var desired = {
|
||||||
OWL_DB_PASS: process.env.OWL_DB_PASS
|
OWL_DB_PASS: process.env.OWL_DB_PASS
|
||||||
}
|
}
|
||||||
// DO NOT LOG CREDENTIALS!!!
|
// DO NOT LOG CREDENTIALS!!!
|
||||||
|
|
||||||
// Test that each of required is NOT undefined.
|
// Test that each of required is NOT undefined.
|
||||||
// var pass = true if all okay, false if not.
|
// var pass = true if all okay, false if not.
|
||||||
// Append any missing values to missing_required = []
|
// Append any missing values to missing_required = []
|
||||||
// Test that each of desired is NOT undefined.
|
// Test that each of desired is NOT undefined.
|
||||||
// Append any missing values to missing_desired = []
|
// Append any missing values to missing_desired = []
|
||||||
|
|
||||||
// Return : {pass: $pass, missong_required = $missing_required, missing_desired = $missing_desired}
|
// Return : {pass: $pass, missong_required = $missing_required, missing_desired = $missing_desired}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
varTest
|
varTest
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user