2017-07-13 17:37:59 +09:00
|
|
|
import { newMutation, editMutation, removeMutation, addGraphQLMutation, Utils } from 'meteor/vulcan:core';
|
2017-03-23 16:27:59 +09:00
|
|
|
import Users from 'meteor/vulcan:users';
|
2016-11-04 10:28:54 +09:00
|
|
|
|
2016-11-22 18:14:51 -05:00
|
|
|
|
|
|
|
const mutations = {
|
2016-11-14 17:17:44 +09:00
|
|
|
|
2016-11-22 18:14:51 -05:00
|
|
|
new: {
|
|
|
|
|
|
|
|
name: 'postsNew',
|
|
|
|
|
|
|
|
check(user, document) {
|
|
|
|
if (!user) return false;
|
|
|
|
return Users.canDo(user, 'posts.new');
|
|
|
|
},
|
|
|
|
|
|
|
|
mutation(root, {document}, context) {
|
|
|
|
|
2017-06-07 05:04:05 -07:00
|
|
|
Utils.performCheck(this.check, context.currentUser, document);
|
2016-11-22 18:14:51 -05:00
|
|
|
|
|
|
|
return newMutation({
|
|
|
|
collection: context.Posts,
|
|
|
|
document: document,
|
|
|
|
currentUser: context.currentUser,
|
2016-11-24 15:47:51 +09:00
|
|
|
validate: true,
|
|
|
|
context,
|
2016-11-22 18:14:51 -05:00
|
|
|
});
|
|
|
|
},
|
2016-11-14 17:17:44 +09:00
|
|
|
|
2016-11-07 11:47:33 +09:00
|
|
|
},
|
2016-11-04 15:49:42 +09:00
|
|
|
|
2016-11-22 18:14:51 -05:00
|
|
|
edit: {
|
|
|
|
|
|
|
|
name: 'postsEdit',
|
|
|
|
|
|
|
|
check(user, document) {
|
|
|
|
if (!user || !document) return false;
|
|
|
|
return Users.owns(user, document) ? Users.canDo(user, 'posts.edit.own') : Users.canDo(user, `posts.edit.all`);
|
|
|
|
},
|
|
|
|
|
|
|
|
mutation(root, {documentId, set, unset}, context) {
|
2016-11-14 17:17:44 +09:00
|
|
|
|
2016-11-22 18:14:51 -05:00
|
|
|
const document = context.Posts.findOne(documentId);
|
2017-06-07 05:04:05 -07:00
|
|
|
Utils.performCheck(this.check, context.currentUser, document);
|
2016-11-22 18:14:51 -05:00
|
|
|
|
|
|
|
return editMutation({
|
|
|
|
collection: context.Posts,
|
|
|
|
documentId: documentId,
|
|
|
|
set: set,
|
|
|
|
unset: unset,
|
|
|
|
currentUser: context.currentUser,
|
2016-11-24 15:47:51 +09:00
|
|
|
validate: true,
|
|
|
|
context,
|
2016-11-22 18:14:51 -05:00
|
|
|
});
|
|
|
|
},
|
2016-11-14 17:17:44 +09:00
|
|
|
|
2016-11-04 14:38:31 +09:00
|
|
|
},
|
2016-11-22 18:14:51 -05:00
|
|
|
|
|
|
|
remove: {
|
|
|
|
|
|
|
|
name: 'postsRemove',
|
|
|
|
|
|
|
|
check(user, document) {
|
|
|
|
if (!user || !document) return false;
|
|
|
|
return Users.owns(user, document) ? Users.canDo(user, 'posts.remove.own') : Users.canDo(user, `posts.remove.all`);
|
|
|
|
},
|
|
|
|
|
|
|
|
mutation(root, {documentId}, context) {
|
|
|
|
|
|
|
|
const document = context.Posts.findOne(documentId);
|
2017-06-07 05:04:05 -07:00
|
|
|
Utils.performCheck(this.check, context.currentUser, document);
|
2016-11-22 18:14:51 -05:00
|
|
|
|
|
|
|
return removeMutation({
|
|
|
|
collection: context.Posts,
|
|
|
|
documentId: documentId,
|
|
|
|
currentUser: context.currentUser,
|
2016-11-24 15:47:51 +09:00
|
|
|
validate: true,
|
|
|
|
context,
|
2016-11-22 18:14:51 -05:00
|
|
|
});
|
|
|
|
},
|
2016-11-04 14:38:31 +09:00
|
|
|
|
2016-11-04 10:28:54 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-07-13 17:37:59 +09:00
|
|
|
addGraphQLMutation('increasePostViewCount(postId: String): Float');
|
2017-02-01 16:37:06 +01:00
|
|
|
|
|
|
|
export default mutations;
|