update many graphql field
This commit is contained in:
70
src/Order/order.schema.ts
Normal file
70
src/Order/order.schema.ts
Normal file
@@ -0,0 +1,70 @@
|
||||
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 OrderSchema extends PothosSchema {
|
||||
constructor(
|
||||
@Inject(SchemaBuilderToken) private readonly builder: Builder,
|
||||
private readonly prisma: PrismaService,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
// Types section
|
||||
@PothosRef()
|
||||
order() {
|
||||
return this.builder.prismaObject('Order', {
|
||||
fields: (t) => ({
|
||||
id: t.exposeID('id'),
|
||||
paymentId: t.exposeString('paymentId'),
|
||||
userId: t.exposeID('userId'),
|
||||
serviceId: t.exposeID('serviceId'),
|
||||
status: t.exposeString('status'),
|
||||
total: t.exposeInt('total'),
|
||||
createdAt: t.expose('createdAt', { type: 'DateTime' }),
|
||||
updatedAt: t.expose('updatedAt', { type: 'DateTime' }),
|
||||
user: t.relation('user'),
|
||||
payment: t.relation('payment'),
|
||||
service: t.relation('service'),
|
||||
refundTicket: t.relation('refundTicket'),
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
@PothosRef()
|
||||
init(): void {
|
||||
// query section
|
||||
this.builder.queryFields((t) => ({
|
||||
orders: t.prismaField({
|
||||
type: [this.order()],
|
||||
args: this.builder.generator.findManyArgs('Order'),
|
||||
resolve: async (query, root, args, ctx, info) => {
|
||||
return await this.prisma.order.findMany({
|
||||
...query,
|
||||
take: args.take ?? 10,
|
||||
skip: args.skip ?? 0,
|
||||
orderBy: args.orderBy ?? undefined,
|
||||
where: args.filter ?? undefined,
|
||||
});
|
||||
},
|
||||
}),
|
||||
order: t.prismaField({
|
||||
type: this.order(),
|
||||
args: this.builder.generator.findUniqueArgs('Order'),
|
||||
resolve: async (query, root, args, ctx, info) => {
|
||||
return await this.prisma.order.findUnique({
|
||||
...query,
|
||||
where: args.where,
|
||||
});
|
||||
},
|
||||
}),
|
||||
}));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user