From 25d21120105ca6296a444eeff54ba81b47ed9c2f Mon Sep 17 00:00:00 2001 From: xXpuma99Xx <51341582+xXpuma99Xx@users.noreply.github.com> Date: Sun, 13 Feb 2022 13:34:54 -0600 Subject: [PATCH] mini cambios --- server/controller/Carrito/update.js | 9 ++-- server/controller/Equipo/update.js | 2 +- .../controller/Multa/historialMultasEquipo.js | 12 +---- .../Multa/historialMultasUsuario.js | 48 ++++++++----------- server/controller/Operador/crear.js | 2 +- server/controller/Prestamo/historial.js | 2 +- server/controller/Prestamo/reporte.js | 10 ++-- server/controller/Usuario/crear.js | 1 - server/controller/Usuario/login.js | 4 +- server/controller/Usuario/quitarMulta.js | 2 +- server/controller/Usuario/usuarios.js | 11 +---- 11 files changed, 38 insertions(+), 65 deletions(-) diff --git a/server/controller/Carrito/update.js b/server/controller/Carrito/update.js index 1b248b7..0ca3598 100644 --- a/server/controller/Carrito/update.js +++ b/server/controller/Carrito/update.js @@ -16,17 +16,18 @@ const update = async (body) => { return TipoCarrito.findOne({ where: { idTipoCarrito } }) .then((res) => { - if (idTipoCarrito && !res) - throw new Error('No existe este tipo carrito.'); + if (idTipoCarrito) { + if (!res) throw new Error('No existe este tipo carrito.'); + update.idTipoCarrito = idTipoCarrito; + } return Carrito.findOne({ where: { idCarrito } }); }) .then((res) => { if (!res) throw new Error('No existe este carrito.'); - if (idTipoCarrito) update.idTipoCarrito = idTipoCarrito; if (body.activo === 'desactivar') update.activo = false; else if (body.activo === 'activar') update.activo = true; if (validar.validarObjetoVacio(update)) - throw new Error('No se envio nada para actualizar.'); + throw new Error('No se envió nada para actualizar.'); return Carrito.update(update, { where: { idCarrito } }); }) .then(() => ({ message: 'Se actualizó correctamente el carrito.' })); diff --git a/server/controller/Equipo/update.js b/server/controller/Equipo/update.js index e9ef8fa..f570870 100644 --- a/server/controller/Equipo/update.js +++ b/server/controller/Equipo/update.js @@ -43,7 +43,7 @@ const update = async (body) => { update.idPrograma = idPrograma; } if (validar.validarObjetoVacio(update)) - throw new Error('No se envio nada para actualizar.'); + throw new Error('No se envió nada para actualizar.'); return Equipo.findOne({ where: { idEquipo } }); }) .then((res) => { diff --git a/server/controller/Multa/historialMultasEquipo.js b/server/controller/Multa/historialMultasEquipo.js index a7d8eaf..d718adc 100644 --- a/server/controller/Multa/historialMultasEquipo.js +++ b/server/controller/Multa/historialMultasEquipo.js @@ -13,17 +13,7 @@ const historialMultasEquipo = async (body) => { { model: Prestamo, where: { idEquipo }, - attributes: [ - 'idPrestamo', - 'activo', - 'horaMaxRecoger', - 'horaInicio', - 'horaFin', - 'horaEntrega', - 'canceladoUsuario', - 'regresoInmediato', - 'createdAt', - ], + attributes: ['idPrestamo'], }, { model: Operador, diff --git a/server/controller/Multa/historialMultasUsuario.js b/server/controller/Multa/historialMultasUsuario.js index d3c733d..2e1d366 100644 --- a/server/controller/Multa/historialMultasUsuario.js +++ b/server/controller/Multa/historialMultasUsuario.js @@ -18,35 +18,25 @@ const historialMultasUsuario = async (body) => { { model: Prestamo, where: { idUsuario }, - include: [ - { - model: Equipo, - include: [ - { - model: Carrito, - include: [{ model: Modulo }, { model: TipoCarrito }], - attributes: ['idCarrito', 'carrito'], - }, - ], - attributes: [ - 'idEquipo', - 'numeroSerie', - 'numeroInventario', - 'equipo', - ], - }, - ], - attributes: [ - 'idPrestamo', - 'activo', - 'horaMaxRecoger', - 'horaInicio', - 'horaFin', - 'horaEntrega', - 'canceladoUsuario', - 'regresoInmediato', - 'createdAt', - ], + // include: [ + // { + // model: Equipo, + // include: [ + // { + // model: Carrito, + // include: [{ model: Modulo }, { model: TipoCarrito }], + // attributes: ['idCarrito', 'carrito'], + // }, + // ], + // attributes: [ + // 'idEquipo', + // 'numeroSerie', + // 'numeroInventario', + // 'equipo', + // ], + // }, + // ], + attributes: ['idPrestamo'], }, { model: Operador, diff --git a/server/controller/Operador/crear.js b/server/controller/Operador/crear.js index 1fd6f87..433d65e 100644 --- a/server/controller/Operador/crear.js +++ b/server/controller/Operador/crear.js @@ -21,7 +21,7 @@ const crear = async (body) => { idTipoUsuario: 2, }); }) - .then(() => ({ message: 'Se creo un nuevo operador correctamente.' })); + .then(() => ({ message: 'Se creó un nuevo operador correctamente.' })); }; module.exports = crear; diff --git a/server/controller/Prestamo/historial.js b/server/controller/Prestamo/historial.js index 9b149e0..6a3a2b2 100644 --- a/server/controller/Prestamo/historial.js +++ b/server/controller/Prestamo/historial.js @@ -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, diff --git a/server/controller/Prestamo/reporte.js b/server/controller/Prestamo/reporte.js index addfaf0..63b1c30 100644 --- a/server/controller/Prestamo/reporte.js +++ b/server/controller/Prestamo/reporte.js @@ -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 = []; @@ -98,8 +98,8 @@ const reporte = async (body) => { horaInicio: moment(res[i].horaInicio).format('YYYY-MM-DD HH:mm'), horaFin: moment(res[i].horaFin).format('YYYY-MM-DD HH:mm'), horaEntrega: moment(res[i].horaEntrega).format('YYYY-MM-DD HH:mm'), - canceladoUsuario: res[i].canceladoUsuario, - canceladoOperador: res[i].canceladoOperador, + canceladoUsuario: res[i].canceladoUsuario ? 'si' : 'no', + canceladoOperador: res[i].canceladoOperador ? 'si' : 'no', createdAt: moment(res[i].createdAt).format('YYYY-MM-DD HH:mm'), numeroInventario: res[i].Equipo.numeroInventario, numeroSerie: res[i].Equipo.numeroSerie, diff --git a/server/controller/Usuario/crear.js b/server/controller/Usuario/crear.js index 1114da4..713f377 100644 --- a/server/controller/Usuario/crear.js +++ b/server/controller/Usuario/crear.js @@ -20,7 +20,6 @@ const crear = async (body) => { .then((res) => { if (!res) throw new Error('No existe este usuario.'); if (res.password) throw new Error('Este usuario ya fue registrado.'); - if (!res.activo) throw new Error('Este usuario no esta activo.'); email = `${res.usuario}@pcpuma.acatlan.unam.mx`; correo = correoPcPuma(password); return Usuario.update( diff --git a/server/controller/Usuario/login.js b/server/controller/Usuario/login.js index d9c97c6..c8ef656 100644 --- a/server/controller/Usuario/login.js +++ b/server/controller/Usuario/login.js @@ -18,11 +18,11 @@ const login = async (body) => { return Usuario.findOne({ where: { usuario, password: { [Op.ne]: null } }, - attributes: ['idUsuario', 'password', 'multa', 'activo'], + attributes: ['idUsuario', 'password', 'activo'], }) .then((res) => { if (!res) throw new Error('No existe este usuario.'); - if (!res.activo) throw new Error('Este usuario fue desactivado.'); + if (!res.activo) throw new Error('Este cuenta se encuentra desactivada.'); if (!comparar(password, res.password)) throw new Error('La contraseña es incorrecta.'); return Usuario.findOne({ diff --git a/server/controller/Usuario/quitarMulta.js b/server/controller/Usuario/quitarMulta.js index b82c279..b01d960 100644 --- a/server/controller/Usuario/quitarMulta.js +++ b/server/controller/Usuario/quitarMulta.js @@ -14,7 +14,7 @@ const quitarMulta = async (body) => { if (!res.multa) throw new Error('Este usuario no tiene multa.'); return Usuario.update({ multa: false }, { where: { idUsuario } }); }) - .then((res) => ({ + .then(() => ({ message: 'Se le quitó la multa a este usuario.', })); }; diff --git a/server/controller/Usuario/usuarios.js b/server/controller/Usuario/usuarios.js index 8a50a81..183047c 100644 --- a/server/controller/Usuario/usuarios.js +++ b/server/controller/Usuario/usuarios.js @@ -6,21 +6,14 @@ const TipoUsuario = require(`${dbPath}/TipoUsuario`); const Usuario = require(`${dbPath}/Usuario`); const usuarios = async (body) => { - const pagina = validar.validarNumero( - body.pagina, - 'página', - false, - null, - true, - true - ); + const pagina = validar.validarNumeroEntero(body.pagina, 'página', false); const usuario = body.usuario ? validar.validarNumeroCuenta(body.usuario) : ''; const nombre = body.nombre ? validar.validarTexto(body.nombre, 'nombre', true, 70) : ''; const idTipoUsuario = body.idTipoUsuario ? validar.validarNumeroEntero(body.idTipoUsuario, 'id tipo usuario', true) - : ''; + : null; return Usuario.findAndCountAll({ where: {