From 342fea041f9944f43c9ef5089a7f02390c4900f8 Mon Sep 17 00:00:00 2001 From: Ly Tuan Kiet Date: Mon, 9 Dec 2024 17:45:52 +0700 Subject: [PATCH] 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. --- src/Quiz/quiz.schema.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Quiz/quiz.schema.ts b/src/Quiz/quiz.schema.ts index 1c6c4c2..b391d6f 100644 --- a/src/Quiz/quiz.schema.ts +++ b/src/Quiz/quiz.schema.ts @@ -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, }, }) },