feat: add invoice stats endpoint

This commit is contained in:
Methapon2001 2024-12-20 11:59:55 +07:00
parent 5309581e14
commit abf20e0fb1

View file

@ -40,6 +40,27 @@ const permissionCheck = createPermCheck(globalAllow);
@Route("/api/v1/invoice")
@Tags("Invoice")
export class InvoiceController extends Controller {
@Get("stats")
@OperationId("getInvoiceStats")
@Security("keycloak")
async getInvoiceStats(@Request() req: RequestWithUser, @Query() quotationId?: string) {
const where = {
quotationId,
quotation: {
registeredBranch: {
OR: permissionCondCompany(req.user),
},
},
};
const [pay, notPay] = await prisma.$transaction([
prisma.invoice.count({ where: { ...where, payment: { isNot: null } } }),
prisma.invoice.count({ where: { ...where, payment: null } }),
]);
return { pay, notPay };
}
@Get()
@OperationId("getInvoiceList")
@Security("keycloak")