From abf20e0fb1dff6f4ec1387c9d17b306fe44e8e82 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Fri, 20 Dec 2024 11:59:55 +0700 Subject: [PATCH] feat: add invoice stats endpoint --- src/controllers/04-invoice-controller.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/controllers/04-invoice-controller.ts b/src/controllers/04-invoice-controller.ts index b4a4753..2338a97 100644 --- a/src/controllers/04-invoice-controller.ts +++ b/src/controllers/04-invoice-controller.ts @@ -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")