2020-05-04 14:02:31 +00:00
|
|
|
const db = require('../../data/db');
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
addMeeting,
|
|
|
|
getMeetingById,
|
|
|
|
updateMeeting,
|
|
|
|
deleteMeeting,
|
2020-05-06 11:17:52 +00:00
|
|
|
getParticipantsByMeetingId,
|
|
|
|
getPossibleDatesByMeetingId,
|
2020-06-02 14:51:42 +00:00
|
|
|
getAvailabilityByMeetingId,
|
2020-05-04 14:02:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
function addMeeting(data) {
|
|
|
|
return db('meeting')
|
|
|
|
.insert(data)
|
|
|
|
.returning([
|
|
|
|
'id',
|
|
|
|
'title',
|
2020-05-06 11:17:52 +00:00
|
|
|
'description',
|
|
|
|
'start_time',
|
2020-05-04 14:02:31 +00:00
|
|
|
'duration',
|
|
|
|
'status',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
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',
|
2020-05-04 14:02:31 +00:00
|
|
|
'duration',
|
|
|
|
'status',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
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',
|
2020-05-04 14:02:31 +00:00
|
|
|
'duration',
|
|
|
|
'status',
|
|
|
|
);
|
|
|
|
}
|
2020-05-06 11:17:52 +00:00
|
|
|
|
|
|
|
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',
|
|
|
|
)
|
|
|
|
.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 });
|
|
|
|
}
|
|
|
|
|
2020-06-02 14:51:42 +00:00
|
|
|
function getAvailabilityByMeetingId(meeting_id) {
|
|
|
|
return db('availability as a')
|
2020-05-06 11:17:52 +00:00
|
|
|
.select(
|
|
|
|
'a.id',
|
|
|
|
'a.meeting_id',
|
|
|
|
'a.account_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 });
|
|
|
|
}
|