update equipo
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
const validar = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Carrito = require(`${dbPath}/Carrito`);
|
||||
const Modulo = require(`${dbPath}/Modulo`);
|
||||
const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
||||
|
||||
const equiposCarrito = async (body) => {};
|
||||
|
||||
module.exports = equiposCarrito;
|
||||
@@ -3,6 +3,20 @@ const dbPath = '../../db/tablas';
|
||||
const Equipo = require(`${dbPath}/Equipo`);
|
||||
const Status = require(`${dbPath}/Status`);
|
||||
|
||||
const update = async (body) => {};
|
||||
const update = async (body) => {
|
||||
const idEquipo = validar.validarId(body.idEquipo);
|
||||
const idStatus = validar.validarId(body.idStatus);
|
||||
|
||||
return Equipo.findOne({ where: { idEquipo } })
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe este equipo.');
|
||||
return Status.findOne({ where: { idStatus } });
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe este status.');
|
||||
return Equipo.update({ idStatus }, { where: { idEquipo } });
|
||||
})
|
||||
.then((res) => ({ message: 'Se actualizó correctamente el equipo.' }));
|
||||
};
|
||||
|
||||
module.exports = update;
|
||||
|
||||
@@ -5,39 +5,44 @@ const Equipo = require(`${dbPath}/Equipo`);
|
||||
const Modulo = require(`${dbPath}/Modulo`);
|
||||
const Prestamo = require(`${dbPath}/Prestamo`);
|
||||
const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
||||
const Usuario = require(`${dbPath}/Usuario`);
|
||||
|
||||
const prestamo = async (body) => {
|
||||
const idUsuario = validarId(body.idUsuario);
|
||||
|
||||
return Prestamo.findOne({
|
||||
where: { idUsuario, activo: true },
|
||||
include: [
|
||||
{
|
||||
model: Equipo,
|
||||
return Usuario.findOne({ where: { idUsuario } })
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe este usuario.');
|
||||
|
||||
return Prestamo.findOne({
|
||||
where: { idUsuario, activo: true },
|
||||
include: [
|
||||
{
|
||||
model: Carrito,
|
||||
include: [{ model: TipoCarrito }, { model: Modulo }],
|
||||
model: Equipo,
|
||||
include: [
|
||||
{
|
||||
model: Carrito,
|
||||
include: [{ model: TipoCarrito }, { model: Modulo }],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
}).then((res) => {
|
||||
if (!res) throw new Error('Este usuario no tiene un prestamo activo.');
|
||||
delete res.dataValues.idUsuario;
|
||||
delete res.dataValues.idOperadorEntrega;
|
||||
delete res.dataValues.idOperadorRegreso;
|
||||
delete res.dataValues.idEquipo;
|
||||
delete res.dataValues.Equipo.dataValues.idPrograma;
|
||||
delete res.dataValues.Equipo.dataValues.idStatus;
|
||||
delete res.dataValues.Equipo.dataValues.idCarrito;
|
||||
delete res.dataValues.Equipo.Carrito.dataValues.idTipoCarrito;
|
||||
delete res.dataValues.Equipo.Carrito.dataValues.idModulo;
|
||||
// delete res.dataValues.Usuario.dataValues.idTipoUsuario;
|
||||
// delete res.dataValues.Usuario.dataValues.idCarrera;
|
||||
// delete res.dataValues.Usuario.dataValues.password;
|
||||
return res;
|
||||
});
|
||||
});
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('Este usuario no tiene un prestamo activo.');
|
||||
delete res.dataValues.idUsuario;
|
||||
delete res.dataValues.idOperadorEntrega;
|
||||
delete res.dataValues.idOperadorRegreso;
|
||||
delete res.dataValues.idEquipo;
|
||||
delete res.dataValues.Equipo.dataValues.idPrograma;
|
||||
delete res.dataValues.Equipo.dataValues.idStatus;
|
||||
delete res.dataValues.Equipo.dataValues.idCarrito;
|
||||
delete res.dataValues.Equipo.Carrito.dataValues.idTipoCarrito;
|
||||
delete res.dataValues.Equipo.Carrito.dataValues.idModulo;
|
||||
delete res.dataValues.Equipo.Carrito.dataValues.activo;
|
||||
return res;
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = prestamo;
|
||||
|
||||
@@ -32,12 +32,19 @@ const status = async (body) => {
|
||||
message: 'Este prestamo no es encuentra activo.',
|
||||
prestamo: res,
|
||||
};
|
||||
} else if (res.Equipo.enUso)
|
||||
} else if (res.Equipo.enUso) {
|
||||
if (moment(res.horaFin) < ahora) {
|
||||
return {
|
||||
message:
|
||||
'Ya paso la hora de entrega. El usuario puede ser acreedor a una multa por el retraso.',
|
||||
prestamo: res,
|
||||
};
|
||||
}
|
||||
return {
|
||||
message: 'El equipo ya fue entregado al usuario.',
|
||||
prestamo: res,
|
||||
};
|
||||
else if (moment(res.horaInicio) < ahora) {
|
||||
} else if (moment(res.horaInicio) < ahora) {
|
||||
await Equipo.update({ apartado: false }, { where: { idEquipo } });
|
||||
await Prestamo.update({ activo: false }, { where: { idPrestamo } });
|
||||
return {
|
||||
|
||||
+14
-10
@@ -8,17 +8,9 @@ const controllerPath = '../controller/Equipo';
|
||||
const cargaMasiva = require(`${controllerPath}/cargaMasiva`);
|
||||
const equipo = require(`${controllerPath}/equipo`);
|
||||
const equipos = require(`${controllerPath}/equipos`);
|
||||
const update = require(`${controllerPath}/update`);
|
||||
|
||||
// app.post(`${route}/`, (req, res) => {
|
||||
// return login(req.body)
|
||||
// .then((data) => {
|
||||
// res.status(200).json(data);
|
||||
// })
|
||||
// .catch((err) => {
|
||||
// res.status(400).json({ message: err.message });
|
||||
// });
|
||||
// });
|
||||
|
||||
// POST
|
||||
app.post(
|
||||
`${route}/carga_masiva`,
|
||||
// verificaToken,
|
||||
@@ -39,6 +31,18 @@ app.post(
|
||||
}
|
||||
);
|
||||
|
||||
// PUT
|
||||
app.put(`${route}/update`, (req, res) => {
|
||||
return update(req.body)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
//GET
|
||||
app.get(`${route}/`, (req, res) => {
|
||||
return equipo(req.query)
|
||||
.then((data) => {
|
||||
|
||||
Reference in New Issue
Block a user