const db = require('../../data/db'); module.exports = { addMeeting, getMeetingById, updateMeeting, deleteMeeting, getParticipantsByMeetingId, getPossibleDatesByMeetingId, getAvailibilityByMeetingId, }; function addMeeting(data) { return db('meeting') .insert(data) .returning([ 'id', 'title', 'description', 'start_time', 'timezone', 'duration', 'status', ]); } function updateMeeting(data, id) { return db('meeting') .where({ id }) .update(data) .returning([ 'id', 'title', 'description', 'start_time', 'timezone', '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', 'timezone', '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', '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 }); }