reporte y multa por numero de inventari
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
const moment = require('moment');
|
||||
const validar = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Infraccion = require(`${dbPath}/Infraccion`);
|
||||
const Equipo = require(`${dbPath}/Equipo`);
|
||||
const Multa = require(`${dbPath}/Multa`);
|
||||
const Prestamo = require(`${dbPath}/Prestamo`);
|
||||
const Usuario = require(`${dbPath}/Usuario`);
|
||||
|
||||
const multar = async (body) => {
|
||||
const idInfraccion = validar.validarId(body.idInfraccion);
|
||||
const numeroInventario = validar.validarAlfanumerico(
|
||||
body.numeroInventario,
|
||||
'El numero de inventario',
|
||||
20
|
||||
);
|
||||
const descripcion = validar.validarTexto(
|
||||
body.descripcion,
|
||||
'La descripción',
|
||||
500
|
||||
);
|
||||
let prestamo = {};
|
||||
let fechaFin = moment();
|
||||
|
||||
return Infraccion.findOne({ where: { idInfraccion } })
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe esta infracción.');
|
||||
if (res.gravedad == '1') fechaFin.add(7, 'd');
|
||||
else fechaFin.add(100, 'y');
|
||||
return Prestamo.findOne({
|
||||
where: { activo: true },
|
||||
include: [
|
||||
{ model: Equipo, where: { numeroInventario } },
|
||||
{ model: Usuario },
|
||||
],
|
||||
});
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res)
|
||||
throw new Error('No existe un prestamo activo con este equipo.');
|
||||
prestamo = res;
|
||||
return Multa.findOne({ where: { idPrestamo: prestamo.idPrestamo } });
|
||||
})
|
||||
.then((res) => {
|
||||
if (res)
|
||||
throw new Error('A este prestamo ya se le ha asignado una multa.');
|
||||
return Usuario.update(
|
||||
{ multa: true },
|
||||
{ where: { idUsuario: prestamo.Usuario.idUsuario } }
|
||||
);
|
||||
})
|
||||
.then((res) =>
|
||||
Multa.create({
|
||||
descripcion,
|
||||
idInfraccion,
|
||||
idPrestamo: prestamo.idPrestamo,
|
||||
fechaFin: fechaFin.format(),
|
||||
})
|
||||
)
|
||||
.then((res) => ({ message: `Se multo correctamente al alumno.` }));
|
||||
};
|
||||
|
||||
module.exports = multar;
|
||||
@@ -0,0 +1,41 @@
|
||||
const validar = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Reporte = require(`${dbPath}/Reporte`);
|
||||
const Prestamo = require(`${dbPath}/Prestamo`);
|
||||
const Equipo = require(`${dbPath}/Equipo`);
|
||||
|
||||
const reportar = async (body) => {
|
||||
const numeroInventario = validar.validarAlfanumerico(
|
||||
body.numeroInventario,
|
||||
'El numero de inventario',
|
||||
20
|
||||
);
|
||||
const descripcion = validar.validarTexto(
|
||||
body.descripcion,
|
||||
'La descripción',
|
||||
500
|
||||
);
|
||||
let prestamo = {};
|
||||
|
||||
return Prestamo.findOne({
|
||||
where: { activo: true },
|
||||
include: [{ model: Equipo, where: { numeroInventario } }],
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res)
|
||||
throw new Error('No existe un prestamo activo con este equipo.');
|
||||
prestamo = res;
|
||||
return Reporte.findOne({ where: { idPrestamo: prestamo.idPrestamo } });
|
||||
})
|
||||
.then((res) => {
|
||||
if (res) throw new Error('Ya existe un reporte con este prestamo.');
|
||||
return Reporte.create({
|
||||
descripcion,
|
||||
idPrestamo: prestamo.idPrestamo,
|
||||
idEquipo: prestamo.idEquipo,
|
||||
});
|
||||
})
|
||||
.then((res) => ({ message: 'Se levanto correctamente el reporte.' }));
|
||||
};
|
||||
|
||||
module.exports = reportar;
|
||||
+16
-1
@@ -3,10 +3,11 @@ const app = express();
|
||||
const { verificaToken } = require('../middleware/autentificacion');
|
||||
const route = '/multa';
|
||||
const multar = require('../controller/Multa/multar');
|
||||
const multarNumeroInventario = require('../controller/Multa/multarNumeroInventario');
|
||||
const historialMultas = require('../controller/Multa/historialMultas');
|
||||
|
||||
app.post(
|
||||
`${route}`,
|
||||
`${route}/multar`,
|
||||
//verificaToken,
|
||||
(req, res) => {
|
||||
return multar(req.body)
|
||||
@@ -19,6 +20,20 @@ app.post(
|
||||
}
|
||||
);
|
||||
|
||||
app.post(
|
||||
`${route}/multar_numero_inventario`,
|
||||
//verificaToken,
|
||||
(req, res) => {
|
||||
return multarNumeroInventario(req.body)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
app.get(
|
||||
`${route}/historial_multas`,
|
||||
//verificaToken,
|
||||
|
||||
@@ -4,6 +4,7 @@ const { verificaToken } = require('../middleware/autentificacion');
|
||||
const route = '/reporte';
|
||||
const reportar = require('../controller/Reporte/reportar');
|
||||
const reportarEquipo = require('../controller/Reporte/reportarEquipo');
|
||||
const reportarNumeroInventario = require('../controller/Reporte/reportarNumeroInventario');
|
||||
const historialReportes = require('../controller/Reporte/historialReportes');
|
||||
|
||||
app.post(
|
||||
@@ -34,6 +35,20 @@ app.post(
|
||||
}
|
||||
);
|
||||
|
||||
app.post(
|
||||
`${route}/reportar_numero_inventario`,
|
||||
//verificaToken,
|
||||
(req, res) => {
|
||||
return reportarNumeroInventario(req.body)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
app.get(
|
||||
`${route}/historial_reportes`,
|
||||
//verificaToken,
|
||||
|
||||
Reference in New Issue
Block a user