From 8ffd2687457620117ac49f4d20a7f0b3cc8d4e60 Mon Sep 17 00:00:00 2001 From: Idan Stark Date: Sun, 9 Feb 2020 00:53:36 +0200 Subject: [PATCH 1/3] Added a bunch of logs --- server/scores.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/server/scores.js b/server/scores.js index 716a6909f..78b7d5ee5 100644 --- a/server/scores.js +++ b/server/scores.js @@ -119,6 +119,7 @@ module.exports = function createScoringRouter (authenticationMiddleware) { .then(([scoringCollection, score]) => { score.creation = score.lastUpdate req.logger.info(`Saving score for team ${score.teamNumber} on ${score.stage} stage with ${score.score} pts.`) + req.logger.debug(JSON.stringify(score)) return scoringCollection.insertOne(score) }) .then(({ ops, insertedId }) => { @@ -136,13 +137,17 @@ module.exports = function createScoringRouter (authenticationMiddleware) { }) router.post('/:id/update', authenticationMiddleware, adminOrScorekeeperAction, (req, res) => { + const shouldUpdateLastTime = (req.query['shouldUpdateLastTime'] === 'true') + const updatedScore = Object.assign(scoreFromQuery(req.body), shouldUpdateLastTime ? { lastUpdate: new Date() } : { }) connectionPromise .then(scoringCollection => { - const shouldUpdateLastTime = (req.query['shouldUpdateLastTime'] === 'true') - const updatedScore = Object.assign(scoreFromQuery(req.body), shouldUpdateLastTime ? { lastUpdate: new Date() } : { }) return scoringCollection.updateOne({ _id: req.params.id }, { $set: updatedScore }) }) - .then(() => res.status(204).send()) + .then(() => { + req.logger.info(`Updating score for team ${updatedScore.teamNumber} on ${updatedScore.stage} stage with ${updatedScore.score} pts.`) + req.logger.debug(JSON.stringify(updatedScore)) + res.status(204).send() + }) .then(() => publishMsg('scores:reload', { id: req.params.id, action: 'update' })) .catch(err => { req.logger.error(err.message) @@ -157,7 +162,10 @@ module.exports = function createScoringRouter (authenticationMiddleware) { router.delete('/all', authenticationMiddleware, adminAction, (req, res) => { connectionPromise .then(scoringCollection => scoringCollection.deleteMany({})) - .then(() => res.status(204).send()) + .then(() => { + req.logger.info(`Deleting all scores.`) + res.status(204).send() + }) .then(() => publishMsg('scores:reload', { action: 'delete all' })) .catch(err => { req.logger.error(err.message) @@ -168,7 +176,10 @@ module.exports = function createScoringRouter (authenticationMiddleware) { router.delete('/:id/delete', authenticationMiddleware, adminOrScorekeeperAction, (req, res) => { connectionPromise .then(scoringCollection => scoringCollection.deleteOne({ _id: req.params.id })) - .then(() => res.status(204).send()) + .then(() => { + req.logger.info(`Deleting score with id ${req.params.id}.`) + res.status(204).send() + }) .then(() => publishMsg('scores:reload', { id: req.params.id, action: 'delete' })) .catch(err => { req.logger.error(err.message) From ccee4fe1b97421b1ff56616ce3d1712b7153b6e8 Mon Sep 17 00:00:00 2001 From: idanstark42 Date: Mon, 10 Feb 2020 19:09:58 +0200 Subject: [PATCH 2/3] Update scores.js --- server/scores.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/scores.js b/server/scores.js index 78b7d5ee5..2f4313474 100644 --- a/server/scores.js +++ b/server/scores.js @@ -119,7 +119,7 @@ module.exports = function createScoringRouter (authenticationMiddleware) { .then(([scoringCollection, score]) => { score.creation = score.lastUpdate req.logger.info(`Saving score for team ${score.teamNumber} on ${score.stage} stage with ${score.score} pts.`) - req.logger.debug(JSON.stringify(score)) + req.logger.info(JSON.stringify(score)) return scoringCollection.insertOne(score) }) .then(({ ops, insertedId }) => { @@ -145,7 +145,7 @@ module.exports = function createScoringRouter (authenticationMiddleware) { }) .then(() => { req.logger.info(`Updating score for team ${updatedScore.teamNumber} on ${updatedScore.stage} stage with ${updatedScore.score} pts.`) - req.logger.debug(JSON.stringify(updatedScore)) + req.logger.info(JSON.stringify(updatedScore)) res.status(204).send() }) .then(() => publishMsg('scores:reload', { id: req.params.id, action: 'update' })) From 664475cbcc3d62b2208e1d040e22fc7c01b393db Mon Sep 17 00:00:00 2001 From: alang Date: Tue, 18 Feb 2020 20:52:32 +0200 Subject: [PATCH 3/3] Add log CREATE/UPDATE --- server/scores.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/scores.js b/server/scores.js index 9e2f367e7..380f28b0c 100644 --- a/server/scores.js +++ b/server/scores.js @@ -119,7 +119,7 @@ module.exports = function createScoringRouter (authenticationMiddleware) { .then(([scoringCollection, score]) => { score.creation = score.lastUpdate req.logger.info(`Saving score for team ${score.teamNumber} on ${score.stage} stage with ${score.score} pts.`) - req.logger.info(JSON.stringify(score)) + req.logger.info(`CREATE ${JSON.stringify(score)}`) return scoringCollection.insertOne(score) }) .then(({ ops, insertedId }) => { @@ -145,7 +145,7 @@ module.exports = function createScoringRouter (authenticationMiddleware) { }) .then(() => { req.logger.info(`Updating score for team ${updatedScore.teamNumber} on ${updatedScore.stage} stage with ${updatedScore.score} pts.`) - req.logger.info(JSON.stringify(updatedScore)) + req.logger.info(`UPDATE ${JSON.stringify(updatedScore)}`) res.status(204).send() }) .then(() => publishMsg('scores:reload', { id: req.params.id, action: 'update' }))