From 7c40f2fd982f9b81ecdf56ad3472f73ca4bd4372 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Thu, 28 Sep 2023 14:43:11 +0100 Subject: [PATCH] Migrate regisstration.services to new logger Signed-off-by: Fred Boniface --- src/services/registration.services.js | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/services/registration.services.js b/src/services/registration.services.js index 36f6710..c23c1a9 100644 --- a/src/services/registration.services.js +++ b/src/services/registration.services.js @@ -1,4 +1,3 @@ -const log = require("../utils/logs.utils"); const auth = require("../utils/auth.utils"); const db = require("./dbAccess.services"); const mail = require("./mail.services"); @@ -6,23 +5,21 @@ const clean = require("../utils/sanitizer.utils"); const domains = require("../configs/domains.configs"); const errors = require("../configs/errorCodes.configs"); +import { logger } from "../utils/logger.utils"; + async function createRegKey(body) { - log.out("registerServices.createRegKey: Incoming request", "INFO"); + logger.debug("registerServices.createRegKey: Incoming request"); if (body.email) { const domain = await clean.getDomainFromEmail(body.email); - log.out(`registerServices: Registration request from: ${domain}`, "info"); + logger.info(`registerServices: Registration request from: ${domain}`); if (domains.includes(domain)) { - log.out( - `registerServices.createRegKey: Key from valid: ${domain}`, - "info" - ); + logger.debug(`registerServices.createRegKey: Key from valid: ${domain}`); const uuid = await auth.generateKey(); db.addRegReq(uuid, domain); const message = await auth.generateConfirmationEmail(body.email, uuid); if (!message) { const err = new Error("Message generation error"); - log.out("registerServices.createRegKey: Error generating email", "err"); - log.out(err, "err"); + logger.error(err, 'registerServices.createRegKey: Error generating email'); return 500; } if ((await mail.send(message)) == true) { @@ -38,10 +35,9 @@ async function createRegKey(body) { async function regUser(req) { // Add input validation - log.out(`Read UUID: ${req.uuid}`, "dbug"); - log.out(`registrationServices.regUser: Request from: ${req.uuid}`, "info"); + logger.trace(`Read UUID: ${req.uuid}`); const res = await auth.checkRequest(req.uuid); - log.out(`registrationServices.regUser: ${JSON.stringify(res)}`, "info"); + logger.debug(res, 'registrationServices'); if (res.result) { const uuid = await auth.generateKey(); const apiKey = await db.addUser(uuid, res.domain); @@ -54,7 +50,6 @@ async function regUser(req) { } async function getUser(uuid) { - log.out("registrationServices: Finding user for given UUID", "dbug"); try { const filter = { uuid: uuid,