🔥🔥🔥🔥🔥🔥
This commit is contained in:
62
src/Schedule/schedule.schema.ts
Normal file
62
src/Schedule/schedule.schema.ts
Normal 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,
|
||||
});
|
||||
},
|
||||
}),
|
||||
}));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user