Migrate trainService.service to new logger

Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
Fred Boniface 2023-09-28 14:53:46 +01:00
parent dc9a5e15da
commit c6552489e1

View File

@ -1,15 +1,12 @@
const log = require("../utils/logs.utils");
const db = require("./dbAccess.services"); const db = require("./dbAccess.services");
const clean = require("../utils/sanitizer.utils"); const clean = require("../utils/sanitizer.utils");
const pis = require("../services/pis.services"); const pis = require("../services/pis.services");
import { logger } from "../utils/logger.utils";
async function findByHeadcodeToday(headcode) { async function findByHeadcodeToday(headcode) {
const sanitizedHeadcode = clean.removeNonAlphanumeric(headcode).toUpperCase(); const sanitizedHeadcode = clean.removeNonAlphanumeric(headcode).toUpperCase();
log.out( logger.debug(`trainServiceServices.findByHeadcode: Searching for headcode ${sanitizedHeadcode}`);
"trainServiceServices.findByHeadcode: Searching for headcode " +
sanitizedHeadcode,
"dbug"
);
const now = new Date(); const now = new Date();
const dayMap = ["su", "m", "t", "w", "th", "f", "s"]; const dayMap = ["su", "m", "t", "w", "th", "f", "s"];
const shortDay = dayMap[now.getDay()]; // Fetch short day from map const shortDay = dayMap[now.getDay()]; // Fetch short day from map
@ -42,11 +39,7 @@ async function findByHeadcodeToday(headcode) {
async function findByHeadcode(date, headcode) { async function findByHeadcode(date, headcode) {
const sanitizedHeadcode = clean.removeNonAlphanumeric(headcode).toUpperCase(); const sanitizedHeadcode = clean.removeNonAlphanumeric(headcode).toUpperCase();
log.out( logger.debug(`trainServiceServices.findByHeadcode: Searching for headcode ${sanitizedHeadcode}`);
"trainServiceServices.findByHeadcode: Searching for headcode " +
sanitizedHeadcode,
"dbug"
);
let searchDate; let searchDate;
if (date === "now") { if (date === "now") {
searchDate = new Date(); searchDate = new Date();
@ -81,7 +74,6 @@ async function findByHeadcode(date, headcode) {
}, },
]; ];
const queryData = await db.queryAggregate("timetable", pipeline); const queryData = await db.queryAggregate("timetable", pipeline);
console.log(JSON.stringify(queryData));
let filteredData = filterServices(queryData); let filteredData = filterServices(queryData);
return await filteredData; return await filteredData;
} }