implement subcategory
This commit is contained in:
Submodule epess-database updated: d4a5d689b8...9fa067cbe4
@@ -23,12 +23,25 @@ export class CategorySchema extends PothosSchema {
|
|||||||
fields: (t) => ({
|
fields: (t) => ({
|
||||||
id: t.exposeID('id'),
|
id: t.exposeID('id'),
|
||||||
name: t.exposeString('name'),
|
name: t.exposeString('name'),
|
||||||
serviceAndCategory: t.relation('serviceAndCategory'),
|
subCategory: t.relation('SubCategory'),
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@PothosRef()
|
@PothosRef()
|
||||||
|
subCategory() {
|
||||||
|
return this.builder.prismaObject('SubCategory', {
|
||||||
|
fields: (t) => ({
|
||||||
|
id: t.exposeID('id'),
|
||||||
|
name: t.exposeString('name'),
|
||||||
|
categoryId: t.exposeID('categoryId'),
|
||||||
|
category: t.relation('category'),
|
||||||
|
serviceAndCategory: t.relation('serviceAndCategory'),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Pothos()
|
||||||
init(): void {
|
init(): void {
|
||||||
this.builder.queryFields((t) => ({
|
this.builder.queryFields((t) => ({
|
||||||
categories: t.prismaField({
|
categories: t.prismaField({
|
||||||
@@ -54,6 +67,19 @@ export class CategorySchema extends PothosSchema {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
subCategories: t.prismaField({
|
||||||
|
type: [this.subCategory()],
|
||||||
|
args: this.builder.generator.findManyArgs('SubCategory'),
|
||||||
|
resolve: async (query, root, args, ctx, info) => {
|
||||||
|
return await this.prisma.subCategory.findMany({
|
||||||
|
...query,
|
||||||
|
where: args.filter ?? undefined,
|
||||||
|
orderBy: args.orderBy ?? undefined,
|
||||||
|
skip: args.skip ?? undefined,
|
||||||
|
take: args.take ?? 10,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
}),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// mutation
|
// mutation
|
||||||
@@ -87,6 +113,21 @@ export class CategorySchema extends PothosSchema {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
createSubCategory: t.prismaField({
|
||||||
|
type: this.subCategory(),
|
||||||
|
args: {
|
||||||
|
input: t.arg({
|
||||||
|
type: this.builder.generator.getCreateInput('SubCategory'),
|
||||||
|
required: true,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
resolve: async (query, root, args, ctx, info) => {
|
||||||
|
return await this.prisma.subCategory.create({
|
||||||
|
data: args.input,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
}),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,8 @@ export class ServiceAndCategorySchema extends PothosSchema {
|
|||||||
serviceId: t.exposeID('serviceId'),
|
serviceId: t.exposeID('serviceId'),
|
||||||
categoryId: t.exposeID('categoryId'),
|
categoryId: t.exposeID('categoryId'),
|
||||||
service: t.relation('service'),
|
service: t.relation('service'),
|
||||||
category: t.relation('category'),
|
subCategory: t.relation('SubCategory'),
|
||||||
|
subCategoryId: t.exposeID('subCategoryId'),
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user