MCPcopy Create free account
hub / github.com/alpha2phi/python-apps / vote

Function vote

hackernews/backend-nodejs/src/resolvers/Mutation.js:58–84  ·  view source on GitHub ↗
(parent, args, context, info)

Source from the content-addressed store, hash-verified

56}
57
58async function vote(parent, args, context, info) {
59 const { userId } = context;
60 const vote = await context.prisma.vote.findUnique({
61 where: {
62 linkId_userId: {
63 linkId: Number(args.linkId),
64 userId: userId
65 }
66 }
67 });
68
69 if (Boolean(vote)) {
70 throw new Error(
71 `Already voted for link: ${args.linkId}`
72 );
73 }
74
75 const newVote = context.prisma.vote.create({
76 data: {
77 user: { connect: { id: userId } },
78 link: { connect: { id: Number(args.linkId) } }
79 }
80 });
81 context.pubsub.publish('NEW_VOTE', newVote);
82
83 return newVote;
84}
85
86module.exports = {
87 post,

Callers

nothing calls this directly

Calls 1

createMethod · 0.80

Tested by

no test coverage detected