Skip to content

Commit

Permalink
feat(apps/gql): make sure upvote doesn't exist before creating it
Browse files Browse the repository at this point in the history
  • Loading branch information
usirin committed Aug 11, 2023
1 parent 95b808c commit 661f68a
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions apps/gql/schema/resolvers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ export const resolvers = {

return { edge: { node, cursor: node.id }, error: null };
},
createPanoUpvote: async (_, { input }, { actions, pasaport: { session } }) => {
createPanoUpvote: async (_, { input }, { loaders, actions, pasaport: { session } }) => {
if (!session?.user?.id) {
return { node: null, error: NotAuthorized() };
}
Expand All @@ -447,7 +447,16 @@ export const resolvers = {

switch (type) {
case "PanoPost": {
const upvote = await actions.pano.postUpvote
let upvote = await loaders.pano.upvote.byUserAndPostID.load({
postID: value,
userID: session.user.id,
});

if (upvote) {
return { node: null, error: InvalidInput() };
}

upvote = await actions.pano.postUpvote
.create({ postID: value, userID: session.user.id })
.then(transformPanoUpvote);

Expand Down

0 comments on commit 661f68a

Please sign in to comment.