Files
epess-web-backend/src/ServiceAndCategory/serviceandcategory.schema.ts

51 lines
1.4 KiB
TypeScript

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 ServiceAndCategorySchema extends PothosSchema {
constructor(
@Inject(SchemaBuilderToken) private readonly builder: Builder,
private readonly prisma: PrismaService,
) {
super();
}
@PothosRef()
serviceAndCategory() {
return this.builder.prismaObject('ServiceAndCategory', {
fields: (t) => ({
serviceId: t.exposeID('serviceId'),
service: t.relation('service'),
subCategory: t.relation('SubCategory'),
subCategoryId: t.exposeID('subCategoryId'),
}),
});
}
@Pothos()
init(): void {
this.builder.queryFields((t) => ({
serviceAndCategories: t.prismaField({
type: [this.serviceAndCategory()],
args: this.builder.generator.findManyArgs('ServiceAndCategory'),
resolve: async (query, root, args, ctx, info) => {
return await this.prisma.serviceAndCategory.findMany({
...query,
skip: args.skip ?? 0,
take: args.take ?? 10,
orderBy: args.orderBy ?? undefined,
where: args.filter ?? undefined,
});
},
}),
}));
}
}