Add functions for staff API Call if I can get the API KEY!

Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
Fred Boniface 2023-04-12 13:54:06 +01:00
parent f1c616e9e0
commit ebd4d1e7a8

View File

@ -10,29 +10,34 @@ const ldbKey = process.env.OWL_LDB_KEY
const ldbsvKey = process.env.OWL_LDB_SVKEY
async function get(id, staff=false){
var cleanId = san.cleanApiEndpointTxt(id);
var obj = await util.checkCrs(cleanId);
const cleanId = san.cleanApiEndpointTxt(id);
const obj = await util.checkCrs(cleanId);
try {
var crs = obj[0]['3ALPHA'];
const crs = obj[0]['3ALPHA'];
log.out(`ldbService.get: Determined CRS for lookup to be: ${crs}`, "info");
var data = arrDepBoard(crs);
db.increment("ldbws");
await data;
if (staff) {
const data = arrDepBoardStaff(crs)
db.increment("ldbsvws")
return await data
} else {
const data = arrDepBoard(crs);
db.increment("ldbws");
return await data
}
} catch (err) {
log.out(`ldbService.get: Error, Unable to find CRS: ${err}`, "info")
var data = {ERROR:'NOT_FOUND',description:'The entered station was not found. Please check and try again.'};
return {ERROR:'NOT_FOUND',description:'The entered station was not found. Please check and try again.'};
}
return data;
}
async function arrDepBoard(CRS){
log.out(`ldbService.arrDepBoard: Trying to fetch ArrDep Board for ${CRS}`, "info")
try {
var options = {
const options = {
numRows: 10,
crs: CRS.toUpperCase()
}
var api = new ldb(ldbKey,false)
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")
@ -45,10 +50,11 @@ async function arrDepBoardStaff(CRS) {
try {
const options = {
numRows: 25,
crs: CRS.toUpperCase()
crs: CRS.toUpperCase(),
getNonPassengerServices: true
}
const api = new ldb(ldbsvKey,true)
return await api.call("Unknown") // Need to find out the syntax of this!
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.`};