fix: Update finance controllers
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
61c61e4c2f
commit
494a5f2306
@ -66,7 +66,7 @@ export function createAccountingController(dataSource: DataSource): Router {
|
|||||||
* GET /accounts/:id
|
* GET /accounts/:id
|
||||||
* Obtiene una cuenta por 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<void> => {
|
||||||
try {
|
try {
|
||||||
const ctx = {
|
const ctx = {
|
||||||
tenantId: req.headers['x-tenant-id'] as string,
|
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);
|
const account = await service.findAccountById(ctx, req.params.id);
|
||||||
if (!account) {
|
if (!account) {
|
||||||
return res.status(404).json({ error: 'Cuenta no encontrada' });
|
res.status(404).json({ error: 'Cuenta no encontrada' });
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
res.json(account);
|
res.json(account);
|
||||||
@ -88,7 +89,7 @@ export function createAccountingController(dataSource: DataSource): Router {
|
|||||||
* GET /accounts/code/:code
|
* GET /accounts/code/:code
|
||||||
* Obtiene una cuenta por código
|
* 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<void> => {
|
||||||
try {
|
try {
|
||||||
const ctx = {
|
const ctx = {
|
||||||
tenantId: req.headers['x-tenant-id'] as string,
|
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);
|
const account = await service.findAccountByCode(ctx, req.params.code);
|
||||||
if (!account) {
|
if (!account) {
|
||||||
return res.status(404).json({ error: 'Cuenta no encontrada' });
|
res.status(404).json({ error: 'Cuenta no encontrada' });
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
res.json(account);
|
res.json(account);
|
||||||
@ -197,7 +199,7 @@ export function createAccountingController(dataSource: DataSource): Router {
|
|||||||
* GET /entries/:id
|
* GET /entries/:id
|
||||||
* Obtiene una póliza por 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<void> => {
|
||||||
try {
|
try {
|
||||||
const ctx = {
|
const ctx = {
|
||||||
tenantId: req.headers['x-tenant-id'] as string,
|
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);
|
const entry = await service.findEntryById(ctx, req.params.id);
|
||||||
if (!entry) {
|
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);
|
res.json(entry);
|
||||||
@ -291,7 +294,7 @@ export function createAccountingController(dataSource: DataSource): Router {
|
|||||||
* POST /entries/:id/cancel
|
* POST /entries/:id/cancel
|
||||||
* Cancela una póliza
|
* 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<void> => {
|
||||||
try {
|
try {
|
||||||
const ctx = {
|
const ctx = {
|
||||||
tenantId: req.headers['x-tenant-id'] as string,
|
tenantId: req.headers['x-tenant-id'] as string,
|
||||||
@ -300,7 +303,8 @@ export function createAccountingController(dataSource: DataSource): Router {
|
|||||||
|
|
||||||
const { reason } = req.body;
|
const { reason } = req.body;
|
||||||
if (!reason) {
|
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);
|
const entry = await service.cancelEntry(ctx, req.params.id, reason);
|
||||||
@ -314,7 +318,7 @@ export function createAccountingController(dataSource: DataSource): Router {
|
|||||||
* POST /entries/:id/reverse
|
* POST /entries/:id/reverse
|
||||||
* Reversa una póliza
|
* 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<void> => {
|
||||||
try {
|
try {
|
||||||
const ctx = {
|
const ctx = {
|
||||||
tenantId: req.headers['x-tenant-id'] as string,
|
tenantId: req.headers['x-tenant-id'] as string,
|
||||||
@ -323,7 +327,8 @@ export function createAccountingController(dataSource: DataSource): Router {
|
|||||||
|
|
||||||
const { reason } = req.body;
|
const { reason } = req.body;
|
||||||
if (!reason) {
|
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);
|
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
|
* GET /reports/account-ledger/:accountId
|
||||||
* Obtiene mayor de una cuenta
|
* 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<void> => {
|
||||||
try {
|
try {
|
||||||
const ctx = {
|
const ctx = {
|
||||||
tenantId: req.headers['x-tenant-id'] as string,
|
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);
|
const endDate = new Date(req.query.endDate as string);
|
||||||
|
|
||||||
if (isNaN(startDate.getTime()) || isNaN(endDate.getTime())) {
|
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);
|
const result = await service.getAccountLedger(ctx, req.params.accountId, startDate, endDate);
|
||||||
|
|||||||
@ -92,7 +92,7 @@ export function createAPController(dataSource: DataSource): Router {
|
|||||||
* GET /payment-schedule
|
* GET /payment-schedule
|
||||||
* Obtiene calendario de pagos
|
* Obtiene calendario de pagos
|
||||||
*/
|
*/
|
||||||
router.get('/payment-schedule', async (req: Request, res: Response) => {
|
router.get('/payment-schedule', async (req: Request, res: Response): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const ctx = {
|
const ctx = {
|
||||||
tenantId: req.headers['x-tenant-id'] as string,
|
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);
|
const endDate = new Date(req.query.endDate as string);
|
||||||
|
|
||||||
if (isNaN(startDate.getTime()) || isNaN(endDate.getTime())) {
|
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 = {
|
const options = {
|
||||||
@ -122,7 +123,7 @@ export function createAPController(dataSource: DataSource): Router {
|
|||||||
* GET /:id
|
* GET /:id
|
||||||
* Obtiene una cuenta por pagar por 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<void> => {
|
||||||
try {
|
try {
|
||||||
const ctx = {
|
const ctx = {
|
||||||
tenantId: req.headers['x-tenant-id'] as string,
|
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);
|
const ap = await service.findById(ctx, req.params.id);
|
||||||
if (!ap) {
|
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);
|
res.json(ap);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user