Blame view
imports/api/documents/methods.js
894 Bytes
cac7cbc73
|
1 2 |
import { SimpleSchema } from 'meteor/aldeed:simple-schema'; import { ValidatedMethod } from 'meteor/mdg:validated-method'; |
c42d4eeac
|
3 |
import Documents from './documents'; |
0b8062427
|
4 |
import { rateLimit } from '../../modules/rate-limit.js'; |
d1f05315d
|
5 |
|
c42d4eeac
|
6 7 |
export const upsertDocument = new ValidatedMethod({ name: 'documents.upsert', |
d1f05315d
|
8 |
validate: new SimpleSchema({ |
c42d4eeac
|
9 10 11 |
_id: { type: String, optional: true }, title: { type: String, optional: true }, body: { type: String, optional: true }, |
d1f05315d
|
12 |
}).validator(), |
f0c912bf1
|
13 |
run(document) { |
c42d4eeac
|
14 |
return Documents.upsert({ _id: document._id }, { $set: document }); |
f0c912bf1
|
15 |
}, |
d1f05315d
|
16 17 18 19 20 |
}); export const removeDocument = new ValidatedMethod({ name: 'documents.remove', validate: new SimpleSchema({ |
f0c912bf1
|
21 |
_id: { type: String }, |
d1f05315d
|
22 |
}).validator(), |
f0c912bf1
|
23 24 25 |
run({ _id }) { Documents.remove(_id); }, |
d1f05315d
|
26 |
}); |
0b8062427
|
27 28 29 |
rateLimit({ methods: [ |
c42d4eeac
|
30 |
upsertDocument, |
0b8062427
|
31 32 33 34 35 |
removeDocument, ], limit: 5, timeRange: 1000, }); |