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.
This commit is contained in:
@@ -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.',
|
||||
|
||||
Reference in New Issue
Block a user