diff --git a/server/controller/Carrito/carritos.js b/server/controller/Carrito/carritos.js index 2e40b52..43ac9a4 100644 --- a/server/controller/Carrito/carritos.js +++ b/server/controller/Carrito/carritos.js @@ -3,11 +3,10 @@ const Carrito = require(`${dbPath}/Carrito`); const Modulo = require(`${dbPath}/Modulo`); const TipoCarrito = require(`${dbPath}/TipoCarrito`); -const carritos = async () => { - return Carrito.findAll({ +const carritos = async () => + Carrito.findAll({ include: [{ model: TipoCarrito }, { model: Modulo }], attributes: ['idCarrito', 'sobrenombre', 'activo'], }); -}; module.exports = carritos; diff --git a/server/controller/Equipo/cargaMasiva.js b/server/controller/Equipo/cargaMasiva.js index 96278a9..7c78d71 100644 --- a/server/controller/Equipo/cargaMasiva.js +++ b/server/controller/Equipo/cargaMasiva.js @@ -95,15 +95,17 @@ const cargaMasiva = async (file) => { { model: Carrito, include: [{ model: TipoCarrito }, { model: Modulo }], + attributes: ['idCarrito', 'sobrenombre'], }, ], + attributes: [ + 'idEquipo', + 'numeroSerie', + 'numeroInventario', + 'sobrenombre', + ], }) ); - delete existeEquipo.dataValues.idStatus; - delete existeEquipo.dataValues.idCarrito; - delete existeEquipo.dataValues.idPrograma; - delete existeEquipo.dataValues.Carrito.dataValues.idModulo; - delete existeEquipo.dataValues.Carrito.dataValues.idTipoCarrito; equiposNuevos.push(existeEquipo); } await eliminarArchivo(path); diff --git a/server/controller/Equipo/equipos.js b/server/controller/Equipo/equipos.js index 52925fb..31ae7bc 100644 --- a/server/controller/Equipo/equipos.js +++ b/server/controller/Equipo/equipos.js @@ -4,8 +4,8 @@ const Equipo = require(`${dbPath}/Equipo`); const Modulo = require(`${dbPath}/Modulo`); const TipoCarrito = require(`${dbPath}/TipoCarrito`); -const equipos = async () => { - return Carrito.findAll({ +const equipos = async () => + Carrito.findAll({ include: [{ model: TipoCarrito }, { model: Modulo }], attributes: ['idCarrito', 'sobrenombre', 'activo'], }).then(async (res) => { @@ -21,6 +21,5 @@ const equipos = async () => { }); return res; }); -}; module.exports = equipos; diff --git a/server/controller/Equipo/update.js b/server/controller/Equipo/update.js index 507113a..30560a3 100644 --- a/server/controller/Equipo/update.js +++ b/server/controller/Equipo/update.js @@ -22,24 +22,30 @@ const update = async (body) => { : null; let update = {}; - if (idStatus) - await Status.findOne({ where: { idStatus } }).then((res) => { - if (!res) throw new Error('No existe este status.'); - update.idStatus = idStatus; - }); - if (idCarrito) - await Carrito.findOne({ where: { idCarrito } }).then((res) => { - if (!res) throw new Error('No existe este carrito.'); - update.idCarrito = idCarrito; - }); - if (idPrograma) - await Programa.findOne({ where: { idPrograma } }).then((res) => { - if (!res) throw new Error('No existe este programa.'); - update.idPrograma = idPrograma; - }); - if (validar.validarObjetoVacio(update)) - throw new Error('No se envio nada para actualizar.'); - return Equipo.findOne({ where: { idEquipo } }) + return Status.findOne({ where: { idStatus } }) + .then((res) => { + if (idStatus) { + if (!res) throw new Error('No existe este status.'); + update.idStatus = idStatus; + } + return Carrito.findOne({ where: { idCarrito } }); + }) + .then((res) => { + if (idCarrito) { + if (!res) throw new Error('No existe este carrito.'); + update.idCarrito = idCarrito; + } + return Programa.findOne({ where: { idPrograma } }); + }) + .then((res) => { + if (idPrograma) { + if (!res) throw new Error('No existe este programa.'); + update.idPrograma = idPrograma; + } + if (validar.validarObjetoVacio(update)) + throw new Error('No se envio nada para actualizar.'); + return Equipo.findOne({ where: { idEquipo } }); + }) .then((res) => { if (!res) throw new Error('No existe este equipo.'); return Equipo.update(update, { where: { idEquipo } }); diff --git a/server/controller/Multa/historialMultasEquipo.js b/server/controller/Multa/historialMultasEquipo.js index f459486..55a02cb 100644 --- a/server/controller/Multa/historialMultasEquipo.js +++ b/server/controller/Multa/historialMultasEquipo.js @@ -45,7 +45,7 @@ const historialMultasEquipo = async (body) => { limit: 25, offset: 25 * (pagina - 1), order: [['createdAt', 'DESC']], - }).then((res) => ({ count: res.count, historialMultasEquipo: res.rows })); + }); }; module.exports = historialMultasEquipo; diff --git a/server/controller/Multa/historialMultasUsuario.js b/server/controller/Multa/historialMultasUsuario.js index 054d23b..b012798 100644 --- a/server/controller/Multa/historialMultasUsuario.js +++ b/server/controller/Multa/historialMultasUsuario.js @@ -58,18 +58,18 @@ const historialMultasUsuario = async (body) => { 'createdAt', ], }, - { model: Infraccion }, { model: Operador, as: 'OperadorMulta', attributes: ['idOperador', 'operador'], }, + { model: Infraccion }, ], attributes: ['idMulta', 'descripcion', 'fechaFin', 'createdAt'], limit: 25, offset: 25 * (pagina - 1), order: [['createdAt', 'DESC']], - }).then((res) => ({ count: res.count, historialMultasUsuario: res.rows })); + }); }; module.exports = historialMultasUsuario; diff --git a/server/controller/Operador/operadores.js b/server/controller/Operador/operadores.js index 8d1f369..2dec3c8 100644 --- a/server/controller/Operador/operadores.js +++ b/server/controller/Operador/operadores.js @@ -1,3 +1,4 @@ +const { Op } = require('sequelize'); const validar = require('../../helper/validar'); const dbPath = '../../db/tablas'; const Operador = require(`${dbPath}/Operador`); @@ -12,15 +13,17 @@ const operadores = async (body) => { true, true ); - // filtros + const operador = body.operador + ? validar.validarTexto(body.operador, 'operador', true, 20) + : ''; return Operador.findAndCountAll({ - where: { idTipoUsuario: 2 }, + where: { idTipoUsuario: 2, operador: { [Op.like]: `%${operador}%` } }, include: [{ model: TipoUsuario }], attributes: ['idOperador', 'operador', 'activo'], limit: 25, offset: 25 * (pagina - 1), - }).then((res) => ({ count: res.count, operadores: res.rows })); + }); }; module.exports = operadores; diff --git a/server/controller/Operador/update.js b/server/controller/Operador/update.js index b1eb5b4..aeff626 100644 --- a/server/controller/Operador/update.js +++ b/server/controller/Operador/update.js @@ -9,19 +9,19 @@ const update = async (body) => { 'id operador', true ); + const password = body.password + ? validar.validarAlfanumerico(body.password, 'contraseña', false, 20) + : ''; let update = {}; - if (body.activo === 'desactivar') update.activo = false; - else if (body.activo === 'activar') update.activo = true; - if (body.password) - update.password = encriptar( - validar.validarAlfanumerico(body.password, 'contraseña', false, 20) - ); - if (validar.validarObjetoVacio(update)) - throw new Error('No se mando nada para actualizar.'); return Operador.findOne({ where: { idOperador, idTipoUsuario: 2 } }) .then((res) => { if (!res) throw new Error('No existe este operador.'); + if (body.activo === 'desactivar') update.activo = false; + else if (body.activo === 'activar') update.activo = true; + if (password) update.password = encriptar(password); + if (validar.validarObjetoVacio(update)) + throw new Error('No se mando nada para actualizar.'); return Operador.update(update, { where: { idOperador } }); }) .then((res) => ({ message: 'Se actualizó correctamente al operador.' })); diff --git a/server/controller/Prestamo/activos.js b/server/controller/Prestamo/activos.js index c091102..2d20085 100644 --- a/server/controller/Prestamo/activos.js +++ b/server/controller/Prestamo/activos.js @@ -43,53 +43,51 @@ const activos = async (body) => { let whereCarrito = [{ idModulo }]; if (idTipoCarrito) whereCarrito.push({ idTipoCarrito }); - return Modulo.findOne({ where: { idModulo } }) - .then((res) => { - if (!res) throw new Error('No existe este modulo.'); - return Prestamo.findAndCountAll({ - where: { activo: true, idPrestamo: { [Op.like]: `%${idPrestamo}%` } }, - include: [ - { - model: Equipo, - where: { numeroInventario: { [Op.like]: `%${numeroInventario}%` } }, - include: [ - { - model: Carrito, - where: { [Op.and]: whereCarrito }, - include: [{ model: TipoCarrito }, { model: Modulo }], - attributes: ['idCarrito', 'sobrenombre'], - }, - { model: Status }, - ], - attributes: [ - 'idEquipo', - 'numeroSerie', - 'numeroInventario', - 'sobrenombre', - ], - }, - { - model: Usuario, - where: { usuario: { [Op.like]: `%${usuario}%` } }, - include: [{ model: TipoUsuario }, { model: Carrera }], - attributes: ['idUsuario', 'usuario', 'nombre'], - }, - ], - attributes: [ - 'idPrestamo', - 'activo', - 'horaMaxRecoger', - 'horaInicio', - 'horaFin', - 'horaEntrega', - 'createdAt', - ], - limit: 25, - offset: 25 * (pagina - 1), - order: [['createdAt', 'DESC']], - }); - }) - .then((res) => ({ count: res.count, activos: res.rows })); + return Modulo.findOne({ where: { idModulo } }).then((res) => { + if (!res) throw new Error('No existe este modulo.'); + return Prestamo.findAndCountAll({ + where: { activo: true, idPrestamo: { [Op.like]: `%${idPrestamo}%` } }, + include: [ + { + model: Equipo, + where: { numeroInventario: { [Op.like]: `%${numeroInventario}%` } }, + include: [ + { + model: Carrito, + where: { [Op.and]: whereCarrito }, + include: [{ model: TipoCarrito }, { model: Modulo }], + attributes: ['idCarrito', 'sobrenombre'], + }, + { model: Status }, + ], + attributes: [ + 'idEquipo', + 'numeroSerie', + 'numeroInventario', + 'sobrenombre', + ], + }, + { + model: Usuario, + where: { usuario: { [Op.like]: `%${usuario}%` } }, + include: [{ model: TipoUsuario }, { model: Carrera }], + attributes: ['idUsuario', 'usuario', 'nombre'], + }, + ], + attributes: [ + 'idPrestamo', + 'activo', + 'horaMaxRecoger', + 'horaInicio', + 'horaFin', + 'horaEntrega', + 'createdAt', + ], + limit: 25, + offset: 25 * (pagina - 1), + order: [['createdAt', 'DESC']], + }); + }); }; module.exports = activos; diff --git a/server/controller/Prestamo/cancelarOperador.js b/server/controller/Prestamo/cancelarOperador.js index c68c366..4a7258a 100644 --- a/server/controller/Prestamo/cancelarOperador.js +++ b/server/controller/Prestamo/cancelarOperador.js @@ -20,7 +20,6 @@ const cancelarOperador = async (body) => { include: [{ model: Equipo }], }); }) - .then((res) => { if (!res) throw new Error('Este prestamo no existe.'); if (!res.activo) diff --git a/server/controller/Prestamo/historial.js b/server/controller/Prestamo/historial.js index c1eda15..cf5f756 100644 --- a/server/controller/Prestamo/historial.js +++ b/server/controller/Prestamo/historial.js @@ -100,7 +100,7 @@ const historial = async (body) => { limit: 25, offset: 25 * (pagina - 1), order: [['createdAt', 'DESC']], - }).then((res) => ({ count: res.count, historial: res.rows })); + }); }; module.exports = historial; diff --git a/server/controller/Prestamo/historialEquipo.js b/server/controller/Prestamo/historialEquipo.js index af6f3e0..fecc6c8 100644 --- a/server/controller/Prestamo/historialEquipo.js +++ b/server/controller/Prestamo/historialEquipo.js @@ -68,7 +68,7 @@ const historialEquipo = async (body) => { limit: 25, offset: 25 * (pagina - 1), order: [['createdAt', 'DESC']], - }).then((res) => ({ count: res.count, historialEquipo: res.rows })); + }); }; module.exports = historialEquipo; diff --git a/server/controller/Prestamo/historialUsuario.js b/server/controller/Prestamo/historialUsuario.js index 71bd168..fe8c194 100644 --- a/server/controller/Prestamo/historialUsuario.js +++ b/server/controller/Prestamo/historialUsuario.js @@ -77,7 +77,7 @@ const historialUsuario = async (body) => { 'canceladoUsuario', 'createdAt', ], - }).then((res) => ({ count: res.count, historialUsuario: res.rows })); + }); }; module.exports = historialUsuario; diff --git a/server/controller/Usuario/crear.js b/server/controller/Usuario/crear.js index bbf32f1..3ed30fb 100644 --- a/server/controller/Usuario/crear.js +++ b/server/controller/Usuario/crear.js @@ -12,14 +12,15 @@ const crear = async (body) => { ); const telefono = validar.validarNumero(body.telefono, 'teléfono', true, 15); const password = encriptar.generarPassword(); - let correo = '@pcpuma.acatlan.unam.mx'; + let correo = ''; return Usuario.findOne({ where: { idUsuario } }) .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.'); - correo = res.usuario + correo; + // correo = `${res.usuario}@pcpuma.acatlan.unam.mx`; + correo = 'lemuelhelonmarquezrosas@gmail.com'; return Usuario.update( { password: encriptar.encriptar(password), @@ -28,10 +29,7 @@ const crear = async (body) => { { where: { idUsuario } } ); }) - .then((res) => { - // return gmail('Contraseña',correo,"") - return gmail('Contraseña', 'lemuelhelonmarquezrosas@gmail.com', password); - }) + .then((res) => gmail('Contraseña', correo, password)) .then((res) => ({ message: 'Se creó correctamente tu cuenta, ingresa a tu correo @pcpuma para consultar tu contraseña para este servicio.', diff --git a/server/controller/Usuario/usuarios.js b/server/controller/Usuario/usuarios.js index 77611b0..8a50a81 100644 --- a/server/controller/Usuario/usuarios.js +++ b/server/controller/Usuario/usuarios.js @@ -14,22 +14,26 @@ const usuarios = async (body) => { true, true ); - // filtros + 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) + : ''; return Usuario.findAndCountAll({ - where: { password: { [Op.ne]: null } }, + where: { + usuario: { [Op.like]: `%${usuario}%` }, + nombre: { [Op.like]: `%${nombre}%` }, + password: { [Op.ne]: null }, + idTipoUsuario: { [Op.like]: `%${idTipoUsuario}%` }, + }, include: [{ model: TipoUsuario }, { model: Carrera }], - attributes: [ - 'idUsuario', - 'usuario', - 'nombre', - 'telefono', - 'multa', - 'activo', - ], + attributes: ['idUsuario', 'usuario', 'nombre', 'multa', 'activo'], limit: 25, offset: 25 * (pagina - 1), - }).then((res) => ({ count: res.count, usuarios: res.rows })); + }); }; module.exports = usuarios;