methods.js
1.04 KB
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
import { SimpleSchema } from 'meteor/aldeed:simple-schema';
import { ValidatedMethod } from 'meteor/mdg:validated-method';
import { Documents } from './documents';
import { rateLimit } from '../../modules/rate-limit.js';
export const insertDocument = new ValidatedMethod({
name: 'documents.insert',
validate: new SimpleSchema({
title: { type: String },
}).validator(),
run(document) {
Documents.insert(document);
},
});
export const updateDocument = new ValidatedMethod({
name: 'documents.update',
validate: new SimpleSchema({
_id: { type: String },
'update.title': { type: String, optional: true },
}).validator(),
run({ _id, update }) {
Documents.update(_id, { $set: update });
},
});
export const removeDocument = new ValidatedMethod({
name: 'documents.remove',
validate: new SimpleSchema({
_id: { type: String },
}).validator(),
run({ _id }) {
Documents.remove(_id);
},
});
rateLimit({
methods: [
insertDocument,
updateDocument,
removeDocument,
],
limit: 5,
timeRange: 1000,
});