2016-10-22 00:27:47 +08:00
|
|
|
import { check } from 'meteor/check';
|
|
|
|
import Logger from '/imports/startup/server/logger';
|
2017-06-19 19:57:32 +08:00
|
|
|
import Meetings from '/imports/api/1.1/meetings';
|
2016-10-22 00:27:47 +08:00
|
|
|
import addMeeting from '../modifiers/addMeeting';
|
|
|
|
import removeMeeting from '../modifiers/removeMeeting';
|
|
|
|
|
2017-06-01 21:12:11 +08:00
|
|
|
export default function handleGetAllMeetings({ payload }) {
|
2016-10-22 00:27:47 +08:00
|
|
|
let meetings = payload.meetings;
|
|
|
|
|
|
|
|
check(meetings, Array);
|
|
|
|
|
|
|
|
// We need to map the meetings payload because for some reason this payload
|
|
|
|
// is different than the `meeting_created_message` one
|
|
|
|
meetings = meetings.map(m => ({
|
|
|
|
meeting_id: m.meetingID,
|
|
|
|
name: m.meetingName,
|
|
|
|
recorded: m.recorded,
|
|
|
|
voice_conf: m.voiceBridge,
|
|
|
|
duration: m.duration,
|
|
|
|
}));
|
|
|
|
|
|
|
|
const meetingsIds = meetings.map(m => m.meeting_id);
|
|
|
|
|
|
|
|
const meetingsToRemove = Meetings.find({
|
|
|
|
meetingId: { $nin: meetingsIds },
|
|
|
|
}).fetch();
|
|
|
|
|
|
|
|
meetingsToRemove.forEach(meeting => removeMeeting(meeting.meetingId));
|
|
|
|
|
2017-06-03 03:25:02 +08:00
|
|
|
const meetingsAdded = [];
|
|
|
|
meetings.forEach((meeting) => {
|
2016-10-22 00:27:47 +08:00
|
|
|
meetingsAdded.push(addMeeting(meeting));
|
|
|
|
});
|
|
|
|
|
|
|
|
return meetingsAdded;
|
2017-06-03 03:25:02 +08:00
|
|
|
}
|