/
publish.js
57 lines (49 loc) · 1.07 KB
/
publish.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
import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
// Feel free to make suggestions for the eventbus api.
Meteor.publish('Events.byThing', function(thingUuid) {
check(thingUuid, String);
let thing = Thing.findOne({
'uuid': thingUuid,
'owner': this.userId
}
, {
fields: {
_id: 1
}
});
if (!thing) { throw new Meteor.Error('not-found', `Thing '${thingUuid}' cannot be found.`); }
return Events.find(
{'thing._id': thing._id}
, {
'sort': {
'insertedAt': -1
},
'limit': 100
});
});
Meteor.publish('Events.byThingAndType', function(thingUuid, type) {
check(thingUuid, String);
check(type, String);
let thing = Things.findOne(
{
'uuid': thingUuid,
'owner': this.userId
}
, {
fields: {
_id: 1
}
});
if (!thing) { throw new Meteor.Error('not-found', `Thing '${thingUuid}' cannot be found.`); }
return Events.find({
'thing._id': thing._id,
'event.message.type': type,
}
, {
'sort': {
'insertedAt': -1
},
'limit': 100
});
});