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 ServiceFeedbackSchema extends PothosSchema { constructor( @Inject(SchemaBuilderToken) private readonly builder: Builder, private readonly prisma: PrismaService, ) { super() } @PothosRef() serviceFeedback() { return this.builder.prismaObject('ServiceFeedback', { description: 'A feedback for a service.', fields: (t) => ({ id: t.exposeID('id', { description: 'The ID of the service feedback.', }), userId: t.exposeID('userId', { description: 'The ID of the user who provided the feedback.', }), serviceId: t.exposeID('serviceId', { description: 'The ID of the service that was provided.', }), rating: t.exposeFloat('rating', { description: 'The rating of the service.', }), comments: t.exposeString('comments', { description: 'The comments of the service feedback.', }), createdAt: t.expose('createdAt', { type: 'DateTime', nullable: true, description: 'The date and time the service feedback was created.', }), updatedAt: t.expose('updatedAt', { type: 'DateTime', nullable: true, description: 'The date and time the service feedback was updated.', }), user: t.relation('user', { description: 'The user who provided the feedback.', }), service: t.relation('service', { description: 'The service that was provided.', }), }), }) } @Pothos() init(): void { this.builder.queryFields((t) => ({ serviceFeedbacks: t.prismaField({ type: [this.serviceFeedback()], args: this.builder.generator.findManyArgs('ServiceFeedback'), description: 'Retrieve a list of service feedbacks with optional filtering, ordering, and pagination.', resolve: async (query, _root, args, _ctx, _info) => { return await this.prisma.serviceFeedback.findMany({ ...query, skip: args.skip ?? undefined, take: args.take ?? undefined, orderBy: args.orderBy ?? undefined, where: args.filter ?? undefined, }) }, }), })) } }