Fix id spreadng order bug and consistency in use

This commit is contained in:
rui hildt 2020-09-01 18:57:33 +02:00
parent 3490f71fc3
commit ac2b6c2b88
5 changed files with 16 additions and 14 deletions

View File

@ -8,8 +8,8 @@ const { validateAccountID } = require('../../middlewares/validateAccountID');
const Account = require('../models/accountModel'); const Account = require('../models/accountModel');
router.post('/', async (req, res) => {
// TODO : remove if unused // TODO : remove if unused
router.post('/', async (req, res) => {
const data = { ...req.body }; const data = { ...req.body };
const hash = bcrypt.hashSync(data.password, saltingRounds); const hash = bcrypt.hashSync(data.password, saltingRounds);
data.password = hash; data.password = hash;
@ -24,7 +24,7 @@ router.post('/', async (req, res) => {
router.put('/:id', authenticate, validateAccountID, async (req, res) => { router.put('/:id', authenticate, validateAccountID, async (req, res) => {
const data = { ...req.body }; const data = { ...req.body };
const id = req.params.id; const { id } = req.params;
if (data.password) { if (data.password) {
const hash = bcrypt.hashSync(data.password, 10); 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) => { router.delete('/:id', authenticate, validateAccountID, async (req, res) => {
const id = req.params.id; const { id } = req.params;
try { try {
const account = await Account.deleteAccount(id); const account = await Account.deleteAccount(id);
@ -84,7 +84,7 @@ router.get(
); );
router.get('/:id', authenticate, async (req, res) => { router.get('/:id', authenticate, async (req, res) => {
const id = req.params.id; const { id } = req.params;
try { try {
const account = await Account.getAccountById(id); const account = await Account.getAccountById(id);

View File

@ -19,7 +19,7 @@ router.post('/', authenticate, async (req, res) => {
}); });
router.delete('/:id', authenticate, async (req, res) => { router.delete('/:id', authenticate, async (req, res) => {
const id = req.params.id; const { id } = req.params;
try { try {
const availability = await Availability.deleteAvailability(id); const availability = await Availability.deleteAvailability(id);

View File

@ -9,7 +9,8 @@ const Meeting = require('../models/meetingModel');
router.post('/', authenticate, async (req, res) => { router.post('/', authenticate, async (req, res) => {
id = uuidv4(); id = uuidv4();
data = { id, ...req.body };
data = { ...req.body, id };
if (data.password) { if (data.password) {
const hash = bcrypt.hashSync(data.password, 14); const hash = bcrypt.hashSync(data.password, 14);
@ -20,13 +21,14 @@ router.post('/', authenticate, async (req, res) => {
const [meeting] = await Meeting.addMeeting(data); const [meeting] = await Meeting.addMeeting(data);
res.status(201).json(meeting); res.status(201).json(meeting);
} catch (error) { } catch (error) {
console.log(error);
res.status(500).json({ message: 'Failed to add new meeting.', error }); res.status(500).json({ message: 'Failed to add new meeting.', error });
} }
}); });
router.put('/:id', authenticate, validateMeetingID, async (req, res) => { router.put('/:id', authenticate, validateMeetingID, async (req, res) => {
const data = { ...req.body }; const data = { ...req.body };
const id = req.params.id; const { id } = req.params;
if (data.password) { if (data.password) {
const hash = bcrypt.hashSync(data.password, 14); 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) => { router.delete('/:id', authenticate, validateMeetingID, async (req, res) => {
const id = req.params.id; const { id } = req.params;
try { try {
const meeting = await Meeting.deleteMeeting(id); 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) => { router.get('/:id', authenticate, async (req, res) => {
const id = req.params.id; const { id } = req.params;
try { try {
const meeting = await Meeting.getMeetingById(id); const meeting = await Meeting.getMeetingById(id);
@ -85,7 +87,7 @@ router.get(
authenticate, authenticate,
validateMeetingID, validateMeetingID,
async (req, res) => { async (req, res) => {
const id = req.params.id; const { id } = req.params;
try { try {
const participants = await Meeting.getParticipantsByMeetingId(id); const participants = await Meeting.getParticipantsByMeetingId(id);
@ -110,7 +112,7 @@ router.get(
authenticate, authenticate,
validateMeetingID, validateMeetingID,
async (req, res) => { async (req, res) => {
const id = req.params.id; const { id } = req.params;
try { try {
const possibleDates = await Meeting.getPossibleDatesByMeetingId(id); const possibleDates = await Meeting.getPossibleDatesByMeetingId(id);
@ -135,7 +137,7 @@ router.get(
authenticate, authenticate,
validateMeetingID, validateMeetingID,
async (req, res) => { async (req, res) => {
const id = req.params.id; const { id } = req.params;
try { try {
const availability = await Meeting.getAvailabilityByMeetingId(id); const availability = await Meeting.getAvailabilityByMeetingId(id);

View File

@ -10,7 +10,7 @@ const Participant = require('../models/participantModel');
router.post('/', authenticate, async (req, res) => { router.post('/', authenticate, async (req, res) => {
id = uuidv4(); id = uuidv4();
const data = { id, ...req.body }; const data = { ...req.body, id };
try { try {
const [participant] = await Participant.addParticipant(data); const [participant] = await Participant.addParticipant(data);

View File

@ -19,7 +19,7 @@ router.post('/', authenticate, async (req, res) => {
}); });
router.delete('/:id', authenticate, async (req, res) => { router.delete('/:id', authenticate, async (req, res) => {
const id = req.params.id; const { id } = req.params;
try { try {
const possibleDate = await PossibleDate.deletePossibleDate(id); const possibleDate = await PossibleDate.deletePossibleDate(id);