endpont status prestamo
This commit is contained in:
@@ -7,20 +7,24 @@ const Status = require('../../db/tablas/Status');
|
||||
const TipoCarrito = require('../../db/tablas/TipoCarrito');
|
||||
|
||||
const get = async (body) => {
|
||||
return Equipo.findAll({
|
||||
const pagina = validar.validarNumero(body.pagina);
|
||||
|
||||
return Equipo.findAndCountAll({
|
||||
include: [
|
||||
{ model: Carrito, include: [{ model: TipoCarrito }, { model: Modulo }] },
|
||||
{ model: Status },
|
||||
{ model: Programa },
|
||||
],
|
||||
limit: 25,
|
||||
offset: 25 * (pagina - 1),
|
||||
}).then((res) => {
|
||||
for (let i = 0; i < res.length; i++) {
|
||||
delete res[i].dataValues.idCarrito;
|
||||
delete res[i].dataValues.idPrograma;
|
||||
delete res[i].dataValues.idStatus;
|
||||
delete res[i].dataValues.Carrito.dataValues.idTipoCarrito;
|
||||
delete res[i].dataValues.Carrito.dataValues.idModulo;
|
||||
if (!res[i].Programa) delete res[i].dataValues.Programa;
|
||||
for (let i = 0; i < res.rows.length; i++) {
|
||||
delete res.rows[i].dataValues.idCarrito;
|
||||
delete res.rows[i].dataValues.idPrograma;
|
||||
delete res.rows[i].dataValues.idStatus;
|
||||
delete res.rows[i].dataValues.Carrito.dataValues.idTipoCarrito;
|
||||
delete res.rows[i].dataValues.Carrito.dataValues.idModulo;
|
||||
if (!res.rows[i].Programa) delete res.rows[i].dataValues.Programa;
|
||||
}
|
||||
return res;
|
||||
});
|
||||
|
||||
@@ -45,8 +45,8 @@ const activos = async (body) => {
|
||||
delete res[i].dataValues.Equipo.dataValues.idPrograma;
|
||||
delete res[i].dataValues.Equipo.dataValues.idStatus;
|
||||
delete res[i].dataValues.Equipo.dataValues.idCarrito;
|
||||
delete res[i].dataValues.Equipo.Carrito.dataValues.idTipoCarrito;
|
||||
delete res[i].dataValues.Equipo.Carrito.dataValues.idModulo;
|
||||
delete res[i].dataValues.Equipo.dataValues.Carrito.dataValues.idTipoCarrito;
|
||||
delete res[i].dataValues.Equipo.dataValues.Carrito.dataValues.idModulo;
|
||||
delete res[i].dataValues.Usuario.dataValues.idTipoUsuario;
|
||||
delete res[i].dataValues.Usuario.dataValues.idCarrera;
|
||||
delete res[i].dataValues.Usuario.dataValues.password;
|
||||
|
||||
@@ -39,8 +39,10 @@ const historial = async (body) => {
|
||||
delete res.rows[i].dataValues.Equipo.dataValues.idPrograma;
|
||||
delete res.rows[i].dataValues.Equipo.dataValues.idStatus;
|
||||
delete res.rows[i].dataValues.Equipo.dataValues.idCarrito;
|
||||
delete res.rows[i].dataValues.Equipo.Carrito.dataValues.idTipoCarrito;
|
||||
delete res.rows[i].dataValues.Equipo.Carrito.dataValues.idModulo;
|
||||
delete res.rows[i].dataValues.Equipo.dataValues.Carrito.dataValues
|
||||
.idTipoCarrito;
|
||||
delete res.rows[i].dataValues.Equipo.dataValues.Carrito.dataValues
|
||||
.idModulo;
|
||||
delete res.rows[i].dataValues.Usuario.dataValues.idTipoUsuario;
|
||||
delete res.rows[i].dataValues.Usuario.dataValues.idCarrera;
|
||||
delete res.rows[i].dataValues.Usuario.dataValues.password;
|
||||
|
||||
@@ -40,8 +40,8 @@ const prestamo = async (body) => {
|
||||
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.dataValues.Carrito.dataValues.idTipoCarrito;
|
||||
delete res.dataValues.Equipo.dataValues.Carrito.dataValues.idModulo;
|
||||
delete res.dataValues.Usuario.dataValues.idTipoUsuario;
|
||||
delete res.dataValues.Usuario.dataValues.idCarrera;
|
||||
delete res.dataValues.Usuario.dataValues.password;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
const moment = require('moment');
|
||||
const validar = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Carrito = require(`${dbPath}/Carrito`);
|
||||
@@ -8,6 +9,7 @@ const Prestamo = require(`${dbPath}/Prestamo`);
|
||||
const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
||||
|
||||
const recoger = async (body) => {
|
||||
const ahora = moment();
|
||||
const idPrestamo = validar.validarId(body.idPrestamo);
|
||||
const idOperadorEntrega = validar.validarId(body.idOperadorEntrega);
|
||||
let idEquipo;
|
||||
@@ -20,12 +22,19 @@ const recoger = async (body) => {
|
||||
include: [{ model: Equipo }],
|
||||
});
|
||||
})
|
||||
.then((res) => {
|
||||
.then(async (res) => {
|
||||
if (!res) throw new Error('No existe este prestamo.');
|
||||
if (!res.activo) throw new Error('Este prestamo ya no esta activo.');
|
||||
if (res.Equipo.enUso)
|
||||
throw new Error('Ya se entrego el equipo al usuario.');
|
||||
idEquipo = res.Equipo.idEquipo;
|
||||
if (!res.activo) throw new Error('Este prestamo ya no esta activo.');
|
||||
else if (res.Equipo.enUso)
|
||||
throw new Error('Ya se entrego el equipo al usuario.');
|
||||
else if (moment(res.horaInicio) < ahora) {
|
||||
await Equipo.update({ apartado: false }, { where: { idEquipo } });
|
||||
await Prestamo.update({ activo: false }, { where: idPrestamo });
|
||||
throw new Error(
|
||||
'Ya paso el tiempo limite para recoger el dispositivo.'
|
||||
);
|
||||
}
|
||||
return Equipo.update({ enUso: true }, { where: { idEquipo } });
|
||||
})
|
||||
.then((res) => {
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
const moment = require('moment');
|
||||
const validar = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Equipo = require(`${dbPath}/Equipo`);
|
||||
const Prestamo = require(`${dbPath}/Prestamo`);
|
||||
|
||||
const status = async (body) => {
|
||||
const ahora = moment();
|
||||
const idPrestamo = validar.validarId(body.idPrestamo);
|
||||
let idEquipo;
|
||||
|
||||
return Prestamo.findOne({
|
||||
where: { idPrestamo },
|
||||
include: [{ model: Equipo }],
|
||||
}).then(async (res) => {
|
||||
if (!res) throw new Error('No existe este prestamo.');
|
||||
idEquipo = res.Equipo.idEquipo;
|
||||
delete res.dataValues.idUsuario;
|
||||
delete res.dataValues.idEquipo;
|
||||
delete res.dataValues.idOperadorRegreso;
|
||||
delete res.dataValues.idOperadorEntrega;
|
||||
delete res.dataValues.Equipo.dataValues.idCarrito;
|
||||
delete res.dataValues.Equipo.dataValues.idStatus;
|
||||
delete res.dataValues.Equipo.dataValues.idPrograma;
|
||||
if (!res.activo) {
|
||||
if (!res.horaEntrega)
|
||||
return {
|
||||
message: 'Este prestamo fue cancelado.',
|
||||
prestamo: res,
|
||||
};
|
||||
return {
|
||||
message: 'Este prestamo no es encuentra activo.',
|
||||
prestamo: res,
|
||||
};
|
||||
} else if (res.Equipo.enUso)
|
||||
return {
|
||||
message: 'El equipo ya fue entregado al usuario.',
|
||||
prestamo: res,
|
||||
};
|
||||
else if (moment(res.horaInicio) < ahora) {
|
||||
await Equipo.update({ apartado: false }, { where: { idEquipo } });
|
||||
await Prestamo.update({ activo: false }, { where: idPrestamo });
|
||||
return {
|
||||
message: 'Ya paso el tiempo limite para recoger el dispositivo.',
|
||||
prestamo: res,
|
||||
};
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = status;
|
||||
@@ -4,14 +4,18 @@ const Carrera = require('../../db/tablas/Carrera');
|
||||
const TipoUsuario = require('../../db/tablas/TipoUsuario');
|
||||
|
||||
const get = async (body) => {
|
||||
return Usuario.findAll({
|
||||
const pagina = validar.validarNumero(body.pagina);
|
||||
|
||||
return Usuario.findAndCountAll({
|
||||
include: [{ model: TipoUsuario }, { model: Carrera }],
|
||||
limit: 25,
|
||||
offset: 25 * (pagina - 1),
|
||||
}).then((res) => {
|
||||
for (let i = 0; i < res.length; i++) {
|
||||
delete res[i].dataValues.password;
|
||||
delete res[i].dataValues.idTipoUsuario;
|
||||
delete res[i].dataValues.idCarrera;
|
||||
if (!res[i].Carrera) delete res[i].dataValues.Carrera;
|
||||
for (let i = 0; i < res.rows.length; i++) {
|
||||
delete res.rows[i].dataValues.password;
|
||||
delete res.rows[i].dataValues.idTipoUsuario;
|
||||
delete res.rows[i].dataValues.idCarrera;
|
||||
if (!res.rows[i].Carrera) delete res.rows[i].dataValues.Carrera;
|
||||
}
|
||||
return res;
|
||||
});
|
||||
|
||||
@@ -13,6 +13,7 @@ const regresar = require(`${controllerPath}/regresar`);
|
||||
const prestamo = require(`${controllerPath}/prestamo`);
|
||||
const prestamoUsuario = require(`${controllerPath}/prestamoUsuario`);
|
||||
const cancelar = require(`${controllerPath}/cancelar`);
|
||||
const status = require(`${controllerPath}/status`);
|
||||
|
||||
app.post(
|
||||
`${route}/pedir`,
|
||||
@@ -154,4 +155,18 @@ app.get(
|
||||
}
|
||||
);
|
||||
|
||||
app.get(
|
||||
`${route}/status`,
|
||||
// verificaToken,
|
||||
(req, res) => {
|
||||
return status(req.query)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
module.exports = app;
|
||||
|
||||
Reference in New Issue
Block a user