Port ldb module to new logger
Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
parent
f29ff277ce
commit
9a6679f0d9
@ -1,11 +1,12 @@
|
||||
// Parse and return an LDB Request
|
||||
|
||||
const log = require("../utils/logs.utils"); // Log Helper
|
||||
const ldb = require("ldbs-json");
|
||||
const util = require("../utils/ldb.utils");
|
||||
const san = require("../utils/sanitizer.utils");
|
||||
const db = require("../services/dbAccess.services");
|
||||
|
||||
import { logger } from "../utils/logger.utils";
|
||||
|
||||
import { transform as staffStationTransform } from "../utils/translators/ldb/staffStation";
|
||||
import { msgCodes } from "../configs/errorCodes.configs";
|
||||
|
||||
@ -17,7 +18,7 @@ async function get(id, staff = false) {
|
||||
const obj = await util.checkCrs(cleanId);
|
||||
try {
|
||||
const crs = obj[0]["3ALPHA"];
|
||||
log.out(`ldbService.get: Determined CRS for lookup to be: ${crs}`, "info");
|
||||
logger.debug(`ldbService.get: Determined CRS for lookup to be: ${crs}`)
|
||||
if (staff) {
|
||||
const data = arrDepBoardStaff(crs);
|
||||
db.increment("ldbsvws");
|
||||
@ -28,7 +29,7 @@ async function get(id, staff = false) {
|
||||
return await data;
|
||||
}
|
||||
} catch (err) {
|
||||
log.out(`ldbService.get: Error, Unable to find CRS: ${err}`, "info");
|
||||
logger.error(err, "ldbService.get: Error, Unable to find CRS")
|
||||
return {
|
||||
obStatus: "LOC_NOT_FOUND",
|
||||
obMsg: "UNABLE TO FIND MESSAGE",
|
||||
@ -37,7 +38,7 @@ async function get(id, staff = false) {
|
||||
}
|
||||
|
||||
async function arrDepBoard(CRS) {
|
||||
log.out(`ldbService.arrDepBoard: Trying to fetch board for ${CRS}`, "info");
|
||||
logger.trace(`ldbService.arrDepBoard: Trying to fetch board for ${CRS}`)
|
||||
try {
|
||||
const options = {
|
||||
numRows: 10,
|
||||
@ -47,7 +48,7 @@ async function arrDepBoard(CRS) {
|
||||
let d = await api.call("GetArrDepBoardWithDetails", options, false, false);
|
||||
return await util.cleanData(d);
|
||||
} catch (err) {
|
||||
log.out(`ldbService.arrDepBoard: Lookup Failed for: ${CRS}`, "warn");
|
||||
logger.error(err, "ldbService.arrDepBoard: Lookup Failed")
|
||||
return {
|
||||
GetStationBoardResult: "not available",
|
||||
Reason: `The CRS code ${CRS} is not valid`,
|
||||
@ -56,7 +57,7 @@ async function arrDepBoard(CRS) {
|
||||
}
|
||||
|
||||
async function arrDepBoardStaff(CRS) {
|
||||
log.out(`ldbService.arrDepBoardStaff: Try to fetch board for ${CRS}`, "dbug");
|
||||
logger.debug(`ldbService.arrDepBoardStaff: Try to fetch board for ${CRS}`)
|
||||
try {
|
||||
const options = {
|
||||
numRows: 40,
|
||||
@ -74,23 +75,24 @@ async function arrDepBoardStaff(CRS) {
|
||||
false,
|
||||
false
|
||||
);
|
||||
console.log("\n\n\nORIGINAL DATA")
|
||||
console.log("\n" + result + "\n\n\n")
|
||||
console.timeEnd(`Fetch Staff LDB for ${CRS.toUpperCase()}`);
|
||||
try {
|
||||
const _staffLdb = staffStationTransform(result);
|
||||
console.log("Transformation Test Successful");
|
||||
console.log(JSON.stringify(_staffLdb));
|
||||
logger.debug("StaffLDB Transformed")
|
||||
logger.trace(_staffLdb, "StaffLDB Transformed")
|
||||
return {
|
||||
obStatus: "OK",
|
||||
obMsg: "OK",
|
||||
data: _staffLdb,
|
||||
};
|
||||
} catch (err) {
|
||||
console.log("Transformation Test Failed: " + err);
|
||||
logger.error(err, "Transformation Error")
|
||||
}
|
||||
return result;
|
||||
} catch (err) {
|
||||
log.out(`ldbService.arrDepBoardStaff: Lookup Failed for: ${CRS}`, "warn");
|
||||
log.out(`ldbService.arrDepBoardStaff: ${err}`);
|
||||
logger.error(err, "ldbService.arrDepBoardStaff error")
|
||||
return {
|
||||
GetStationBoardResult: "not available",
|
||||
Reason: `The CRS code ${CRS} is not valid`,
|
||||
@ -99,7 +101,7 @@ async function arrDepBoardStaff(CRS) {
|
||||
}
|
||||
|
||||
async function getServiceByRID(rid) {
|
||||
log.out(`ldbService.getServiceByRID: Finding RID: ${rid}`, "dbug");
|
||||
logger.debug(`ldbService.getServiceByRID: Finding RID: ${rid}`);
|
||||
try {
|
||||
const options = {
|
||||
rid: String(rid),
|
||||
@ -107,12 +109,12 @@ async function getServiceByRID(rid) {
|
||||
const api = new ldb(ldbsvKey, true);
|
||||
return await api.call("GetServiceDetailsByRID", options, false, false);
|
||||
} catch (err) {
|
||||
log.out(`ldbService.queryService: ${err}`, "EROR");
|
||||
logger.error(err, `ldbService.queryService`);
|
||||
}
|
||||
}
|
||||
|
||||
async function getServicesByOther(id) {
|
||||
log.out(`ldbService.getServiceByOther: Finding services: ${id}`, "dbug");
|
||||
logger.debug(`ldbService.getServiceByOther: Finding services: ${id}`);
|
||||
try {
|
||||
const options = {
|
||||
serviceID: id,
|
||||
@ -121,30 +123,30 @@ async function getServicesByOther(id) {
|
||||
const api = new ldb(ldbsvKey, true);
|
||||
return await api.call("QueryServices", options, false, false);
|
||||
} catch (err) {
|
||||
log.out(`ldbService.getServiceByOther: Error: ${err}`, "EROR");
|
||||
logger.error(err, "ldbService.getServiceByOther")
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async function getReasonCodeList() {
|
||||
log.out("ldbService.getReasonCodeList: Fetching reason code list", "eror");
|
||||
logger.debug("ldbService.getReasonCodeList: Fetching reason code list")
|
||||
try {
|
||||
const dbFilter = {};
|
||||
return await db.query("reasonCodes", dbFilter, false);
|
||||
} catch (err) {
|
||||
log.out(`ldbService.getReasonCodeList: ${err}`, "eror");
|
||||
logger.error(err, "ldbService.getReasonCodeList")
|
||||
}
|
||||
}
|
||||
|
||||
async function getReasonCode(code) {
|
||||
log.out(`ldbService.getReasonCode: Fetching reason code ${code}`, "dbug");
|
||||
logger.debug(`ldbService.getReasonCode: Fetching reason code ${code}`);
|
||||
try {
|
||||
const dbFilter = {
|
||||
code: code,
|
||||
};
|
||||
return await db.query("reasonCodes", dbFilter, false);
|
||||
} catch (err) {
|
||||
log.out(`ldbService.getReasonCode: ${err}`, "eror");
|
||||
logger.error(err, "ldbService.getReasonCode")
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user