From 77e35265641a49818c6ec1f4eb407c51a30943f3 Mon Sep 17 00:00:00 2001 From: Ly Tuan Kiet Date: Sat, 7 Dec 2024 16:05:12 +0700 Subject: [PATCH] feat: add scheduleDates field to ScheduleSchema for retrieving schedule dates - Introduced a new `scheduleDates` field in the ScheduleSchema to allow users to fetch a list of schedule dates. - Implemented argument handling for pagination and filtering, ensuring efficient data retrieval. - Added error handling to prevent access during subscriptions and ensure user authentication before data access. - Enhanced the overall functionality of the ScheduleSchema, improving user experience and data management. --- src/Schedule/schedule.schema.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/Schedule/schedule.schema.ts b/src/Schedule/schedule.schema.ts index 76991d6..f1c64a4 100644 --- a/src/Schedule/schedule.schema.ts +++ b/src/Schedule/schedule.schema.ts @@ -311,6 +311,29 @@ export class ScheduleSchema extends PothosSchema { }, }), + scheduleDates: t.prismaField({ + type: [this.scheduleDate()], + description: 'Retrieve a list of schedule dates.', + args: this.builder.generator.findManyArgs('ScheduleDate'), + resolve: async (query, _root, args, ctx, _info) => { + if (ctx.isSubscription) { + throw new Error('Cannot retrieve schedule dates in subscription') + } + if (!ctx.http?.me?.id) { + throw new Error('User not found') + } + return await this.prisma.scheduleDate.findMany({ + ...query, + skip: args.skip ?? undefined, + take: args.take ?? undefined, + orderBy: args.orderBy ?? undefined, + where: { + AND: [{ participantIds: { has: ctx.http.me.id } }, ...(args.filter ? [args.filter] : [])], + }, + }) + }, + }), + centerPreviewSchedule: t.field({ type: this.previewSchedule(), description: 'Preview a schedule for center mentor.',