feat: enhance QuizSchema with schedule integration and validation
- Added scheduleId and schedule relation to QuizSchema, allowing quizzes to be associated with specific schedules. - Implemented validation to ensure that both quiz ID and schedule ID are provided during quiz attempt creation, improving data integrity. - Updated related types in pothos.generated.ts to reflect the new schedule relationship, enhancing the overall schema structure. These changes improve the functionality of the Quiz feature by integrating schedule management and ensuring proper validation during quiz attempts.
This commit is contained in:
@@ -91,6 +91,8 @@ export class QuizSchema extends PothosSchema {
|
||||
questions: t.expose('questions', {
|
||||
type: 'JsonList',
|
||||
}),
|
||||
scheduleId: t.exposeID('scheduleId'),
|
||||
schedule: t.relation('schedule'),
|
||||
createdAt: t.expose('createdAt', {
|
||||
type: 'DateTime',
|
||||
}),
|
||||
@@ -432,6 +434,9 @@ export class QuizSchema extends PothosSchema {
|
||||
if (!args.data.quiz?.connect?.id) {
|
||||
throw new Error('Quiz ID is required')
|
||||
}
|
||||
if (!args.data.schedule?.connect?.id) {
|
||||
throw new Error('Schedule ID is required')
|
||||
}
|
||||
// query the quiz to get the questions
|
||||
const quiz = await this.prisma.quiz.findUnique({
|
||||
where: { id: args.data.quiz.connect.id },
|
||||
@@ -450,7 +455,7 @@ export class QuizSchema extends PothosSchema {
|
||||
})
|
||||
// update schedule status to WAITING_INTERVIEW
|
||||
await this.prisma.schedule.update({
|
||||
where: { id: result.quizId },
|
||||
where: { id: args.data.schedule.connect.id },
|
||||
data: { status: ScheduleStatus.WAITING_INTERVIEW },
|
||||
})
|
||||
return result
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user