|
|
@ -166,13 +166,28 @@ export const questionsQuestionCommentRouter = createProtectedRouter()
|
|
|
|
const userId = ctx.session?.user?.id;
|
|
|
|
const userId = ctx.session?.user?.id;
|
|
|
|
const { questionCommentId, vote } = input;
|
|
|
|
const { questionCommentId, vote } = input;
|
|
|
|
|
|
|
|
|
|
|
|
return await ctx.prisma.questionsQuestionCommentVote.create({
|
|
|
|
const incrementValue: number = vote === Vote.UPVOTE ? 1 : -1;
|
|
|
|
data: {
|
|
|
|
|
|
|
|
questionCommentId,
|
|
|
|
const [ questionCommentVote ] = await ctx.prisma.$transaction([
|
|
|
|
userId,
|
|
|
|
ctx.prisma.questionsQuestionCommentVote.create({
|
|
|
|
vote,
|
|
|
|
data: {
|
|
|
|
},
|
|
|
|
questionCommentId,
|
|
|
|
});
|
|
|
|
userId,
|
|
|
|
|
|
|
|
vote,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
ctx.prisma.questionsQuestionComment.update({
|
|
|
|
|
|
|
|
data: {
|
|
|
|
|
|
|
|
upvotes: {
|
|
|
|
|
|
|
|
increment: incrementValue,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
where: {
|
|
|
|
|
|
|
|
id: questionCommentId,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
return questionCommentVote;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.mutation('updateVote', {
|
|
|
|
.mutation('updateVote', {
|
|
|
@ -198,14 +213,30 @@ export const questionsQuestionCommentRouter = createProtectedRouter()
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return await ctx.prisma.questionsQuestionCommentVote.update({
|
|
|
|
const incrementValue = vote === Vote.UPVOTE ? 2 : -2;
|
|
|
|
data: {
|
|
|
|
|
|
|
|
vote,
|
|
|
|
const [questionCommentVote] = await ctx.prisma.$transaction([
|
|
|
|
},
|
|
|
|
ctx.prisma.questionsQuestionCommentVote.update({
|
|
|
|
where: {
|
|
|
|
data: {
|
|
|
|
id,
|
|
|
|
vote,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
where: {
|
|
|
|
|
|
|
|
id,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
ctx.prisma.questionsQuestionComment.update({
|
|
|
|
|
|
|
|
data: {
|
|
|
|
|
|
|
|
upvotes: {
|
|
|
|
|
|
|
|
increment: incrementValue,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
where: {
|
|
|
|
|
|
|
|
id: voteToUpdate.questionCommentId,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return questionCommentVote;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.mutation('deleteVote', {
|
|
|
|
.mutation('deleteVote', {
|
|
|
@ -229,10 +260,25 @@ export const questionsQuestionCommentRouter = createProtectedRouter()
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return await ctx.prisma.questionsQuestionCommentVote.delete({
|
|
|
|
const incrementValue = voteToDelete.vote === Vote.UPVOTE ? -1 : 1;
|
|
|
|
where: {
|
|
|
|
|
|
|
|
id: input.id,
|
|
|
|
const [questionCommentVote] = await ctx.prisma.$transaction([
|
|
|
|
},
|
|
|
|
ctx.prisma.questionsQuestionCommentVote.delete({
|
|
|
|
});
|
|
|
|
where: {
|
|
|
|
|
|
|
|
id: input.id,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
ctx.prisma.questionsQuestionComment.update({
|
|
|
|
|
|
|
|
data: {
|
|
|
|
|
|
|
|
upvotes: {
|
|
|
|
|
|
|
|
increment: incrementValue,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
where: {
|
|
|
|
|
|
|
|
id: voteToDelete.questionCommentId,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
return questionCommentVote;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|