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>
53 lines
1.6 KiB
TypeScript
53 lines
1.6 KiB
TypeScript
import type { Request, Response, NextFunction } from 'express';
|
|
import * as calendarioService from '../services/calendario.service.js';
|
|
|
|
export async function getEventos(req: Request, res: Response, next: NextFunction) {
|
|
try {
|
|
const { año, mes } = req.query;
|
|
const añoNum = parseInt(año as string) || new Date().getFullYear();
|
|
const mesNum = mes ? parseInt(mes as string) : undefined;
|
|
|
|
const eventos = await calendarioService.getEventos(req.tenantPool!, añoNum, mesNum);
|
|
res.json(eventos);
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
}
|
|
|
|
export async function getProximos(req: Request, res: Response, next: NextFunction) {
|
|
try {
|
|
const dias = parseInt(req.query.dias as string) || 30;
|
|
const eventos = await calendarioService.getProximosEventos(req.tenantPool!, dias);
|
|
res.json(eventos);
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
}
|
|
|
|
export async function createEvento(req: Request, res: Response, next: NextFunction) {
|
|
try {
|
|
const evento = await calendarioService.createEvento(req.tenantPool!, req.body);
|
|
res.status(201).json(evento);
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
}
|
|
|
|
export async function updateEvento(req: Request, res: Response, next: NextFunction) {
|
|
try {
|
|
const evento = await calendarioService.updateEvento(req.tenantPool!, parseInt(String(req.params.id)), req.body);
|
|
res.json(evento);
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
}
|
|
|
|
export async function deleteEvento(req: Request, res: Response, next: NextFunction) {
|
|
try {
|
|
await calendarioService.deleteEvento(req.tenantPool!, parseInt(String(req.params.id)));
|
|
res.status(204).send();
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
}
|