Improve error messages with id
This commit is contained in:
parent
b7b7dbbc73
commit
cfedf47568
16
api/models/possibleDateModel.js
Normal file
16
api/models/possibleDateModel.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
const db = require('../../data/db');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
addPossibleDate,
|
||||||
|
deletePossibleDate,
|
||||||
|
};
|
||||||
|
|
||||||
|
function addPossibleDate(data) {
|
||||||
|
return db('possible_date')
|
||||||
|
.insert(data)
|
||||||
|
.returning(['id', 'meeting_id', 'possible_date']);
|
||||||
|
}
|
||||||
|
|
||||||
|
function deletePossibleDate(id) {
|
||||||
|
return db('possible_date').where({ id }).del();
|
||||||
|
}
|
@ -22,7 +22,7 @@ router.put('/:id', async (req, res) => {
|
|||||||
const account = await Account.updateAccount(data, id);
|
const account = await Account.updateAccount(data, id);
|
||||||
res.status(200).json(...account);
|
res.status(200).json(...account);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
res.status(500).json({ message: 'Failed to update account.', error });
|
res.status(500).json({ message: `Failed to update account with id ${id}.`, error });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ router.delete('/:id', async (req, res) => {
|
|||||||
const account = await Account.deleteAccount(id);
|
const account = await Account.deleteAccount(id);
|
||||||
res.status(200).json({message: `Account with id ${id} successfully deleted.`});
|
res.status(200).json({message: `Account with id ${id} successfully deleted.`});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
res.status(500).json({ message: 'Failed to delete account.', error });
|
res.status(500).json({ message: `Failed to delete account with id ${id}.`, error });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ router.put('/:id', async (req, res) => {
|
|||||||
const meeting = await Meeting.updateMeeting(data, id);
|
const meeting = await Meeting.updateMeeting(data, id);
|
||||||
res.status(200).json(meeting);
|
res.status(200).json(meeting);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
res.status(500).json({ message: 'Failed to update meeting.', error });
|
res.status(500).json({ message: `Failed to update meeting with id ${id}.`, error });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ router.delete('/:id', async (req, res) => {
|
|||||||
const meeting = await Meeting.deleteMeeting(id);
|
const meeting = await Meeting.deleteMeeting(id);
|
||||||
res.status(200).json({message: `Meeting with id ${id} successfully deleted.`});
|
res.status(200).json({message: `Meeting with id ${id} successfully deleted.`});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
res.status(500).json({ message: 'Failed to delete meeting.', error });
|
res.status(500).json({ message: `Failed to delete meeting with id ${id}.`, error });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -65,7 +65,10 @@ router.get('/:account_id-:meeting_id', async (req, res) => {
|
|||||||
);
|
);
|
||||||
res.status(200).json(participant);
|
res.status(200).json(participant);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
res.status(500).json({ message: "Participant doesn't exist.", error });
|
res.status(500).json({
|
||||||
|
message: `Participant with id ${account_id}-${meeting_id} doesn't exist.`,
|
||||||
|
error,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
36
api/routes/possibleDateRoute.js
Normal file
36
api/routes/possibleDateRoute.js
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
let express = require('express');
|
||||||
|
let router = express.Router();
|
||||||
|
|
||||||
|
let PossibleDate = require('../models/possibleDateModel');
|
||||||
|
|
||||||
|
router.post('/', async (req, res) => {
|
||||||
|
const data = { ...req.body };
|
||||||
|
|
||||||
|
try {
|
||||||
|
const [possibleDate] = await PossibleDate.addPossibleDate(data);
|
||||||
|
res.status(201).json(possibleDate);
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: 'Failed to add a new possible date.',
|
||||||
|
error,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
router.delete('/:possible_date_id', async (req, res) => {
|
||||||
|
const id = req.params.id;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const possibleDate = await PossibleDate.deletePossibleDate(id);
|
||||||
|
res.status(200).json({
|
||||||
|
message: `Possible date with id ${id} successfully deleted.`,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: `Failed to delete possible date with id ${id}.`,
|
||||||
|
error,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = router;
|
@ -6,6 +6,7 @@ require('dotenv').config();
|
|||||||
const accountsRoute = require('./routes/accountRoute');
|
const accountsRoute = require('./routes/accountRoute');
|
||||||
const meetingsRoute = require('./routes/meetingRoute');
|
const meetingsRoute = require('./routes/meetingRoute');
|
||||||
const participantsRoute = require('./routes/participantRoute');
|
const participantsRoute = require('./routes/participantRoute');
|
||||||
|
const possibleDatesRoute = require('./routes/possibleDateRoute');
|
||||||
|
|
||||||
const server = express();
|
const server = express();
|
||||||
|
|
||||||
@ -16,6 +17,7 @@ server.use(helmet());
|
|||||||
server.use('/api/accounts', accountsRoute);
|
server.use('/api/accounts', accountsRoute);
|
||||||
server.use('/api/meetings', meetingsRoute);
|
server.use('/api/meetings', meetingsRoute);
|
||||||
server.use('/api/participants', participantsRoute);
|
server.use('/api/participants', participantsRoute);
|
||||||
|
server.use('/api/possible-dates', possibleDatesRoute);
|
||||||
|
|
||||||
server.get('/', (req, res) =>
|
server.get('/', (req, res) =>
|
||||||
res
|
res
|
||||||
|
Loading…
Reference in New Issue
Block a user