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:
@@ -187,6 +187,9 @@ export class OrderSchema extends PothosSchema {
|
||||
if (ctx.isSubscription) {
|
||||
throw new Error('Subscription is not allowed')
|
||||
}
|
||||
if (!ctx.http.me) {
|
||||
throw new Error('Unauthorized')
|
||||
}
|
||||
if (!args.data.service.connect?.id) {
|
||||
throw new Error('Service not found')
|
||||
}
|
||||
@@ -197,6 +200,24 @@ export class OrderSchema extends PothosSchema {
|
||||
if (!service) {
|
||||
throw new Error('Service not found')
|
||||
}
|
||||
// check if user has already registered for this service
|
||||
const userService = await this.prisma.schedule.findFirst({
|
||||
where: {
|
||||
AND: [
|
||||
{
|
||||
customerId: ctx.http.me?.id,
|
||||
},
|
||||
{
|
||||
managedService: {
|
||||
serviceId: service.id,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
if (userService) {
|
||||
throw new Error('User has already registered for this service')
|
||||
}
|
||||
// check if input schedule has order id then throw error
|
||||
const schedule = await this.prisma.schedule.findUnique({
|
||||
where: { id: args.data.schedule.connect?.id ?? '' },
|
||||
|
||||
Reference in New Issue
Block a user