mirror of
https://github.com/yangshun/tech-interview-handbook.git
synced 2025-07-30 13:43:59 +08:00
[questions][refactor]: refactor queries (#383)
This commit is contained in:
@ -12,6 +12,7 @@ export const questionsQuestionCommentRouter = createProtectedRouter()
|
||||
questionId: z.string(),
|
||||
}),
|
||||
async resolve({ ctx, input }) {
|
||||
const { questionId } = input;
|
||||
const questionCommentsData =
|
||||
await ctx.prisma.questionsQuestionComment.findMany({
|
||||
include: {
|
||||
@ -27,7 +28,7 @@ export const questionsQuestionCommentRouter = createProtectedRouter()
|
||||
createdAt: 'desc',
|
||||
},
|
||||
where: {
|
||||
...input,
|
||||
questionId,
|
||||
},
|
||||
});
|
||||
return questionCommentsData.map((data) => {
|
||||
@ -68,9 +69,12 @@ export const questionsQuestionCommentRouter = createProtectedRouter()
|
||||
async resolve({ ctx, input }) {
|
||||
const userId = ctx.session?.user?.id;
|
||||
|
||||
const { content, questionId } = input;
|
||||
|
||||
return await ctx.prisma.questionsQuestionComment.create({
|
||||
data: {
|
||||
...input,
|
||||
content,
|
||||
questionId,
|
||||
userId,
|
||||
},
|
||||
});
|
||||
@ -84,6 +88,8 @@ export const questionsQuestionCommentRouter = createProtectedRouter()
|
||||
async resolve({ ctx, input }) {
|
||||
const userId = ctx.session?.user?.id;
|
||||
|
||||
const { content } = input;
|
||||
|
||||
const questionCommentToUpdate =
|
||||
await ctx.prisma.questionsQuestionComment.findUnique({
|
||||
where: {
|
||||
@ -100,7 +106,7 @@ export const questionsQuestionCommentRouter = createProtectedRouter()
|
||||
|
||||
return await ctx.prisma.questionsQuestionComment.update({
|
||||
data: {
|
||||
...input,
|
||||
content,
|
||||
},
|
||||
where: {
|
||||
id: input.id,
|
||||
@ -158,11 +164,13 @@ export const questionsQuestionCommentRouter = createProtectedRouter()
|
||||
}),
|
||||
async resolve({ ctx, input }) {
|
||||
const userId = ctx.session?.user?.id;
|
||||
const { questionCommentId, vote } = input;
|
||||
|
||||
return await ctx.prisma.questionsQuestionCommentVote.create({
|
||||
data: {
|
||||
...input,
|
||||
questionCommentId,
|
||||
userId,
|
||||
vote,
|
||||
},
|
||||
});
|
||||
},
|
||||
|
Reference in New Issue
Block a user