update service and category

This commit is contained in:
2024-11-11 18:55:24 +07:00
parent 705c4b53d8
commit e0a8b0aaa0
8 changed files with 130 additions and 20 deletions

View File

@@ -31,6 +31,9 @@ export class ServiceAndCategorySchema extends PothosSchema {
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.',
}),
@@ -41,12 +44,23 @@ export class ServiceAndCategorySchema extends PothosSchema {
@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) => {
resolve: async (query, _root, args, _ctx, _info) => {
return await this.prisma.serviceAndCategory.findMany({
...query,
skip: args.skip ?? undefined,
@@ -56,6 +70,41 @@ export class ServiceAndCategorySchema extends PothosSchema {
})
},
}),
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,
},
})
},
}),
}))
}
}