Blame view

imports/api/documents/methods.js 894 Bytes
cac7cbc73   tmcdeveloper   4.1.0 release
1
2
  import { SimpleSchema } from 'meteor/aldeed:simple-schema';
  import { ValidatedMethod } from 'meteor/mdg:validated-method';
c42d4eeac   themeteorchef   handful of changes
3
  import Documents from './documents';
0b8062427   tmcdeveloper   add support for r...
4
  import { rateLimit } from '../../modules/rate-limit.js';
d1f05315d   tmcdeveloper   wip adding API an...
5

c42d4eeac   themeteorchef   handful of changes
6
7
  export const upsertDocument = new ValidatedMethod({
    name: 'documents.upsert',
d1f05315d   tmcdeveloper   wip adding API an...
8
    validate: new SimpleSchema({
c42d4eeac   themeteorchef   handful of changes
9
10
11
      _id: { type: String, optional: true },
      title: { type: String, optional: true },
      body: { type: String, optional: true },
d1f05315d   tmcdeveloper   wip adding API an...
12
    }).validator(),
f0c912bf1   tmcdeveloper   add method tests ...
13
    run(document) {
c42d4eeac   themeteorchef   handful of changes
14
      return Documents.upsert({ _id: document._id }, { $set: document });
f0c912bf1   tmcdeveloper   add method tests ...
15
    },
d1f05315d   tmcdeveloper   wip adding API an...
16
17
18
19
20
  });
  
  export const removeDocument = new ValidatedMethod({
    name: 'documents.remove',
    validate: new SimpleSchema({
f0c912bf1   tmcdeveloper   add method tests ...
21
      _id: { type: String },
d1f05315d   tmcdeveloper   wip adding API an...
22
    }).validator(),
f0c912bf1   tmcdeveloper   add method tests ...
23
24
25
    run({ _id }) {
      Documents.remove(_id);
    },
d1f05315d   tmcdeveloper   wip adding API an...
26
  });
0b8062427   tmcdeveloper   add support for r...
27
28
29
  
  rateLimit({
    methods: [
c42d4eeac   themeteorchef   handful of changes
30
      upsertDocument,
0b8062427   tmcdeveloper   add support for r...
31
32
33
34
35
      removeDocument,
    ],
    limit: 5,
    timeRange: 1000,
  });