Migrate regisstration.services to new logger

Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
Fred Boniface 2023-09-28 14:43:11 +01:00
parent 648c72fa34
commit 7c40f2fd98

View File

@ -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,