Skip to content

Commit

Permalink
Merge branch 'main' of github.com:jonogon/jonogon-web
Browse files Browse the repository at this point in the history
  • Loading branch information
omranjamal committed Aug 24, 2024
2 parents 365d634 + b51fe66 commit 0b8fd82
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions apps/jonogon-core/src/api/trpc/procedures/petitions/crud.mts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,27 @@ export const createPetition = protectedProcedure.mutation(
});
}

const upvote = await ctx.services.postgresQueryBuilder
.insertInto('petition_votes')
.values({
petition_id: created.id,
user_id: ctx.auth.user_id,
vote: 1, // Upvote
})
.executeTakeFirst();

if (!upvote) {
await ctx.services.postgresQueryBuilder
.deleteFrom('petitions')
.where('id', '=', `${created.id}`)
.executeTakeFirst();

throw new TRPCError({
code: 'INTERNAL_SERVER_ERROR',
message: 'failed-to-upvote-petition',
});
}

return {
data: created,
};
Expand Down

0 comments on commit 0b8fd82

Please sign in to comment.