This repository has been archived on 2023-08-24. You can view files and clone it, but cannot push or open issues or pull requests.
OwlBoard/src/services/ldb.services.js
2023-01-05 21:00:39 +00:00

48 lines
1.5 KiB
JavaScript

// Parse and return an LDB Request
// FUNCTIONS
// 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 log = require('../utils/log.utils'); // Log Helper
const ldb = require('ldbs-json')
const util = require('../utils/ldb.utils')
const ldbKey = process.env.OWL_LDB_KEY
const ldbsvKey = process.env.OWL_LDB_SVKEY
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) with the id from the url directly used - UNSAFE
var output = await arrDepBoard(id)
return output
}
async function arrDepBoard(CRS){
var valid = await util.checkCrs(CRS)
log.out(`ldbService: Fetching ArrDep Board for ${CRS}`)
if (valid != false){
var options = {
numRows: 10,
crs: CRS.toUpperCase()
}
var api = new ldb(ldbKey,false)
var reply = await api.call("GetArrDepBoardWithDetails",options)
return reply
} else if (valid == false) {
return {status: false, reason: "Invalid CRS/3alpha code"};
}
};
module.exports = {
get
}