111 lines
3.5 KiB
TypeScript
111 lines
3.5 KiB
TypeScript
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 ServiceAndCategorySchema extends PothosSchema {
|
|
constructor(
|
|
@Inject(SchemaBuilderToken) private readonly builder: Builder,
|
|
private readonly prisma: PrismaService,
|
|
) {
|
|
super()
|
|
}
|
|
|
|
@PothosRef()
|
|
serviceAndCategory() {
|
|
return this.builder.prismaObject('ServiceAndCategory', {
|
|
description: 'A service and category in the system.',
|
|
fields: (t) => ({
|
|
serviceId: t.exposeID('serviceId', {
|
|
description: 'The ID of the service.',
|
|
}),
|
|
service: t.relation('service', {
|
|
description: 'The service for the service and category.',
|
|
}),
|
|
subCategory: t.relation('subCategory', {
|
|
description: 'The sub category for the service and category.',
|
|
}),
|
|
isDeleted: t.exposeBoolean('isDeleted', {
|
|
description: 'Whether the service and category is deleted.',
|
|
}),
|
|
subCategoryId: t.exposeID('subCategoryId', {
|
|
description: 'The ID of the sub category.',
|
|
}),
|
|
}),
|
|
})
|
|
}
|
|
|
|
@Pothos()
|
|
init(): void {
|
|
this.builder.queryFields((t) => ({
|
|
serviceAndCategory: t.prismaField({
|
|
type: this.serviceAndCategory(),
|
|
args: this.builder.generator.findUniqueArgs('ServiceAndCategory'),
|
|
description: 'Retrieve a service and category by ID.',
|
|
resolve: async (query, _root, args, _ctx, _info) => {
|
|
return await this.prisma.serviceAndCategory.findUnique({
|
|
...query,
|
|
where: args.where,
|
|
})
|
|
},
|
|
}),
|
|
serviceAndCategories: t.prismaField({
|
|
type: [this.serviceAndCategory()],
|
|
args: this.builder.generator.findManyArgs('ServiceAndCategory'),
|
|
description:
|
|
'Retrieve a list of service and categories with optional filtering, ordering, and pagination.',
|
|
resolve: async (query, _root, args, _ctx, _info) => {
|
|
return await this.prisma.serviceAndCategory.findMany({
|
|
...query,
|
|
skip: args.skip ?? undefined,
|
|
take: args.take ?? undefined,
|
|
orderBy: args.orderBy ?? undefined,
|
|
where: args.filter ?? undefined,
|
|
})
|
|
},
|
|
}),
|
|
createServiceAndCategory: t.prismaField({
|
|
type: this.serviceAndCategory(),
|
|
args: {
|
|
data: t.arg({
|
|
type: this.builder.generator.getCreateInput('ServiceAndCategory'),
|
|
required: true,
|
|
}),
|
|
},
|
|
description: 'Create a service and category.',
|
|
resolve: async (query, _root, args, _ctx, _info) => {
|
|
return await this.prisma.serviceAndCategory.create({
|
|
...query,
|
|
data: args.data,
|
|
})
|
|
},
|
|
}),
|
|
deleteServiceAndCategory: t.prismaField({
|
|
type: this.serviceAndCategory(),
|
|
args: {
|
|
where: t.arg({
|
|
type: this.builder.generator.getWhereUnique('ServiceAndCategory'),
|
|
required: true,
|
|
}),
|
|
},
|
|
description: 'Delete a service and category.',
|
|
resolve: async (query, _root, args, _ctx, _info) => {
|
|
return await this.prisma.serviceAndCategory.update({
|
|
...query,
|
|
where: args.where,
|
|
data: {
|
|
isDeleted: true,
|
|
},
|
|
})
|
|
},
|
|
}),
|
|
}))
|
|
}
|
|
}
|