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
1 changed files with 18 additions and 12 deletions

View File

@ -10,29 +10,34 @@ 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){
var cleanId = san.cleanApiEndpointTxt(id); const cleanId = san.cleanApiEndpointTxt(id);
var obj = await util.checkCrs(cleanId); const obj = await util.checkCrs(cleanId);
try { try {
var 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");
var data = arrDepBoard(crs); if (staff) {
db.increment("ldbws"); const data = arrDepBoardStaff(crs)
await data; db.increment("ldbsvws")
return await data
} else {
const data = arrDepBoard(crs);
db.increment("ldbws");
return await data
}
} catch (err) { } catch (err) {
log.out(`ldbService.get: Error, Unable to find CRS: ${err}`, "info") 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){ 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 {
var options = { const options = {
numRows: 10, numRows: 10,
crs: CRS.toUpperCase() crs: CRS.toUpperCase()
} }
var api = new ldb(ldbKey,false) const api = new ldb(ldbKey,false)
return await api.call("GetArrDepBoardWithDetails", options, false, false) return await api.call("GetArrDepBoardWithDetails", options, false, false)
} catch (err) { } catch (err) {
log.out(`ldbService.arrDepBoard: Lookup Failed for: ${CRS}`, "warn") log.out(`ldbService.arrDepBoard: Lookup Failed for: ${CRS}`, "warn")
@ -45,10 +50,11 @@ async function arrDepBoardStaff(CRS) {
try { try {
const options = { const options = {
numRows: 25, numRows: 25,
crs: CRS.toUpperCase() crs: CRS.toUpperCase(),
getNonPassengerServices: true
} }
const api = new ldb(ldbsvKey,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) { } catch (err) {
log.out(`ldbService.arrDepBoardStaff: Lookup Failed for: ${CRS}, "warn`) 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.`}; 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.`};