refactor: migrate all tenant services and controllers to pool-based queries
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>
This commit is contained in:
@@ -4,12 +4,12 @@ import { AppError } from '../middlewares/error.middleware.js';
|
||||
|
||||
export async function getIvaMensual(req: Request, res: Response, next: NextFunction) {
|
||||
try {
|
||||
if (!req.tenantSchema) {
|
||||
return next(new AppError(400, 'Schema no configurado'));
|
||||
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.tenantSchema, año);
|
||||
const data = await impuestosService.getIvaMensual(req.tenantPool, año);
|
||||
res.json(data);
|
||||
} catch (error) {
|
||||
next(error);
|
||||
@@ -18,14 +18,14 @@ export async function getIvaMensual(req: Request, res: Response, next: NextFunct
|
||||
|
||||
export async function getResumenIva(req: Request, res: Response, next: NextFunction) {
|
||||
try {
|
||||
if (!req.tenantSchema) {
|
||||
return next(new AppError(400, 'Schema no configurado'));
|
||||
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.tenantSchema, año, mes);
|
||||
const resumen = await impuestosService.getResumenIva(req.tenantPool, año, mes);
|
||||
res.json(resumen);
|
||||
} catch (error) {
|
||||
next(error);
|
||||
@@ -34,12 +34,12 @@ export async function getResumenIva(req: Request, res: Response, next: NextFunct
|
||||
|
||||
export async function getIsrMensual(req: Request, res: Response, next: NextFunction) {
|
||||
try {
|
||||
if (!req.tenantSchema) {
|
||||
return next(new AppError(400, 'Schema no configurado'));
|
||||
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.tenantSchema, año);
|
||||
const data = await impuestosService.getIsrMensual(req.tenantPool, año);
|
||||
res.json(data);
|
||||
} catch (error) {
|
||||
next(error);
|
||||
@@ -48,14 +48,14 @@ export async function getIsrMensual(req: Request, res: Response, next: NextFunct
|
||||
|
||||
export async function getResumenIsr(req: Request, res: Response, next: NextFunction) {
|
||||
try {
|
||||
if (!req.tenantSchema) {
|
||||
return next(new AppError(400, 'Schema no configurado'));
|
||||
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.tenantSchema, año, mes);
|
||||
const resumen = await impuestosService.getResumenIsr(req.tenantPool, año, mes);
|
||||
res.json(resumen);
|
||||
} catch (error) {
|
||||
next(error);
|
||||
|
||||
Reference in New Issue
Block a user