Vulcan/packages/nova-comments/lib/mutations.js

61 lines
1.8 KiB
JavaScript
Raw Normal View History

import Telescope, { newMutation, editMutation, removeMutation } from 'meteor/nova:lib';
2016-11-05 18:37:46 +09:00
import Comments from './collection.js'
import Users from 'meteor/nova:users';
import Events from "meteor/nova:events";
// Resolvers
2016-11-05 18:37:46 +09:00
Comments.mutations = {
2016-11-07 23:46:12 +09:00
commentsNew(root, {document}, context) {
return newMutation({
action: 'comments.new',
collection: context.Comments,
2016-11-07 23:46:12 +09:00
document: document,
currentUser: context.currentUser,
validate: true
});
2016-11-05 18:37:46 +09:00
},
2016-11-07 23:46:12 +09:00
commentsEdit(root, {documentId, set, unset}, context) {
const document = Comments.findOne(documentId);
const action = Users.owns(context.currentUser, document) ? 'comments.edit.own' : 'comments.edit.all';
return editMutation({
action: action,
collection: context.Comments,
2016-11-07 23:46:12 +09:00
documentId: documentId,
set: set,
unset: unset,
currentUser: context.currentUser,
validate: true
});
},
2016-11-05 18:37:46 +09:00
2016-11-07 23:46:12 +09:00
commentsRemove(root, {documentId}, context) {
const document = Comments.findOne(documentId);
const action = Users.owns(context.currentUser, document) ? 'comments.remove.own' : 'comments.remove.all';
return removeMutation({
action: action,
collection: context.Comments,
2016-11-07 23:46:12 +09:00
documentId: documentId,
currentUser: context.currentUser,
validate: true
});
2016-11-05 18:37:46 +09:00
},
2016-11-07 23:46:12 +09:00
commentsVote(root, {documentId, voteType}, context) {
2016-11-05 18:37:46 +09:00
},
};
// GraphQL mutations
2016-11-07 23:46:12 +09:00
Telescope.graphQL.addMutation('commentsNew(document: commentsInput) : Comment');
Telescope.graphQL.addMutation('commentsEdit(documentId: String, set: commentsInput, unset: commentsUnset) : Comment');
Telescope.graphQL.addMutation('commentsRemove(documentId: String) : Comment');
Telescope.graphQL.addMutation('commentsVote(documentId: String, voteType: String) : Comment');
2016-11-05 18:37:46 +09:00
export default Comments.mutations;