vote: protectedProcedure
.input(
z.object({
server_id: z.string(),
})
)
.mutation(({ ctx, input }) => {
// Promise all means it perfroms both actions. Previously only the .update happened.
return Promise.all([
ctx.prisma.votes.create({
data: {
server_id: input.server_id,
user_id: ctx.session.id,
},
}),
ctx.prisma.server.update({
where: {
id: input.server_id,
},
data: {
votes: {
increment: 1,
},
},
}),
]);
}),
vote: protectedProcedure
.input(
z.object({
server_id: z.string(),
})
)
.mutation(({ ctx, input }) => {
// Promise all means it perfroms both actions. Previously only the .update happened.
return Promise.all([
ctx.prisma.votes.create({
data: {
server_id: input.server_id,
user_id: ctx.session.id,
},
}),
ctx.prisma.server.update({
where: {
id: input.server_id,
},
data: {
votes: {
increment: 1,
},
},
}),
]);
}),