Complete account endpoints

This commit is contained in:
rui hildt 2020-05-06 12:30:32 +02:00
parent a6dd5bb7f4
commit ad7ca3136a
2 changed files with 38 additions and 29 deletions

View File

@ -5,7 +5,7 @@ module.exports = {
getAccountById, getAccountById,
updateAccount, updateAccount,
deleteAccount, deleteAccount,
// getMeetingsByAccountId, getMeetingsByAccountId,
}; };
function addAccount(data) { function addAccount(data) {
@ -39,20 +39,20 @@ function deleteAccount(id) {
return db('account').where({ id }).del(); return db('account').where({ id }).del();
} }
// function getMeetingsByAccountId(id) { function getMeetingsByAccountId(account_id) {
// // Get all meetings to which an account is participating return db('participant as p')
// // select id, title, description, start_time, timezone, duration, status where .select(
// return db('participant') 'm.id',
// .where({ id }) 'm.title',
// .select( 'm.description',
// 'id', 'm.start_time',
// 'username', 'm.timezone',
// 'email', 'm.duration',
// 'timezone', 'm.status',
// 'earliest_time', )
// 'latest_time', .join('meeting as m', { 'm.id': 'p.meeting_id' })
// ); .where({ account_id });
// } }
function getAccountById(id) { function getAccountById(id) {
return db('account') return db('account')

View File

@ -22,7 +22,10 @@ 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 with id ${id}.`, error }); res.status(500).json({
message: `Failed to update account with id ${id}.`,
error,
});
} }
}); });
@ -31,24 +34,30 @@ router.delete('/:id', async (req, res) => {
try { try {
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 with id ${id}.`, error }); res.status(500).json({
message: `Failed to delete account with id ${id}.`,
error,
});
} }
}); });
router.get('/:id/meetings', async (req, res) => {
const { id } = req.params;
// // Get list of meetings by id try {
// router.get('/', async (req, res) => { const meetings = await Account.getMeetingsByAccountId(id);
// const { id } = req.body; res.status(200).json(meetings);
} catch (error) {
// try { res.status(500).json({
// const meetings = await Account.getMeetingsByAccountId(id); message: `Couldn't get meetings for account with id ${id}.`,
// res.status(200).json(meetings); error,
// } catch (error) { });
// res.status(500).json({ message: "Couldn't get meetings for account with id ${id}.", error }); }
// } });
// });
router.get('/:id', async (req, res) => { router.get('/:id', async (req, res) => {
const id = req.params.id; const id = req.params.id;