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:
@@ -75,7 +75,7 @@ export class QuizSchema extends PothosSchema {
|
|||||||
quizAttempt() {
|
quizAttempt() {
|
||||||
return this.builder.prismaObject('QuizAttempt', {
|
return this.builder.prismaObject('QuizAttempt', {
|
||||||
fields: (t) => ({
|
fields: (t) => ({
|
||||||
id: t.exposeID('id'),
|
id: t.exposeID('id'),
|
||||||
quizId: t.exposeID('quizId'),
|
quizId: t.exposeID('quizId'),
|
||||||
quiz: t.relation('quiz'),
|
quiz: t.relation('quiz'),
|
||||||
userId: t.exposeID('userId'),
|
userId: t.exposeID('userId'),
|
||||||
@@ -211,13 +211,22 @@ export class QuizSchema extends PothosSchema {
|
|||||||
if (!centerMentor) {
|
if (!centerMentor) {
|
||||||
throw new Error('Center mentor not found')
|
throw new Error('Center mentor not found')
|
||||||
}
|
}
|
||||||
return await this.prisma.quiz.findMany({
|
if (args.scheduleId) {
|
||||||
...query,
|
const schedule = await this.prisma.schedule.findUnique({
|
||||||
where: {
|
where: { id: args.scheduleId },
|
||||||
serviceId: args.serviceId,
|
})
|
||||||
centerMentorId: centerMentor.mentorId,
|
if (!schedule) {
|
||||||
},
|
throw new Error('Schedule not found')
|
||||||
})
|
}
|
||||||
|
return await this.prisma.quiz.findMany({
|
||||||
|
...query,
|
||||||
|
where: {
|
||||||
|
serviceId: args.serviceId,
|
||||||
|
centerMentorId: centerMentor.mentorId,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
throw new Error('Schedule ID is required')
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|||||||
Reference in New Issue
Block a user