refactor: improve quiz retrieval logic with schedule validation

- Added validation to ensure 'scheduleId' is provided when retrieving quizzes, enhancing error handling.
- Implemented a check for the existence of the schedule before proceeding with quiz retrieval, improving robustness.
- Reformatted code for better readability and consistency in the Quiz schema.
This commit is contained in:
2024-12-10 16:37:36 +07:00
parent 4435bc0804
commit d18258f81a

View File

@@ -211,6 +211,13 @@ export class QuizSchema extends PothosSchema {
if (!centerMentor) { if (!centerMentor) {
throw new Error('Center mentor not found') throw new Error('Center mentor not found')
} }
if (args.scheduleId) {
const schedule = await this.prisma.schedule.findUnique({
where: { id: args.scheduleId },
})
if (!schedule) {
throw new Error('Schedule not found')
}
return await this.prisma.quiz.findMany({ return await this.prisma.quiz.findMany({
...query, ...query,
where: { where: {
@@ -219,6 +226,8 @@ export class QuizSchema extends PothosSchema {
}, },
}) })
} }
throw new Error('Schedule ID is required')
}
}, },
}), }),
})) }))