Skip to content
Snippets Groups Projects
AuditorController.ts 1.17 KiB
Newer Older
Renzo Beux's avatar
Renzo Beux committed
import {
  Request, Response, Router,
} from 'express';
import Auditor from '../Services/AuditorService';
Renzo Beux's avatar
Renzo Beux committed
import { logAndRespond } from './Utils';
Renzo Beux's avatar
Renzo Beux committed

const router = Router();

const auditGet = async (req: Request, res: Response) => {
Agustin Ruiz Diaz Cambon's avatar
Agustin Ruiz Diaz Cambon committed
  try {
Renzo Beux's avatar
Renzo Beux committed
    const token = req.headers.authorization;
    const { filters } = req.body;
    const audits = await
    Auditor.getAudit(Number(req.body.cant), Number(req.body.page), token, filters as string[]);
Renzo Beux's avatar
Renzo Beux committed
    return logAndRespond(res, 200, 'send', audits, 'info', null, null);
Agustin Ruiz Diaz Cambon's avatar
Agustin Ruiz Diaz Cambon committed
  } catch (error) {
    const e = error as Error;
Renzo Beux's avatar
Renzo Beux committed
    return logAndRespond(res, 400, 'json', { error: e.message }, 'info', null, null);
Agustin Ruiz Diaz Cambon's avatar
Agustin Ruiz Diaz Cambon committed
  }
Renzo Beux's avatar
Renzo Beux committed
};

const calculationAuditGet = async (req: Request, res: Response) => {
  try {
    const audits = await
    Auditor.getCalculationsAudit(req.body.userIds, req.body.dateFrom, req.body.dateTo);
    return logAndRespond(res, 200, 'send', audits, 'info', null, null);
  } catch (error) {
    const e = error as Error;
    return logAndRespond(res, 400, 'json', { error: e.message }, 'info', null, null);
  }
};

router.post('/', auditGet);
router.post('/calculations', calculationAuditGet);
Renzo Beux's avatar
Renzo Beux committed

export default router;