From ac2b6c2b8882353b11560fabbd07bdc72fa38f7b Mon Sep 17 00:00:00 2001 From: rui hildt Date: Tue, 1 Sep 2020 18:57:33 +0200 Subject: [PATCH] Fix id spreadng order bug and consistency in use --- api/routes/accountRoute.js | 8 ++++---- api/routes/availabilityRoute.js | 2 +- api/routes/meetingRoute.js | 16 +++++++++------- api/routes/participantRoute.js | 2 +- api/routes/possibleDateRoute.js | 2 +- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/api/routes/accountRoute.js b/api/routes/accountRoute.js index 4b9f458..725d107 100644 --- a/api/routes/accountRoute.js +++ b/api/routes/accountRoute.js @@ -8,8 +8,8 @@ const { validateAccountID } = require('../../middlewares/validateAccountID'); const Account = require('../models/accountModel'); +// TODO : remove if unused router.post('/', async (req, res) => { - // TODO : remove if unused const data = { ...req.body }; const hash = bcrypt.hashSync(data.password, saltingRounds); data.password = hash; @@ -24,7 +24,7 @@ router.post('/', async (req, res) => { router.put('/:id', authenticate, validateAccountID, async (req, res) => { const data = { ...req.body }; - const id = req.params.id; + const { id } = req.params; if (data.password) { const hash = bcrypt.hashSync(data.password, 10); @@ -43,7 +43,7 @@ router.put('/:id', authenticate, validateAccountID, async (req, res) => { }); router.delete('/:id', authenticate, validateAccountID, async (req, res) => { - const id = req.params.id; + const { id } = req.params; try { const account = await Account.deleteAccount(id); @@ -84,7 +84,7 @@ router.get( ); router.get('/:id', authenticate, async (req, res) => { - const id = req.params.id; + const { id } = req.params; try { const account = await Account.getAccountById(id); diff --git a/api/routes/availabilityRoute.js b/api/routes/availabilityRoute.js index 1024ebb..66692f4 100644 --- a/api/routes/availabilityRoute.js +++ b/api/routes/availabilityRoute.js @@ -19,7 +19,7 @@ router.post('/', authenticate, async (req, res) => { }); router.delete('/:id', authenticate, async (req, res) => { - const id = req.params.id; + const { id } = req.params; try { const availability = await Availability.deleteAvailability(id); diff --git a/api/routes/meetingRoute.js b/api/routes/meetingRoute.js index 7bcf4d7..c58d23b 100644 --- a/api/routes/meetingRoute.js +++ b/api/routes/meetingRoute.js @@ -9,7 +9,8 @@ const Meeting = require('../models/meetingModel'); router.post('/', authenticate, async (req, res) => { id = uuidv4(); - data = { id, ...req.body }; + + data = { ...req.body, id }; if (data.password) { const hash = bcrypt.hashSync(data.password, 14); @@ -20,13 +21,14 @@ router.post('/', authenticate, async (req, res) => { const [meeting] = await Meeting.addMeeting(data); res.status(201).json(meeting); } catch (error) { + console.log(error); res.status(500).json({ message: 'Failed to add new meeting.', error }); } }); router.put('/:id', authenticate, validateMeetingID, async (req, res) => { const data = { ...req.body }; - const id = req.params.id; + const { id } = req.params; if (data.password) { const hash = bcrypt.hashSync(data.password, 14); @@ -45,7 +47,7 @@ router.put('/:id', authenticate, validateMeetingID, async (req, res) => { }); router.delete('/:id', authenticate, validateMeetingID, async (req, res) => { - const id = req.params.id; + const { id } = req.params; try { const meeting = await Meeting.deleteMeeting(id); @@ -61,7 +63,7 @@ router.delete('/:id', authenticate, validateMeetingID, async (req, res) => { }); router.get('/:id', authenticate, async (req, res) => { - const id = req.params.id; + const { id } = req.params; try { const meeting = await Meeting.getMeetingById(id); @@ -85,7 +87,7 @@ router.get( authenticate, validateMeetingID, async (req, res) => { - const id = req.params.id; + const { id } = req.params; try { const participants = await Meeting.getParticipantsByMeetingId(id); @@ -110,7 +112,7 @@ router.get( authenticate, validateMeetingID, async (req, res) => { - const id = req.params.id; + const { id } = req.params; try { const possibleDates = await Meeting.getPossibleDatesByMeetingId(id); @@ -135,7 +137,7 @@ router.get( authenticate, validateMeetingID, async (req, res) => { - const id = req.params.id; + const { id } = req.params; try { const availability = await Meeting.getAvailabilityByMeetingId(id); diff --git a/api/routes/participantRoute.js b/api/routes/participantRoute.js index f2798ba..d9dc063 100644 --- a/api/routes/participantRoute.js +++ b/api/routes/participantRoute.js @@ -10,7 +10,7 @@ const Participant = require('../models/participantModel'); router.post('/', authenticate, async (req, res) => { id = uuidv4(); - const data = { id, ...req.body }; + const data = { ...req.body, id }; try { const [participant] = await Participant.addParticipant(data); diff --git a/api/routes/possibleDateRoute.js b/api/routes/possibleDateRoute.js index 25c8528..d5bb230 100644 --- a/api/routes/possibleDateRoute.js +++ b/api/routes/possibleDateRoute.js @@ -19,7 +19,7 @@ router.post('/', authenticate, async (req, res) => { }); router.delete('/:id', authenticate, async (req, res) => { - const id = req.params.id; + const { id } = req.params; try { const possibleDate = await PossibleDate.deletePossibleDate(id);