feat: add count of service under group / type
This commit is contained in:
parent
68bed31800
commit
14004b81c9
2 changed files with 11 additions and 4 deletions
|
|
@ -84,9 +84,9 @@ export class ProductGroup extends Controller {
|
|||
prisma.productGroup.count({ where }),
|
||||
]);
|
||||
|
||||
const statsProduct = await prisma.productType.findMany({
|
||||
const statsDeep = await prisma.productType.findMany({
|
||||
include: {
|
||||
_count: { select: { product: true } },
|
||||
_count: { select: { product: true, service: true } },
|
||||
},
|
||||
where: {
|
||||
productGroupId: { in: result.map((v) => v.id) },
|
||||
|
|
@ -98,10 +98,14 @@ export class ProductGroup extends Controller {
|
|||
...v,
|
||||
_count: {
|
||||
...v._count,
|
||||
product: statsProduct.reduce(
|
||||
product: statsDeep.reduce(
|
||||
(a, c) => (c.productGroupId === v.id ? a + c._count.product : a),
|
||||
0,
|
||||
),
|
||||
service: statsDeep.reduce(
|
||||
(a, c) => (c.productGroupId === v.id ? a + c._count.service : a),
|
||||
0,
|
||||
),
|
||||
},
|
||||
})),
|
||||
page,
|
||||
|
|
|
|||
|
|
@ -70,7 +70,10 @@ export class ProductType extends Controller {
|
|||
prisma.productType.findMany({
|
||||
include: {
|
||||
_count: {
|
||||
select: { product: true },
|
||||
select: {
|
||||
product: true,
|
||||
service: true,
|
||||
},
|
||||
},
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue