feat: enhance GraphQL schemas and service logic

- Added support for creating relation inputs in PrismaCrudGenerator for object types.
- Implemented unauthorized access checks in OrderSchema to ensure user authentication.
- Added logic to prevent duplicate service registrations for users in OrderSchema.
- Updated PayosService to change order status from IN_PROGRESS to WAITING_QUIZ.
- Introduced a new mutation for creating multiple personal milestones in PersonalMilestoneSchema with necessary validation.
- Enhanced QuizSchema to update schedule status to WAITING_INTERVIEW upon quiz attempt creation.

These changes improve the robustness of the GraphQL API by adding necessary validations, enhancing user experience, and ensuring proper state management across various schemas.
This commit is contained in:
2024-12-13 18:52:16 +07:00
parent ed8df7a1bc
commit bbe0d34cdb
5 changed files with 74 additions and 4 deletions

View File

@@ -1,6 +1,6 @@
import crypto from 'crypto'
import { Inject, Injectable, Logger } from '@nestjs/common'
import { AnswerType, Role } from '@prisma/client'
import { AnswerType, Role, ScheduleStatus } from '@prisma/client'
import { QuestionType } from '@prisma/client'
import { Pothos, PothosRef, PothosSchema, SchemaBuilderToken } from '@smatch-corp/nestjs-pothos'
import { Builder } from '../Graphql/graphql.builder'
@@ -205,6 +205,7 @@ export class QuizSchema extends PothosSchema {
centerMentorId: centerMentorId,
},
})
// check if user has already taken the quiz
const quizAttempt = await this.prisma.quizAttempt.findFirst({
where: {
@@ -437,7 +438,7 @@ export class QuizSchema extends PothosSchema {
throw new Error('Quiz not found')
}
try {
return await this.prisma.quizAttempt.create({
const result = await this.prisma.quizAttempt.create({
...query,
data: {
...args.data,
@@ -445,6 +446,12 @@ export class QuizSchema extends PothosSchema {
user: { connect: { id: ctx.http.me.id } },
},
})
// update schedule status to WAITING_INTERVIEW
await this.prisma.schedule.update({
where: { id: result.quizId },
data: { status: ScheduleStatus.WAITING_INTERVIEW },
})
return result
} catch (_error) {
throw new Error('Quiz attempt already exists')
}