Blame view

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