forked from activitypods/activitypods
-
Notifications
You must be signed in to change notification settings - Fork 0
/
event.js
59 lines (57 loc) · 2.13 KB
/
event.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const { ControlledContainerMixin } = require('@semapps/ldp');
const { AnnouncerMixin } = require('@activitypods/announcer');
const { OBJECT_TYPES } = require('@semapps/activitypub');
module.exports = {
name: 'events.event',
mixins: [AnnouncerMixin, ControlledContainerMixin],
settings: {
path: '/events',
acceptedTypes: [OBJECT_TYPES.EVENT],
permissions: {},
newResourcesPermissions: {},
notificationMapping: {
key: 'new_event',
title: {
en: `{{emitterProfile.vcard:given-name}} invites you to an event "{{activity.object.name}}"`,
fr: `{{emitterProfile.vcard:given-name}} vous invite à une rencontre "{{activity.object.name}}"`
}
}
},
hooks: {
after: {
async create(ctx, res) {
res.newData = await ctx.call('ldp.resource.awaitCreateComplete', {
resourceUri: res.resourceUri,
predicates: [
'dc:creator',
'dc:modified',
'dc:created',
'apods:announces',
'apods:announcers',
'apods:attendees'
]
});
await ctx.call('events.status.tagNewEvent', { eventUri: res.resourceUri });
await ctx.call('events.registration.addCreatorToAttendees', res);
await ctx.call('events.registration.givePermissionsForAttendeesCollection', res);
await ctx.call('events.location.setNewRights', res);
return res;
},
// TODO handle new PATCH method https://github.com/assemblee-virtuelle/activitypods/issues/42
// async patch(ctx, res) {
// await ctx.call('events.location.updateRights', res);
// if (res.newData['apods:maxAttendees'] !== res.oldData['apods:maxAttendees']) {
// await ctx.call('events.status.tagUpdatedEvent', { eventUri: res.resourceUri });
// }
// return res;
// },
async put(ctx, res) {
await ctx.call('events.location.updateRights', res);
if (res.newData['apods:maxAttendees'] !== res.oldData['apods:maxAttendees']) {
await ctx.call('events.status.tagUpdatedEvent', { eventUri: res.resourceUri });
}
return res;
}
}
}
};