From c808364444e275dd91ba8126752c9a594eb162ed Mon Sep 17 00:00:00 2001 From: Abheek Dhawan Date: Tue, 29 Mar 2022 22:39:07 -0500 Subject: [PATCH] Improve logging for user score creation --- src/helpers/db.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/helpers/db.ts b/src/helpers/db.ts index afd7952..fac2f83 100644 --- a/src/helpers/db.ts +++ b/src/helpers/db.ts @@ -14,11 +14,14 @@ export async function updateScore(isCorrect, score, authorId) { authorID: authorId, score: score, }); - newUserScore.save((err) => - err - ? console.log('Error creating new user for scoring') - : console.log('Sucessfully created user to score.'), - ); + newUserScore.save(err => { + if (err) { + log({ logger: 'db', content: `Error creating new user ${authorId} for scoring`, level: 'error' }); + } + else { + log({ logger: 'db', content: `Successfully created user ${authorId} for scoring`, level: 'debug' }); + } + }); } else { // TODO: Error handling @@ -41,4 +44,4 @@ export async function connect(mongoUri) { }) .then(() => log({ logger: 'db', content: `Connected to the database at ${mongoUri}!`, level: 'info' })) .catch(err => log({ logger: 'db', content: `Failed to connect to the database at ${mongoUri}: ${err}`, level: 'fatal' })); -} \ No newline at end of file +}