update schema due to majority database change

This commit is contained in:
2024-10-18 01:50:26 +07:00
parent 9dcc84d371
commit 1523642b9d
13 changed files with 293 additions and 61 deletions

View File

@@ -0,0 +1,7 @@
import { Module } from '@nestjs/common';
import { ManagedServiceSchema } from './managedservice.schema';
@Module({
providers: [ManagedServiceSchema],
})
export class ManagedServiceModule {}

View File

@@ -0,0 +1,83 @@
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 ManagedServiceSchema extends PothosSchema {
constructor(
@Inject(SchemaBuilderToken) private readonly builder: Builder,
private readonly prisma: PrismaService,
) {
super();
}
@PothosRef()
managedService() {
return this.builder.prismaObject('ManagedService', {
description: 'A managed service',
fields: (t) => ({
staffId: t.exposeID('staffId', {
description: 'The ID of the staff member.',
}),
serviceId: t.exposeID('serviceId', {
description: 'The ID of the service.',
}),
staff: t.relation('staff'),
service: t.relation('service'),
}),
});
}
@Pothos()
init(): void {
this.builder.queryFields((t) => ({
managedService: t.field({
type: this.managedService(),
args: this.builder.generator.findUniqueArgs('ManagedService'),
resolve: async (parent, args, context) => {
return this.prisma.managedService.findUnique({
where: args.where,
});
},
}),
managedServices: t.field({
type: [this.managedService()],
args: this.builder.generator.findManyArgs('ManagedService'),
resolve: async (parent, args, context) => {
return this.prisma.managedService.findMany({
where: args.filter ?? undefined,
orderBy: args.orderBy ?? undefined,
cursor: args.cursor ?? undefined,
take: args.take ?? 10,
skip: args.skip ?? undefined,
});
},
}),
}));
this.builder.mutationFields((t) => ({
createManagedService: t.field({
type: this.managedService(),
args: {
input: t.arg({
type: this.builder.generator.getCreateInput('ManagedService'),
required: true,
description: 'The data for the managed service.',
}),
},
resolve: async (parent, args, context) => {
return this.prisma.managedService.create({
data: args.input,
});
},
}),
}));
}
}