wip wiring up account forms

This commit is contained in:
cleverbeagle 2017-05-25 16:31:01 -05:00
parent cdc15f019d
commit 3459bf26f8
25 changed files with 413 additions and 53 deletions

View file

@ -46,6 +46,6 @@ Documents.schema = new SimpleSchema({
},
});
Documents.attachSchema(Documents.schema);
// Documents.attachSchema(Documents.schema);
export default Documents;

View file

@ -0,0 +1,52 @@
import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
import Documents from './Documents';
import rateLimit from '../../modules/rate-limit';
Meteor.methods({
'documents.insert': function documentsInsert(doc) {
check(doc, {
title: String,
body: String,
});
try {
return Documents.insert({ owner: this.userId, ...doc });
} catch (exception) {
throw new Meteor.Error('500', exception);
}
},
'documents.update': function documentsUpdate(doc) {
check(doc, {
_id: String,
title: String,
body: String,
});
try {
Documents.update(doc._id, { $set: doc });
return doc._id; // Return _id so we can redirect to document after update.
} catch (exception) {
throw new Meteor.Error('500', exception);
}
},
'documents.remove': function documentsRemove(documentId) {
check(documentId, String);
try {
return Documents.remove(documentId);
} catch (exception) {
throw new Meteor.Error('500', exception);
}
},
});
rateLimit({
methods: [
'documents.insert',
'documents.update',
'documents.remove',
],
limit: 5,
timeRange: 1000,
});

View file

@ -0,0 +1,17 @@
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();
});