feat: add quotation stats by group

This commit is contained in:
Methapon Metanipat 2024-10-07 10:19:32 +07:00
parent 474ac86f46
commit bbdf47205b

View file

@ -158,6 +158,26 @@ const permissionCond = createPermCondition(globalAllow);
@Route("/api/v1/quotation")
@Tags("Quotation")
export class QuotationController extends Controller {
@Get("stats")
@Security("keycloak")
async getProductStats(@Request() req: RequestWithUser) {
const result = await prisma.quotation.groupBy({
_count: true,
by: "payCondition",
where: {
customerBranch: {
customer: {
registeredBranch: isSystem(req.user) ? undefined : { OR: permissionCond(req.user) },
},
},
},
});
return result.reduce<Record<string, number>>((a, c) => {
a[c.payCondition] = c._count;
return a;
}, {});
}
@Get()
@Security("keycloak")
async getQuotationList(