From f5d3b16f27a591a2895fcdaf3316916ec108cdc9 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Sun, 24 Jan 2021 15:36:03 +0100 Subject: [PATCH] isAdmin default value = false. --- api/controllers/lotteryWinnerController.js | 5 +++-- api/lottery.js | 8 ++------ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/api/controllers/lotteryWinnerController.js b/api/controllers/lotteryWinnerController.js index 13109e1..9187653 100644 --- a/api/controllers/lotteryWinnerController.js +++ b/api/controllers/lotteryWinnerController.js @@ -78,9 +78,10 @@ const allWinners = (req, res) => { const winnerById = (req, res) => { const { id } = req.params; + const isAdmin = req.isAuthenticated(); return lotteryRepository - .winnerById(id) + .winnerById(id, isAdmin) .then(winner => res.send({ winner, @@ -98,7 +99,7 @@ const winnerById = (req, res) => { }; const deleteWinnerById = (req, res) => { - const isAdmin = req.isAuthenticated() || true; + const isAdmin = req.isAuthenticated(); const { id } = req.params; return lotteryRepository diff --git a/api/lottery.js b/api/lottery.js index f50f0f5..dee8b96 100644 --- a/api/lottery.js +++ b/api/lottery.js @@ -71,7 +71,7 @@ const redactWinnerInfoMapper = winner => { }; }; -const allAttendees = isAdmin => { +const allAttendees = (isAdmin = false) => { if (!isAdmin) { return Attendee.find().then(attendees => attendees.map(redactAttendeeInfoMapper)); } else { @@ -101,8 +101,6 @@ const updateAttendeeById = (id, updateModel) => { throw new UserNotFound(); } - console.log(updateModel); - const updatedAttendee = { name: updateModel.name != null ? updateModel.name : attendee.name, green: updateModel.green != null ? updateModel.green : attendee.green, @@ -113,8 +111,6 @@ const updateAttendeeById = (id, updateModel) => { winner: updateModel.winner != null ? updateModel.winner : attendee.winner }; - console.log(updatedAttendee); - return Attendee.updateOne({ _id: id }, updatedAttendee).then(_ => updatedAttendee); }); }; @@ -211,7 +207,7 @@ const allWinners = (isAdmin = false) => { } }; -const winnerById = (id, isAdmin) => { +const winnerById = (id, isAdmin = false) => { return VirtualWinner.findOne({ _id: id }).then(winner => { if (winner == null) { throw new WinnerNotFound();