Replace Prisma raw queries with pg.Pool for all tenant-scoped services: cfdi, dashboard, impuestos, alertas, calendario, reportes, export, and SAT. Controllers now pass req.tenantPool instead of req.tenantSchema. Fixes SQL injection in calendario.service.ts (parameterized interval). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
64 lines
2.0 KiB
TypeScript
64 lines
2.0 KiB
TypeScript
import type { Request, Response, NextFunction } from 'express';
|
|
import * as impuestosService from '../services/impuestos.service.js';
|
|
import { AppError } from '../middlewares/error.middleware.js';
|
|
|
|
export async function getIvaMensual(req: Request, res: Response, next: NextFunction) {
|
|
try {
|
|
if (!req.tenantPool) {
|
|
return next(new AppError(400, 'Tenant no configurado'));
|
|
}
|
|
|
|
const año = parseInt(req.query.año as string) || new Date().getFullYear();
|
|
const data = await impuestosService.getIvaMensual(req.tenantPool, año);
|
|
res.json(data);
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
}
|
|
|
|
export async function getResumenIva(req: Request, res: Response, next: NextFunction) {
|
|
try {
|
|
if (!req.tenantPool) {
|
|
return next(new AppError(400, 'Tenant no configurado'));
|
|
}
|
|
|
|
const año = parseInt(req.query.año as string) || new Date().getFullYear();
|
|
const mes = parseInt(req.query.mes as string) || new Date().getMonth() + 1;
|
|
|
|
const resumen = await impuestosService.getResumenIva(req.tenantPool, año, mes);
|
|
res.json(resumen);
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
}
|
|
|
|
export async function getIsrMensual(req: Request, res: Response, next: NextFunction) {
|
|
try {
|
|
if (!req.tenantPool) {
|
|
return next(new AppError(400, 'Tenant no configurado'));
|
|
}
|
|
|
|
const año = parseInt(req.query.año as string) || new Date().getFullYear();
|
|
const data = await impuestosService.getIsrMensual(req.tenantPool, año);
|
|
res.json(data);
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
}
|
|
|
|
export async function getResumenIsr(req: Request, res: Response, next: NextFunction) {
|
|
try {
|
|
if (!req.tenantPool) {
|
|
return next(new AppError(400, 'Tenant no configurado'));
|
|
}
|
|
|
|
const año = parseInt(req.query.año as string) || new Date().getFullYear();
|
|
const mes = parseInt(req.query.mes as string) || new Date().getMonth() + 1;
|
|
|
|
const resumen = await impuestosService.getResumenIsr(req.tenantPool, año, mes);
|
|
res.json(resumen);
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
}
|