Blame view

imports/api/documents/methods.js 882 Bytes
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';
d1f05315d   tmcdeveloper   wip adding API an...
4
5
6
7
  
  export const insertDocument = new ValidatedMethod({
    name: 'documents.insert',
    validate: new SimpleSchema({
f0c912bf1   tmcdeveloper   add method tests ...
8
      title: { type: String },
d1f05315d   tmcdeveloper   wip adding API an...
9
    }).validator(),
f0c912bf1   tmcdeveloper   add method tests ...
10
11
12
    run(document) {
      Documents.insert(document);
    },
d1f05315d   tmcdeveloper   wip adding API an...
13
14
15
16
17
18
  });
  
  export const updateDocument = new ValidatedMethod({
    name: 'documents.update',
    validate: new SimpleSchema({
      _id: { type: String },
f0c912bf1   tmcdeveloper   add method tests ...
19
      'update.title': { type: String, optional: true },
d1f05315d   tmcdeveloper   wip adding API an...
20
    }).validator(),
f0c912bf1   tmcdeveloper   add method tests ...
21
22
23
    run({ _id, update }) {
      Documents.update(_id, { $set: update });
    },
d1f05315d   tmcdeveloper   wip adding API an...
24
25
26
27
28
  });
  
  export const removeDocument = new ValidatedMethod({
    name: 'documents.remove',
    validate: new SimpleSchema({
f0c912bf1   tmcdeveloper   add method tests ...
29
      _id: { type: String },
d1f05315d   tmcdeveloper   wip adding API an...
30
    }).validator(),
f0c912bf1   tmcdeveloper   add method tests ...
31
32
33
    run({ _id }) {
      Documents.remove(_id);
    },
d1f05315d   tmcdeveloper   wip adding API an...
34
  });