mirror of
https://github.com/yangshun/tech-interview-handbook.git
synced 2025-07-29 21:23:14 +08:00
[questions][feat] pagination (#410)
* [questions][feat] pagination * [questions][feat] update aggregated data * [questions][feat] add next cursors * [questions][fix] fix bug * [questions][chore] fix lint error * [questions][chore] update cursor to support adapter * [questions][feat] paginate browse queries * [questions][ui] change page size to 10 * [question][refactor] clean up router code * [questions][fix] fix type errors * [questions][feat] add upvotes tracking * [questions][chore] add default upovte value Co-authored-by: Jeff Sieu <jeffsy00@gmail.com>
This commit is contained in:
@ -166,13 +166,28 @@ export const questionsQuestionCommentRouter = createProtectedRouter()
|
||||
const userId = ctx.session?.user?.id;
|
||||
const { questionCommentId, vote } = input;
|
||||
|
||||
return await ctx.prisma.questionsQuestionCommentVote.create({
|
||||
data: {
|
||||
questionCommentId,
|
||||
userId,
|
||||
vote,
|
||||
},
|
||||
});
|
||||
const incrementValue: number = vote === Vote.UPVOTE ? 1 : -1;
|
||||
|
||||
const [ questionCommentVote ] = await ctx.prisma.$transaction([
|
||||
ctx.prisma.questionsQuestionCommentVote.create({
|
||||
data: {
|
||||
questionCommentId,
|
||||
userId,
|
||||
vote,
|
||||
},
|
||||
}),
|
||||
ctx.prisma.questionsQuestionComment.update({
|
||||
data: {
|
||||
upvotes: {
|
||||
increment: incrementValue,
|
||||
},
|
||||
},
|
||||
where: {
|
||||
id: questionCommentId,
|
||||
},
|
||||
}),
|
||||
]);
|
||||
return questionCommentVote;
|
||||
},
|
||||
})
|
||||
.mutation('updateVote', {
|
||||
@ -198,14 +213,30 @@ export const questionsQuestionCommentRouter = createProtectedRouter()
|
||||
});
|
||||
}
|
||||
|
||||
return await ctx.prisma.questionsQuestionCommentVote.update({
|
||||
data: {
|
||||
vote,
|
||||
},
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
});
|
||||
const incrementValue = vote === Vote.UPVOTE ? 2 : -2;
|
||||
|
||||
const [questionCommentVote] = await ctx.prisma.$transaction([
|
||||
ctx.prisma.questionsQuestionCommentVote.update({
|
||||
data: {
|
||||
vote,
|
||||
},
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
}),
|
||||
ctx.prisma.questionsQuestionComment.update({
|
||||
data: {
|
||||
upvotes: {
|
||||
increment: incrementValue,
|
||||
},
|
||||
},
|
||||
where: {
|
||||
id: voteToUpdate.questionCommentId,
|
||||
},
|
||||
}),
|
||||
]);
|
||||
|
||||
return questionCommentVote;
|
||||
},
|
||||
})
|
||||
.mutation('deleteVote', {
|
||||
@ -229,10 +260,25 @@ export const questionsQuestionCommentRouter = createProtectedRouter()
|
||||
});
|
||||
}
|
||||
|
||||
return await ctx.prisma.questionsQuestionCommentVote.delete({
|
||||
where: {
|
||||
id: input.id,
|
||||
},
|
||||
});
|
||||
const incrementValue = voteToDelete.vote === Vote.UPVOTE ? -1 : 1;
|
||||
|
||||
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;
|
||||
},
|
||||
});
|
||||
|
Reference in New Issue
Block a user