backend/api/models/meetingModel.js

97 lines
1.7 KiB
JavaScript
Raw Normal View History

const db = require('../../data/db');
module.exports = {
addMeeting,
getMeetingById,
updateMeeting,
deleteMeeting,
2020-05-06 11:17:52 +00:00
getParticipantsByMeetingId,
getPossibleDatesByMeetingId,
getAvailabilityByMeetingId,
};
function addMeeting(data) {
return db('meeting')
.insert(data)
.returning([
'id',
'title',
2020-05-06 11:17:52 +00:00
'description',
'start_time',
'duration',
'status',
2020-08-28 17:02:50 +00:00
'password',
]);
}
function updateMeeting(data, id) {
return db('meeting')
.where({ id })
.update(data)
.returning([
'id',
'title',
2020-05-06 11:17:52 +00:00
'description',
'start_time',
'duration',
'status',
2020-08-28 17:02:50 +00:00
'password',
]);
}
function deleteMeeting(id) {
return db('meeting').where({ id }).del();
}
function getMeetingById(id) {
return db('meeting')
.where({ id })
.first()
.select(
'id',
'title',
2020-05-06 11:17:52 +00:00
'description',
'start_time',
'duration',
'status',
2020-08-28 17:02:50 +00:00
'password',
);
}
2020-05-06 11:17:52 +00:00
function getParticipantsByMeetingId(meeting_id) {
return db('participant as p')
.select(
2020-08-28 14:08:19 +00:00
'p.id',
'p.email',
2020-08-28 17:02:50 +00:00
'p.account_id',
2020-05-06 11:17:52 +00:00
'p.meeting_id',
'p.quorum',
'p.mandatory',
'p.host',
'p.answered',
)
.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 getAvailabilityByMeetingId(meeting_id) {
return db('availability as a')
2020-05-06 11:17:52 +00:00
.select(
'a.id',
2020-08-28 17:02:50 +00:00
'a.participant_id',
2020-05-06 11:17:52 +00:00
'a.possible_date_id',
'a.preference',
'a.start_time',
'a.end_time',
)
.join('meeting as m', { 'm.id': 'a.meeting_id' })
.where({ meeting_id });
}