2016-11-22 18:39:50 -05:00
|
|
|
import Telescope from 'meteor/nova:lib';
|
2016-11-29 12:27:26 +01:00
|
|
|
import Posts from 'meteor/nova:posts';
|
2016-12-12 10:41:50 +09:00
|
|
|
import { GraphQLSchema } from 'meteor/nova:core';
|
2016-12-12 16:43:23 +09:00
|
|
|
import { operateOnItem } from './vote.js';
|
2016-11-22 18:39:50 -05:00
|
|
|
|
|
|
|
const voteSchema = `
|
|
|
|
type Vote {
|
|
|
|
itemId: String
|
|
|
|
power: Float
|
|
|
|
votedAt: String
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2016-12-12 10:41:50 +09:00
|
|
|
GraphQLSchema.addSchema(voteSchema);
|
2016-11-22 18:39:50 -05:00
|
|
|
|
2016-12-12 10:41:50 +09:00
|
|
|
GraphQLSchema.addMutation('postsVote(documentId: String, voteType: String) : Post');
|
2016-11-22 18:39:50 -05:00
|
|
|
|
|
|
|
const voteResolver = {
|
|
|
|
Mutation: {
|
|
|
|
postsVote(root, {documentId, voteType}, context) {
|
|
|
|
Meteor._sleepForMs(2000); // wait 2 seconds for demonstration purpose
|
|
|
|
console.log("sleep done");
|
|
|
|
const post = Posts.findOne(documentId);
|
2016-12-12 16:43:23 +09:00
|
|
|
return context.Users.canDo(context.currentUser, `posts.${voteType}`) ? operateOnItem(context.Posts, post, context.currentUser, voteType) : false;
|
2016-11-22 18:39:50 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2016-12-12 10:41:50 +09:00
|
|
|
GraphQLSchema.addResolvers(voteResolver);
|