mirror of
https://github.com/vale981/Vulcan
synced 2025-03-09 20:16:39 -04:00
46 lines
No EOL
1 KiB
JavaScript
46 lines
No EOL
1 KiB
JavaScript
import Telescope from 'meteor/nova:lib';
|
|
import Posts from 'meteor/nova:posts';
|
|
import { GraphQLSchema } from 'meteor/nova:core';
|
|
|
|
/**
|
|
* @summary Vote schema
|
|
* @type {SimpleSchema}
|
|
*/
|
|
Telescope.schemas.votes = new SimpleSchema({
|
|
itemId: {
|
|
type: String
|
|
},
|
|
power: {
|
|
type: Number,
|
|
optional: true
|
|
},
|
|
votedAt: {
|
|
type: Date,
|
|
optional: true
|
|
}
|
|
});
|
|
|
|
const voteSchema = `
|
|
type Vote {
|
|
itemId: String
|
|
power: Float
|
|
votedAt: String
|
|
}
|
|
`;
|
|
|
|
GraphQLSchema.addSchema(voteSchema);
|
|
|
|
GraphQLSchema.addMutation('postsVote(documentId: String, voteType: String) : Post');
|
|
|
|
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);
|
|
return context.Users.canDo(context.currentUser, `posts.${voteType}`) ? Telescope.operateOnItem(context.Posts, post, context.currentUser, voteType) : false;
|
|
},
|
|
},
|
|
};
|
|
|
|
GraphQLSchema.addResolvers(voteResolver); |