63 lines
1.8 KiB
TypeScript
63 lines
1.8 KiB
TypeScript
import type { Request, Response, NextFunction } from 'express';
|
|
import * as cfdiService from '../services/cfdi.service.js';
|
|
import { AppError } from '../middlewares/error.middleware.js';
|
|
import type { CfdiFilters } from '@horux/shared';
|
|
|
|
export async function getCfdis(req: Request, res: Response, next: NextFunction) {
|
|
try {
|
|
if (!req.tenantSchema) {
|
|
return next(new AppError(400, 'Schema no configurado'));
|
|
}
|
|
|
|
const filters: CfdiFilters = {
|
|
tipo: req.query.tipo as any,
|
|
estado: req.query.estado as any,
|
|
fechaInicio: req.query.fechaInicio as string,
|
|
fechaFin: req.query.fechaFin as string,
|
|
rfc: req.query.rfc as string,
|
|
search: req.query.search as string,
|
|
page: parseInt(req.query.page as string) || 1,
|
|
limit: parseInt(req.query.limit as string) || 20,
|
|
};
|
|
|
|
const result = await cfdiService.getCfdis(req.tenantSchema, filters);
|
|
res.json(result);
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
}
|
|
|
|
export async function getCfdiById(req: Request, res: Response, next: NextFunction) {
|
|
try {
|
|
if (!req.tenantSchema) {
|
|
return next(new AppError(400, 'Schema no configurado'));
|
|
}
|
|
|
|
const cfdi = await cfdiService.getCfdiById(req.tenantSchema, req.params.id);
|
|
|
|
if (!cfdi) {
|
|
return next(new AppError(404, 'CFDI no encontrado'));
|
|
}
|
|
|
|
res.json(cfdi);
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
}
|
|
|
|
export async function getResumen(req: Request, res: Response, next: NextFunction) {
|
|
try {
|
|
if (!req.tenantSchema) {
|
|
return next(new AppError(400, 'Schema 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 cfdiService.getResumenCfdis(req.tenantSchema, año, mes);
|
|
res.json(resumen);
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
}
|