historial y activos perfecionado

This commit is contained in:
xXpuma99Xx
2022-02-13 19:10:21 -06:00
parent 8429cd74e3
commit e285fe893d
11 changed files with 34 additions and 36 deletions
-4
View File
@@ -16,10 +16,6 @@ app.use(
})
);
io.on('connect', () => {
console.log('hola');
});
app.use(bodyParser.json());
app.get('/', (req, res) => res.send('API Pcpuma'));
+1 -1
View File
@@ -11,7 +11,7 @@ const update = async (body) => {
);
const idTipoCarrito = body.idTipoCarrito
? validar.validarNumeroEntero(body.idTipoCarrito, 'id tipo carrito', true)
: null;
: '';
let update = {};
return TipoCarrito.findOne({ where: { idTipoCarrito } })
+3 -3
View File
@@ -13,13 +13,13 @@ const update = async (body) => {
);
const idStatus = body.idStatus
? validar.validarNumeroEntero(body.idStatus, 'id status', true)
: null;
: '';
const idCarrito = body.idCarrito
? validar.validarNumeroEntero(body.idCarrito, 'id carrito', true)
: null;
: '';
const idPrograma = body.idPrograma
? validar.validarNumeroEntero(body.idPrograma, 'id programa', true)
: null;
: '';
let update = {};
return Status.findOne({ where: { idStatus } })
+12 -11
View File
@@ -20,10 +20,10 @@ const activos = async (body) => {
);
const idPrestamo = body.idPrestamo
? validar.validarNumeroEntero(body.idPrestamo, 'id préstamo', true)
: null;
: '';
const idTipoCarrito = body.idTipoCarrito
? validar.validarNumeroEntero(body.idTipoCarrito, 'id tipo carrito', true)
: null;
: '';
const usuario = body.usuario ? validar.validarNumeroCuenta(body.usuario) : '';
const numeroInventario = body.numeroInventario
? validar.validarAlfanumerico(
@@ -33,21 +33,22 @@ const activos = async (body) => {
20
)
: '';
let wherePrestamo = {
[Op.or]: [
{ activo: true },
{
[Op.and]: [{ regresoInmediato: true }, { idOperadorRegreso: null }],
},
],
};
let whereCarrito = [{ idModulo }];
if (idTipoCarrito) whereCarrito.push({ idTipoCarrito });
if (idPrestamo) wherePrestamo.idPrestamo = { [Op.like]: `%${idPrestamo}%` };
return Modulo.findOne({ where: { idModulo } }).then((res) => {
if (!res) throw new Error('No existe este módulo.');
return Prestamo.findAndCountAll({
where: {
[Op.or]: [
{ activo: true },
{
[Op.and]: [{ regresoInmediato: true }, { idOperadorRegreso: null }],
},
{ idPrestamo: { [Op.like]: `%${idPrestamo}%` } },
],
},
where: wherePrestamo,
include: [
{
model: Equipo,
+3 -3
View File
@@ -16,7 +16,7 @@ const historial = async (body) => {
const usuario = body.usuario ? validar.validarNumeroCuenta(body.usuario) : '';
const idPrestamo = body.idPrestamo
? validar.validarNumeroEntero(body.idPrestamo, 'id préstamo', true)
: null;
: '';
const numeroInventario = body.numeroInventario
? validar.validarAlfanumerico(
body.numeroInventario,
@@ -27,10 +27,10 @@ const historial = async (body) => {
: '';
const idModulo = body.idModulo
? validar.validarNumeroEntero(body.idModulo, 'id módulo', true)
: null;
: '';
const idTipoCarrito = body.idTipoCarrito
? validar.validarNumeroEntero(body.idTipoCarrito, 'id tipo carrito', true)
: null;
: '';
let whereCarrito = [];
if (idTipoCarrito) whereCarrito.push({ idTipoCarrito });
+4 -5
View File
@@ -23,10 +23,11 @@ const pedir = async (body) => {
);
const idPrograma = body.idPrograma
? validarNumeroEntero(body.idPrograma, 'id programa', true)
: null;
: '';
const idModulo = idPrograma
? 1
: validarNumeroEntero(body.idModulo, 'id modulo', true);
let whereEquipo = { idStatus: 4 };
let idEquipo;
// if (ahora > horaMax)
@@ -44,6 +45,7 @@ const pedir = async (body) => {
})
.then((res) => {
if (!res && idPrograma) throw new Error('No existe este programa.');
if (idPrograma) whereEquipo.idPrograma = idPrograma;
return Usuario.findOne({ where: { idUsuario } });
})
.then((res) => {
@@ -79,10 +81,7 @@ const pedir = async (body) => {
);
}
return Equipo.findOne({
where: {
idStatus: 4,
idPrograma,
},
where: whereEquipo,
include: [
{
model: Carrito,
+2
View File
@@ -7,6 +7,7 @@ const Modulo = require(`${dbPath}/Modulo`);
const Operador = require(`${dbPath}/Operador`);
const Prestamo = require(`${dbPath}/Prestamo`);
const Programa = require(`${dbPath}/Programa`);
const Status = require(`${dbPath}/Status`);
const TipoCarrito = require(`${dbPath}/TipoCarrito`);
const TipoUsuario = require(`${dbPath}/TipoUsuario`);
const Usuario = require(`${dbPath}/Usuario`);
@@ -26,6 +27,7 @@ const prestamo = async (body) => {
attributes: ['idCarrito', 'carrito'],
},
{ model: Programa },
{ model: Status },
],
attributes: ['idEquipo', 'numeroSerie', 'numeroInventario', 'equipo'],
},
+6 -6
View File
@@ -21,13 +21,13 @@ const reporte = async (body) => {
const fin = validar.validarFecha(body.fin, 'fecha fin', false);
const idCarrera = body.idCarrera
? validar.validarNumeroEntero(body.idCarrera, 'id carrera', true)
: null;
: '';
const idTipoUsuario = body.idTipoUsuario
? validar.validarNumeroEntero(body.idTipoUsuario, 'id tipo usuario', true)
: null;
: '';
const idTipoCarrito = body.idTipoCarrito
? validar.validarNumeroEntero(body.idTipoCarrito, 'id tipo carrito', true)
: null;
: '';
const path = `server/uploads/reporte.csv`;
const data = [];
@@ -106,7 +106,7 @@ const reporte = async (body) => {
equipo: res[i].Equipo.equipo,
programa: res[i].Equipo.Programa
? res[i].Equipo.Programa.programa
: null,
: '',
carrito: res[i].Equipo.Carrito.carrito,
modulo: res[i].Equipo.Carrito.Modulo.modulo,
tipoCarrito: res[i].Equipo.Carrito.TipoCarrito.tipoCarrito,
@@ -116,10 +116,10 @@ const reporte = async (body) => {
carrera: res[i].Usuario.Carrera.carrera,
operadorEntrega: res[i].OperadorEntrega
? res[i].OperadorEntrega.operador
: null,
: '',
operadorRegreso: res[i].OperadorRegreso
? res[i].OperadorRegreso.operador
: null,
: '',
});
}
await helper.eliminarArchivo(path).catch((err) => {});
+1 -2
View File
@@ -1,6 +1,5 @@
const { Op } = require('sequelize');
const Status = require('../../db/tablas/Status');
const get = async () => Status.findAll({ where: { idStatus: { [Op.gt]: 3 } } });
const get = async () => Status.findAll();
module.exports = get;
+1 -1
View File
@@ -13,7 +13,7 @@ const usuarios = async (body) => {
: '';
const idTipoUsuario = body.idTipoUsuario
? validar.validarNumeroEntero(body.idTipoUsuario, 'id tipo usuario', true)
: null;
: '';
return Usuario.findAndCountAll({
where: {
+1
View File
@@ -87,6 +87,7 @@ app.put(
);
app.put(`${route}/cancelar_usuario`, verificaToken, (req, res) => {
req.body.idUsuario = req.decoded.data.idUsuario;
return cancelarUsuario(req.body)
.then((data) => {
res.status(200).json(data);