reportes
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
const moment = require('moment');
|
||||
const Infraccion = require('../../db/tablas/Infraccion');
|
||||
const { validarId, validarTexto } = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Infraccion = require(`${dbPath}/Infraccion`);
|
||||
const Prestamo = require(`${dbPath}/Prestamo`);
|
||||
const Usuario = require(`${dbPath}/Usuario`);
|
||||
const Multa = require(`${dbPath}/Multa`);
|
||||
@@ -10,13 +10,14 @@ const multar = async (body) => {
|
||||
const idInfraccion = validarId(body.idInfraccion);
|
||||
const idPrestamo = validarId(body.idPrestamo);
|
||||
const descripcion = validarTexto(body.descripcion, 'La descripción', 500);
|
||||
let infraccion = {};
|
||||
let prestamo = {};
|
||||
let fechaFin = moment();
|
||||
|
||||
return Infraccion.findOne({ where: { idInfraccion } })
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe esta infracción.');
|
||||
infraccion = res;
|
||||
if (res.gravedad == '1') fechaFin.add(7, 'd');
|
||||
else fechaFin.add(100, 'y');
|
||||
return Prestamo.findOne({
|
||||
where: { idPrestamo },
|
||||
include: [{ model: Usuario }],
|
||||
@@ -24,22 +25,25 @@ const multar = async (body) => {
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe este prestamo.');
|
||||
console.log(res.dataValues);
|
||||
return Usuario.update(
|
||||
{ multa: true },
|
||||
{ where: { idUsuario: res.Usuario.idUsuario } }
|
||||
);
|
||||
prestamo = res;
|
||||
return Multa.findOne({ where: { idPrestamo } });
|
||||
})
|
||||
.then((res) => {
|
||||
if (infraccion.gravedad === '1') fechaFin.add(7, 'd');
|
||||
else fechaFin.add(100, 'y');
|
||||
return Multa.create({
|
||||
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,
|
||||
fechaFin: fechaFin.format(),
|
||||
});
|
||||
})
|
||||
})
|
||||
)
|
||||
.then((res) => ({ message: `Se multo correctamente al alumno.` }));
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
const { validarId, validarTexto } = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Reporte = require(`${dbPath}/Reporte`);
|
||||
const Prestamo = require(`${dbPath}/Prestamo`);
|
||||
|
||||
const reportar = async (body) => {
|
||||
const idPrestamo = validarId(body.idPrestamo);
|
||||
const descripcion = validarTexto(body.descripcion, 'La descripción', 500);
|
||||
|
||||
return Prestamo.findOne({ where: { idPrestamo } })
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe este prestamo.');
|
||||
return Reporte.findOne({ where: { idPrestamo } });
|
||||
})
|
||||
.then((res) => {
|
||||
if (res) throw new Error('Ya existe un reporte con este prestamo.');
|
||||
return Reporte.create({ descripcion, idPrestamo });
|
||||
})
|
||||
.then((res) => ({ message: 'Se levanto correctamente el reporte.' }));
|
||||
};
|
||||
|
||||
module.exports = reportar;
|
||||
@@ -0,0 +1,19 @@
|
||||
const { validarId, validarTexto } = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Reporte = require(`${dbPath}/Reporte`);
|
||||
const Equipo = require(`${dbPath}/Equipo`);
|
||||
|
||||
const reportar = async (body) => {
|
||||
console.log(body);
|
||||
const idEquipo = validarId(body.idEquipo);
|
||||
const descripcion = validarTexto(body.descripcion, 'La descripción', 500);
|
||||
|
||||
return Equipo.findOne({ where: { idEquipo } })
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe este equipo.');
|
||||
return Reporte.create({ descripcion, idEquipo });
|
||||
})
|
||||
.then((res) => ({ message: 'Se levanto correctamente el reporte.' }));
|
||||
};
|
||||
|
||||
module.exports = reportar;
|
||||
+30
-15
@@ -1,21 +1,36 @@
|
||||
const express = require('express');
|
||||
const app = express();
|
||||
const { verificaToken } = require('../middleware/autentificacion');
|
||||
const route = '/status';
|
||||
// const get = require('../controller/Status/get');
|
||||
const route = '/reporte';
|
||||
const reportar = require('../controller/Reporte/reportar');
|
||||
const reportarEquipo = require('../controller/Reporte/reportarEquipo');
|
||||
|
||||
// app.get(
|
||||
// `${route}`,
|
||||
// //verificaToken,
|
||||
// (req, res) => {
|
||||
// return get()
|
||||
// .then((data) => {
|
||||
// res.status(200).json(data);
|
||||
// })
|
||||
// .catch((err) => {
|
||||
// res.status(400).json({ message: err.message });
|
||||
// });
|
||||
// }
|
||||
// );
|
||||
app.post(
|
||||
`${route}/reportar`,
|
||||
//verificaToken,
|
||||
(req, res) => {
|
||||
return reportar(req.body)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
app.post(
|
||||
`${route}/reportar_equipo`,
|
||||
//verificaToken,
|
||||
(req, res) => {
|
||||
return reportarEquipo(req.body)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
module.exports = app;
|
||||
|
||||
@@ -9,7 +9,7 @@ app.use(require('./Multa'));
|
||||
app.use(require('./Operador'));
|
||||
app.use(require('./Prestamo'));
|
||||
app.use(require('./Programa'));
|
||||
// app.use(require('./Reporte'));
|
||||
app.use(require('./Reporte'));
|
||||
app.use(require('./Status'));
|
||||
app.use(require('./TipoCarrito'));
|
||||
app.use(require('./Usuario'));
|
||||
|
||||
Reference in New Issue
Block a user