feat: add service field to Quiz creation and enforce service ID requirement

- Introduced 'service' field in the Quiz creation input to enhance data structure.
- Added validation to ensure 'service ID' is provided during Quiz creation, improving data integrity.
- Updated centerMentor association logic to connect the current user as the center mentor for the Quiz.
This commit is contained in:
2024-12-09 17:45:52 +07:00
parent b8d7c52d63
commit 342fea041f

View File

@@ -170,7 +170,13 @@ export class QuizSchema extends PothosSchema {
type: this.quiz(),
args: {
data: t.arg({
type: this.builder.generator.getCreateInput('Quiz', ['id', 'centerMentorId', 'createdAt', 'updatedAt']),
type: this.builder.generator.getCreateInput('Quiz', [
'id',
'centerMentorId',
'createdAt',
'updatedAt',
'service',
]),
required: true,
}),
},
@@ -184,12 +190,18 @@ export class QuizSchema extends PothosSchema {
if (!args.data) {
throw new Error('Data is required')
}
if (!args.data.service?.connect?.id) {
throw new Error('Service ID is required')
}
args.data.centerMentor = {
connect: {
mentorId: ctx.http.me.id,
},
}
return await this.prisma.quiz.create({
...query,
data: {
...args.data,
centerMentorId: ctx.http.me.id,
},
})
},