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 }),
|
prisma.productGroup.count({ where }),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const statsProduct = await prisma.productType.findMany({
|
const statsDeep = await prisma.productType.findMany({
|
||||||
include: {
|
include: {
|
||||||
_count: { select: { product: true } },
|
_count: { select: { product: true, service: true } },
|
||||||
},
|
},
|
||||||
where: {
|
where: {
|
||||||
productGroupId: { in: result.map((v) => v.id) },
|
productGroupId: { in: result.map((v) => v.id) },
|
||||||
|
|
@ -98,10 +98,14 @@ export class ProductGroup extends Controller {
|
||||||
...v,
|
...v,
|
||||||
_count: {
|
_count: {
|
||||||
...v._count,
|
...v._count,
|
||||||
product: statsProduct.reduce(
|
product: statsDeep.reduce(
|
||||||
(a, c) => (c.productGroupId === v.id ? a + c._count.product : a),
|
(a, c) => (c.productGroupId === v.id ? a + c._count.product : a),
|
||||||
0,
|
0,
|
||||||
),
|
),
|
||||||
|
service: statsDeep.reduce(
|
||||||
|
(a, c) => (c.productGroupId === v.id ? a + c._count.service : a),
|
||||||
|
0,
|
||||||
|
),
|
||||||
},
|
},
|
||||||
})),
|
})),
|
||||||
page,
|
page,
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,10 @@ export class ProductType extends Controller {
|
||||||
prisma.productType.findMany({
|
prisma.productType.findMany({
|
||||||
include: {
|
include: {
|
||||||
_count: {
|
_count: {
|
||||||
select: { product: true },
|
select: {
|
||||||
|
product: true,
|
||||||
|
service: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
createdBy: true,
|
createdBy: true,
|
||||||
updatedBy: true,
|
updatedBy: true,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue