Complete meeting endpoints

This commit is contained in:
rui hildt 2020-05-06 13:17:52 +02:00
parent ad7ca3136a
commit 596baff4b3
2 changed files with 87 additions and 11 deletions

View File

@ -5,7 +5,9 @@ module.exports = {
getMeetingById,
updateMeeting,
deleteMeeting,
// getMeetingsByAccountId,
getParticipantsByMeetingId,
getPossibleDatesByMeetingId,
getAvailibilityByMeetingId,
};
function addMeeting(data) {
@ -55,3 +57,43 @@ function getMeetingById(id) {
'status',
);
}
function getParticipantsByMeetingId(meeting_id) {
return db('participant as p')
.select(
'p.account_id',
'p.meeting_id',
'p.earliest_time',
'p.latest_time',
'p.quorum',
'p.mandatory',
'p.host',
'p.answered',
'p.timezone',
)
.join('meeting as m', { 'm.id': 'p.meeting_id' })
.where({ meeting_id });
}
function getPossibleDatesByMeetingId(meeting_id) {
return db('possible_date as p')
.select('p.id', 'p.meeting_id', 'p.possible_date')
.join('meeting as m', { 'm.id': 'p.meeting_id' })
.where({ meeting_id });
}
function getAvailibilityByMeetingId(meeting_id) {
return db('availibility as a')
.select(
'a.id',
'a.meeting_id',
'a.account_id',
'a.possible_date_id',
'a.preference',
'a.start_time',
'a.end_time',
'a.timezone',
)
.join('meeting as m', { 'm.id': 'a.meeting_id' })
.where({ meeting_id });
}

View File

@ -40,7 +40,7 @@ router.delete('/:id', async (req, res) => {
}
});
router.get('/', async (req, res) => {
router.get('/:id', async (req, res) => {
const id = req.params.id;
try {
@ -51,4 +51,38 @@ router.get('/', async (req, res) => {
}
});
router.get('/:id/participants', async (req, res) => {
const id = req.params.id;
try {
const meeting = await Meeting.getParticipantsByMeetingId(id);
res.status(200).json(meeting);
} catch (error) {
res.status(500).json({ message: "Meeting doesn't exist.", error });
}
});
router.get('/:id/possible-dates', async (req, res) => {
const id = req.params.id;
try {
const meeting = await Meeting.getPossibleDatesByMeetingId(id);
res.status(200).json(meeting);
} catch (error) {
res.status(500).json({ message: "Meeting doesn't exist.", error });
}
});
router.get('/:id/availibility', async (req, res) => {
const id = req.params.id;
try {
const meeting = await Meeting.getAvailibilityByMeetingId(id);
res.status(200).json(meeting);
} catch (error) {
res.status(500).json({ message: "Meeting doesn't exist.", error });
}
});
module.exports = router;