Blame view
imports/api/documents/methods.js
1.04 KB
cac7cbc73
|
1 2 |
import { SimpleSchema } from 'meteor/aldeed:simple-schema'; import { ValidatedMethod } from 'meteor/mdg:validated-method'; |
3540345c5
|
3 |
import { Documents } from './documents'; |
0b8062427
|
4 |
import { rateLimit } from '../../modules/rate-limit.js'; |
d1f05315d
|
5 6 7 8 |
export const insertDocument = new ValidatedMethod({ name: 'documents.insert', validate: new SimpleSchema({ |
f0c912bf1
|
9 |
title: { type: String }, |
d1f05315d
|
10 |
}).validator(), |
f0c912bf1
|
11 12 13 |
run(document) { Documents.insert(document); }, |
d1f05315d
|
14 15 16 17 18 19 |
}); export const updateDocument = new ValidatedMethod({ name: 'documents.update', validate: new SimpleSchema({ _id: { type: String }, |
f0c912bf1
|
20 |
'update.title': { type: String, optional: true }, |
d1f05315d
|
21 |
}).validator(), |
f0c912bf1
|
22 23 24 |
run({ _id, update }) { Documents.update(_id, { $set: update }); }, |
d1f05315d
|
25 26 27 28 29 |
}); export const removeDocument = new ValidatedMethod({ name: 'documents.remove', validate: new SimpleSchema({ |
f0c912bf1
|
30 |
_id: { type: String }, |
d1f05315d
|
31 |
}).validator(), |
f0c912bf1
|
32 33 34 |
run({ _id }) { Documents.remove(_id); }, |
d1f05315d
|
35 |
}); |
0b8062427
|
36 37 38 39 40 41 42 43 44 45 |
rateLimit({ methods: [ insertDocument, updateDocument, removeDocument, ], limit: 5, timeRange: 1000, }); |