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) { async getProductStats(@Request() req: RequestWithUser) {
const result = await prisma.quotation.groupBy({ const result = await prisma.quotation.groupBy({
_count: true, _count: true,
by: "payCondition", by: "quotationStatus",
where: { where: {
registeredBranch: isSystem(req.user) ? undefined : { OR: permissionCond(req.user) }, registeredBranch: isSystem(req.user) ? undefined : { OR: permissionCond(req.user) },
}, },
}); });
return result.reduce<Record<string, number>>((a, c) => { 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; return a;
}, {}); }, {});
} }