todos-contra-el-fuego-web/imports/api/Documents/server/publications.js
2017-05-25 16:31:01 -05:00

17 lines
540 B
JavaScript

import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
import Documents from '../Documents';
Meteor.publish('documents', function documentsView() {
return Documents.find({ owner: this.userId });
});
// Note: documents.view is also used when editing an existing document.
Meteor.publish('documents.view', function documentsView(documentId) {
check(documentId, String);
const doc = Documents.find(documentId);
const isOwner = doc.fetch()[0].owner === this.userId;
return isOwner ? doc : this.ready();
});