2016-11-07 11:47:33 +09:00
|
|
|
import Telescope, { newMutation, editMutation, removeMutation } from 'meteor/nova:lib';
|
2016-11-04 10:28:54 +09:00
|
|
|
import Posts from './collection.js'
|
|
|
|
import Users from 'meteor/nova:users';
|
|
|
|
import Events from "meteor/nova:events";
|
|
|
|
|
2016-11-07 11:47:33 +09:00
|
|
|
// Resolvers
|
2016-11-04 10:28:54 +09:00
|
|
|
Posts.mutations = {
|
|
|
|
|
|
|
|
postsNew(root, {post}, context) {
|
2016-11-07 12:11:02 +09:00
|
|
|
return newMutation({
|
|
|
|
collection: context.Posts,
|
|
|
|
document: post,
|
|
|
|
currentUser: context.currentUser,
|
|
|
|
validate: true
|
|
|
|
});
|
2016-11-04 10:28:54 +09:00
|
|
|
},
|
|
|
|
|
2016-11-05 18:37:46 +09:00
|
|
|
postsEdit(root, {postId, set, unset}, context) {
|
2016-11-07 12:11:02 +09:00
|
|
|
return editMutation({
|
|
|
|
collection: context.Posts,
|
|
|
|
documentId: postId,
|
|
|
|
set: set,
|
|
|
|
unset: unset,
|
|
|
|
currentUser: context.currentUser,
|
|
|
|
validate: true
|
|
|
|
});
|
2016-11-07 11:47:33 +09:00
|
|
|
},
|
2016-11-04 15:49:42 +09:00
|
|
|
|
2016-11-07 11:47:33 +09:00
|
|
|
postsRemove(root, {postId}, context) {
|
2016-11-07 12:11:02 +09:00
|
|
|
return removeMutation({
|
|
|
|
collection: context.Posts,
|
|
|
|
documentId: postId,
|
|
|
|
currentUser: context.currentUser,
|
|
|
|
validate: true
|
|
|
|
});
|
2016-11-04 14:38:31 +09:00
|
|
|
},
|
|
|
|
|
2016-11-04 10:28:54 +09:00
|
|
|
postsVote(root, {postId, voteType}, context) {
|
|
|
|
Meteor._sleepForMs(2000); // wait 2 seconds for demonstration purpose
|
|
|
|
console.log("sleep done");
|
|
|
|
const post = Posts.findOne(postId);
|
|
|
|
return context.Users.canDo(context.currentUser, `posts.${voteType}`) ? Telescope.operateOnItem(context.Posts, post, context.currentUser, voteType) : false;
|
|
|
|
},
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-11-07 11:47:33 +09:00
|
|
|
// GraphQL mutations
|
|
|
|
Telescope.graphQL.addMutation('postsNew(post: PostInput) : Post');
|
|
|
|
Telescope.graphQL.addMutation('postsEdit(postId: String, set: PostInput, unset: PostUnsetModifier) : Post');
|
|
|
|
Telescope.graphQL.addMutation('postsRemove(postId: String) : Post');
|
|
|
|
Telescope.graphQL.addMutation('postsVote(postId: String, voteType: String) : Post');
|
|
|
|
|
2016-11-04 10:28:54 +09:00
|
|
|
export default Posts.mutations;
|