update many graphql field
This commit is contained in:
9
src/RefundTicket/refundticket.module.ts
Normal file
9
src/RefundTicket/refundticket.module.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { Global, Module } from '@nestjs/common';
|
||||
import { RefundTicketSchema } from './refundticket.schema';
|
||||
|
||||
@Global()
|
||||
@Module({
|
||||
providers: [RefundTicketSchema],
|
||||
exports: [RefundTicketSchema],
|
||||
})
|
||||
export class RefundTicketModule {}
|
||||
55
src/RefundTicket/refundticket.schema.ts
Normal file
55
src/RefundTicket/refundticket.schema.ts
Normal 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 'src/Prisma/prisma.service';
|
||||
|
||||
@Injectable()
|
||||
export class RefundTicketSchema extends PothosSchema {
|
||||
constructor(
|
||||
@Inject(SchemaBuilderToken) private readonly builder: Builder,
|
||||
private readonly prisma: PrismaService,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
// Types section
|
||||
@PothosRef()
|
||||
refundTicket() {
|
||||
return this.builder.prismaObject('RefundTicket', {
|
||||
fields: (t) => ({
|
||||
id: t.exposeID('id'),
|
||||
amount: t.exposeFloat('amount'),
|
||||
status: t.exposeString('status'),
|
||||
createdAt: t.expose('createdAt', { type: 'DateTime' }),
|
||||
updatedAt: t.expose('updatedAt', { type: 'DateTime' }),
|
||||
order: t.relation('order'),
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
// Queries section
|
||||
@Pothos()
|
||||
init(): void {
|
||||
this.builder.queryFields((t) => ({
|
||||
refundTickets: t.prismaField({
|
||||
type: [this.refundTicket()],
|
||||
args: this.builder.generator.findManyArgs('RefundTicket'),
|
||||
resolve: async (query, root, args, ctx, info) => {
|
||||
return await this.prisma.refundTicket.findMany({
|
||||
...query,
|
||||
where: args.filter ?? undefined,
|
||||
orderBy: args.orderBy ?? undefined,
|
||||
cursor: args.cursor ?? undefined,
|
||||
take: args.take ?? 10,
|
||||
skip: args.skip ?? 0,
|
||||
});
|
||||
},
|
||||
}),
|
||||
}));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user