From 494a5f2306949c6a5e1de0d29ed4b2c9022b03d9 Mon Sep 17 00:00:00 2001 From: Adrian Flores Cortes Date: Sun, 25 Jan 2026 14:14:19 -0600 Subject: [PATCH] fix: Update finance controllers Co-Authored-By: Claude Opus 4.5 --- .../controllers/accounting.controller.ts | 30 +++++++++++-------- .../finance/controllers/ap.controller.ts | 10 ++++--- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/modules/finance/controllers/accounting.controller.ts b/src/modules/finance/controllers/accounting.controller.ts index 4608a84..1d6a126 100644 --- a/src/modules/finance/controllers/accounting.controller.ts +++ b/src/modules/finance/controllers/accounting.controller.ts @@ -66,7 +66,7 @@ export function createAccountingController(dataSource: DataSource): Router { * GET /accounts/:id * Obtiene una cuenta por ID */ - router.get('/accounts/:id', async (req: Request, res: Response) => { + router.get('/accounts/:id', async (req: Request, res: Response): Promise => { try { const ctx = { tenantId: req.headers['x-tenant-id'] as string, @@ -75,7 +75,8 @@ export function createAccountingController(dataSource: DataSource): Router { const account = await service.findAccountById(ctx, req.params.id); if (!account) { - return res.status(404).json({ error: 'Cuenta no encontrada' }); + res.status(404).json({ error: 'Cuenta no encontrada' }); + return; } res.json(account); @@ -88,7 +89,7 @@ export function createAccountingController(dataSource: DataSource): Router { * GET /accounts/code/:code * Obtiene una cuenta por código */ - router.get('/accounts/code/:code', async (req: Request, res: Response) => { + router.get('/accounts/code/:code', async (req: Request, res: Response): Promise => { try { const ctx = { tenantId: req.headers['x-tenant-id'] as string, @@ -97,7 +98,8 @@ export function createAccountingController(dataSource: DataSource): Router { const account = await service.findAccountByCode(ctx, req.params.code); if (!account) { - return res.status(404).json({ error: 'Cuenta no encontrada' }); + res.status(404).json({ error: 'Cuenta no encontrada' }); + return; } res.json(account); @@ -197,7 +199,7 @@ export function createAccountingController(dataSource: DataSource): Router { * GET /entries/:id * Obtiene una póliza por ID */ - router.get('/entries/:id', async (req: Request, res: Response) => { + router.get('/entries/:id', async (req: Request, res: Response): Promise => { try { const ctx = { tenantId: req.headers['x-tenant-id'] as string, @@ -206,7 +208,8 @@ export function createAccountingController(dataSource: DataSource): Router { const entry = await service.findEntryById(ctx, req.params.id); if (!entry) { - return res.status(404).json({ error: 'Póliza no encontrada' }); + res.status(404).json({ error: 'Póliza no encontrada' }); + return; } res.json(entry); @@ -291,7 +294,7 @@ export function createAccountingController(dataSource: DataSource): Router { * POST /entries/:id/cancel * Cancela una póliza */ - router.post('/entries/:id/cancel', async (req: Request, res: Response) => { + router.post('/entries/:id/cancel', async (req: Request, res: Response): Promise => { try { const ctx = { tenantId: req.headers['x-tenant-id'] as string, @@ -300,7 +303,8 @@ export function createAccountingController(dataSource: DataSource): Router { const { reason } = req.body; if (!reason) { - return res.status(400).json({ error: 'Se requiere motivo de cancelación' }); + res.status(400).json({ error: 'Se requiere motivo de cancelación' }); + return; } const entry = await service.cancelEntry(ctx, req.params.id, reason); @@ -314,7 +318,7 @@ export function createAccountingController(dataSource: DataSource): Router { * POST /entries/:id/reverse * Reversa una póliza */ - router.post('/entries/:id/reverse', async (req: Request, res: Response) => { + router.post('/entries/:id/reverse', async (req: Request, res: Response): Promise => { try { const ctx = { tenantId: req.headers['x-tenant-id'] as string, @@ -323,7 +327,8 @@ export function createAccountingController(dataSource: DataSource): Router { const { reason } = req.body; if (!reason) { - return res.status(400).json({ error: 'Se requiere motivo de reverso' }); + res.status(400).json({ error: 'Se requiere motivo de reverso' }); + return; } const entry = await service.reverseEntry(ctx, req.params.id, reason); @@ -360,7 +365,7 @@ export function createAccountingController(dataSource: DataSource): Router { * GET /reports/account-ledger/:accountId * Obtiene mayor de una cuenta */ - router.get('/reports/account-ledger/:accountId', async (req: Request, res: Response) => { + router.get('/reports/account-ledger/:accountId', async (req: Request, res: Response): Promise => { try { const ctx = { tenantId: req.headers['x-tenant-id'] as string, @@ -371,7 +376,8 @@ export function createAccountingController(dataSource: DataSource): Router { const endDate = new Date(req.query.endDate as string); if (isNaN(startDate.getTime()) || isNaN(endDate.getTime())) { - return res.status(400).json({ error: 'Fechas inválidas' }); + res.status(400).json({ error: 'Fechas inválidas' }); + return; } const result = await service.getAccountLedger(ctx, req.params.accountId, startDate, endDate); diff --git a/src/modules/finance/controllers/ap.controller.ts b/src/modules/finance/controllers/ap.controller.ts index e7356aa..9919dff 100644 --- a/src/modules/finance/controllers/ap.controller.ts +++ b/src/modules/finance/controllers/ap.controller.ts @@ -92,7 +92,7 @@ export function createAPController(dataSource: DataSource): Router { * GET /payment-schedule * Obtiene calendario de pagos */ - router.get('/payment-schedule', async (req: Request, res: Response) => { + router.get('/payment-schedule', async (req: Request, res: Response): Promise => { try { const ctx = { tenantId: req.headers['x-tenant-id'] as string, @@ -103,7 +103,8 @@ export function createAPController(dataSource: DataSource): Router { const endDate = new Date(req.query.endDate as string); if (isNaN(startDate.getTime()) || isNaN(endDate.getTime())) { - return res.status(400).json({ error: 'Fechas inválidas' }); + res.status(400).json({ error: 'Fechas inválidas' }); + return; } const options = { @@ -122,7 +123,7 @@ export function createAPController(dataSource: DataSource): Router { * GET /:id * Obtiene una cuenta por pagar por ID */ - router.get('/:id', async (req: Request, res: Response) => { + router.get('/:id', async (req: Request, res: Response): Promise => { try { const ctx = { tenantId: req.headers['x-tenant-id'] as string, @@ -131,7 +132,8 @@ export function createAPController(dataSource: DataSource): Router { const ap = await service.findById(ctx, req.params.id); if (!ap) { - return res.status(404).json({ error: 'Cuenta por pagar no encontrada' }); + res.status(404).json({ error: 'Cuenta por pagar no encontrada' }); + return; } res.json(ap);