update many graphql field

This commit is contained in:
2024-10-12 16:34:43 +07:00
parent 244a6f3015
commit ba77bd4e1c
29 changed files with 466 additions and 56 deletions

View File

@@ -0,0 +1,9 @@
import { Global, Module } from '@nestjs/common';
import { ServiceFeedbackSchema } from './servicefeedback.schema';
@Global()
@Module({
providers: [ServiceFeedbackSchema],
exports: [ServiceFeedbackSchema],
})
export class ServiceFeedbackModule {}

View File

@@ -0,0 +1,55 @@
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', {
fields: (t) => ({
id: t.exposeID('id'),
userId: t.exposeID('userId'),
serviceId: t.exposeID('serviceId'),
rating: t.exposeFloat('rating'),
comments: t.exposeString('comments'),
createdAt: t.expose('createdAt', { type: 'DateTime' }),
updatedAt: t.expose('updatedAt', { type: 'DateTime' }),
user: t.relation('user'),
service: t.relation('service'),
}),
});
}
@Pothos()
init(): void {
this.builder.queryFields((t) => ({
serviceFeedbacks: t.prismaField({
type: [this.serviceFeedback()],
args: this.builder.generator.findManyArgs('ServiceFeedback'),
resolve: async (query, root, args, ctx, info) => {
return await this.prisma.serviceFeedback.findMany({
...query,
skip: args.skip ?? 0,
take: args.take ?? 10,
orderBy: args.orderBy ?? undefined,
where: args.filter ?? undefined,
});
},
}),
}));
}
}