3 var _ = require('lodash');
4 var appEvents = require('gitter-web-appevents');
5 var restSerializer = require('../../serializers/rest-serializer');
7 function serializeEventToRoom(operation, event) {
8 var url = '/rooms/' + event.toTroupeId + '/events';
9 var strategy = new restSerializer.EventStrategy();
11 return restSerializer.serializeObject(event, strategy).then(function(serializedEvent) {
12 appEvents.dataChange2(url, operation, serializedEvent, 'event');
17 create: function(event) {
18 return serializeEventToRoom('create', event);
21 update: function(event) {
22 return serializeEventToRoom('update', event);
25 patch: function(eventId, troupeId, patch) {
26 var url = '/rooms/' + troupeId + '/events';
27 appEvents.dataChange2(url, 'patch', _.extend({}, patch, { id: eventId }), 'event');
30 remove: function(event) {
31 return this.removeId(event._id, event.toTroupeId);
34 removeId: function(eventId, troupeId) {
35 var url = '/rooms/' + troupeId + '/events';
36 appEvents.dataChange2(url, 'remove', { id: eventId }, 'event');