94 lines
1.6 KiB
JavaScript
94 lines
1.6 KiB
JavaScript
const db = require('../../data/db');
|
|
|
|
module.exports = {
|
|
addMeeting,
|
|
getMeetingById,
|
|
updateMeeting,
|
|
deleteMeeting,
|
|
getParticipantsByMeetingId,
|
|
getPossibleDatesByMeetingId,
|
|
getAvailabilityByMeetingId,
|
|
};
|
|
|
|
function addMeeting(data) {
|
|
return db('meeting')
|
|
.insert(data)
|
|
.returning([
|
|
'id',
|
|
'title',
|
|
'description',
|
|
'start_time',
|
|
'duration',
|
|
'status',
|
|
]);
|
|
}
|
|
|
|
function updateMeeting(data, id) {
|
|
return db('meeting')
|
|
.where({ id })
|
|
.update(data)
|
|
.returning([
|
|
'id',
|
|
'title',
|
|
'description',
|
|
'start_time',
|
|
'duration',
|
|
'status',
|
|
]);
|
|
}
|
|
|
|
function deleteMeeting(id) {
|
|
return db('meeting').where({ id }).del();
|
|
}
|
|
|
|
function getMeetingById(id) {
|
|
return db('meeting')
|
|
.where({ id })
|
|
.first()
|
|
.select(
|
|
'id',
|
|
'title',
|
|
'description',
|
|
'start_time',
|
|
'duration',
|
|
'status',
|
|
);
|
|
}
|
|
|
|
function getParticipantsByMeetingId(meeting_id) {
|
|
return db('participant as p')
|
|
.select(
|
|
'p.id',
|
|
'p.email',
|
|
'p.account_id',
|
|
'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')
|
|
.select(
|
|
'a.id',
|
|
'a.participant_id',
|
|
'a.possible_date_id',
|
|
'a.preference',
|
|
'a.start_time',
|
|
'a.end_time',
|
|
)
|
|
.join('meeting as m', { 'm.id': 'a.meeting_id' })
|
|
.where({ meeting_id });
|
|
}
|