update schema due to majority database change
This commit is contained in:
83
src/ManagedService/managedservice.schema.ts
Normal file
83
src/ManagedService/managedservice.schema.ts
Normal 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,
|
||||
});
|
||||
},
|
||||
}),
|
||||
}));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user