fix: stats now group by status

This commit is contained in:
Methapon Metanipat 2024-11-07 12:59:37 +07:00
parent 5fa6e4d2f9
commit 4d2dadbc05

View file

@ -170,14 +170,14 @@ export class QuotationController extends Controller {
async getProductStats(@Request() req: RequestWithUser) {
const result = await prisma.quotation.groupBy({
_count: true,
by: "payCondition",
by: "quotationStatus",
where: {
registeredBranch: isSystem(req.user) ? undefined : { OR: permissionCond(req.user) },
},
});
return result.reduce<Record<string, number>>((a, c) => {
a[c.payCondition.charAt(0).toLowerCase() + c.payCondition.slice(1)] = c._count;
a[c.quotationStatus.charAt(0).toLowerCase() + c.quotationStatus.slice(1)] = c._count;
return a;
}, {});
}