🔥🔥🔥🔥🔥🔥

This commit is contained in:
2024-10-12 17:11:09 +07:00
parent ba77bd4e1c
commit 4fac0a052b
13 changed files with 354 additions and 4 deletions

View File

@@ -0,0 +1,62 @@
import { Inject, Injectable } from '@nestjs/common';
import {
Pothos,
PothosRef,
PothosSchema,
SchemaBuilderToken,
} from '@smatch-corp/nestjs-pothos';
import { Builder } from '../Graphql/graphql.builder';
import { PrismaService } from '../Prisma/prisma.service';
@Injectable()
export class ScheduleSchema extends PothosSchema {
constructor(
@Inject(SchemaBuilderToken) private readonly builder: Builder,
private readonly prisma: PrismaService,
) {
super();
}
@PothosRef()
schedule() {
return this.builder.prismaObject('Schedule', {
fields: (t) => ({
id: t.exposeID('id'),
serviceId: t.exposeID('serviceId'),
service: t.relation('service'),
dates: t.expose('dates', { type: 'Json' as any }),
status: t.exposeString('status'),
}),
});
}
@Pothos()
init(): void {
this.builder.queryFields((t) => ({
schedule: t.prismaField({
type: this.schedule(),
args: this.builder.generator.findUniqueArgs('Schedule'),
resolve: async (query, root, args, ctx, info) => {
return await this.prisma.schedule.findUnique({
...query,
where: args.where,
});
},
}),
schedules: t.prismaField({
type: [this.schedule()],
args: this.builder.generator.findManyArgs('Schedule'),
resolve: async (query, root, args, ctx, info) => {
return await this.prisma.schedule.findMany({
...query,
skip: args.skip ?? 0,
take: args.take ?? 10,
orderBy: args.orderBy ?? undefined,
where: args.filter ?? undefined,
});
},
}),
}));
}
}