-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
73 lines (59 loc) · 2.13 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { Meteor } from 'meteor/meteor';
import '../imports/api/messages';
import { Documents } from '../imports/api/documents.js';
import { DocumentContents } from '../imports/api/documentContents.js';
import { UserDocuments } from '../imports/api/userDoc';
Meteor.startup(() => {
return (
Meteor.methods({
getAllUsers: function() {
return Meteor.users.find({}).fetch();
},
quickUserSearchInUserDoc: function(currentUser, docId) {
return UserDocuments.find({ userId: currentUser, docId: docId }).fetch();
},
getAllUsersByDocument: function(docId) {
return UserDocuments.find({ docId: docId }).fetch();
},
getAllSharedDocumentsByOthers: function(userId) {
return UserDocuments.find({ userId: userId, createdBy: { $ne: userId } }).fetch();
},
getDocumentsByUser: function(currentUser) {
return Documents.find({ createdBy: currentUser }, {sort: {createdAt: -1}}).fetch();
},
getDocumentsByDocIds: function(docIdArray) {
return Documents.find({ _id: { "$in": docIdArray } }, {sort: {createdAt: -1}}).fetch();
},
// Delete the document's dependents (document contents) and itself.
deleteDocument: function(docId) {
return DocumentContents.remove({docId: docId}, function() {
Documents.remove(docId);
});
},
findDocument: function(docId) {
return Documents.findOne({ _id: docId });
},
updateTitle(docId, docTitle) {
Documents.update({ _id: docId }, {$set: {title: docTitle}});
},
updateMode(docId, docMode) {
Documents.update({ _id: docId }, {$set: {mode: docMode}});
},
upsertUserDocument(userId, docId, documentCreatedBy) {
UserDocuments.upsert({
// Selector
userId: userId,
docId: docId,
createdBy: documentCreatedBy
}, {
// Modifier
$set: {
userId: userId,
docId: docId,
createdBy: documentCreatedBy
}
})
}
}) //End of Meteor.methods
) //End of return
});