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.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 }); } function getAvailabilityByMeetingId(meeting_id) { return db('availability as a') .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 }); }