diff --git a/server/controller/Prestamo/activos.js b/server/controller/Prestamo/activos.js index d47f01e..978c15e 100644 --- a/server/controller/Prestamo/activos.js +++ b/server/controller/Prestamo/activos.js @@ -19,7 +19,7 @@ const activos = async (body) => { true ); const idPrestamo = body.idPrestamo - ? validar.validarNumeroEntero(body.idPrestamo, 'id prestamo', true) + ? validar.validarNumeroEntero(body.idPrestamo, 'id préstamo', true) : null; const idTipoCarrito = body.idTipoCarrito ? validar.validarNumeroEntero(body.idTipoCarrito, 'id tipo carrito', true) @@ -37,7 +37,7 @@ const activos = async (body) => { if (idTipoCarrito) whereCarrito.push({ idTipoCarrito }); return Modulo.findOne({ where: { idModulo } }).then((res) => { - if (!res) throw new Error('No existe este modulo.'); + if (!res) throw new Error('No existe este módulo.'); return Prestamo.findAndCountAll({ where: { [Op.or]: [ diff --git a/server/controller/Prestamo/cancelarOperador.js b/server/controller/Prestamo/cancelarOperador.js index e31ebe7..fcce9ab 100644 --- a/server/controller/Prestamo/cancelarOperador.js +++ b/server/controller/Prestamo/cancelarOperador.js @@ -15,7 +15,7 @@ const cancelarOperador = async (body) => { return Prestamo.findOne({ where: { idPrestamo } }); }) .then((res) => { - if (!res) throw new Error('Este prestamo no existe.'); + if (!res) throw new Error('Este préstamo no existe.'); if (!res.activo) throw new Error( 'Este préstamo ya no esta activo, no se puede cancelar.' diff --git a/server/controller/Prestamo/cancelarUsuario.js b/server/controller/Prestamo/cancelarUsuario.js index 9336e92..ab72a94 100644 --- a/server/controller/Prestamo/cancelarUsuario.js +++ b/server/controller/Prestamo/cancelarUsuario.js @@ -1,16 +1,22 @@ const io = require('../../socket'); const { validarNumeroEntero } = require('../../helper/validar'); const dbPath = '../../db/tablas'; -const Prestamo = require(`${dbPath}/Prestamo`); const Equipo = require(`${dbPath}/Equipo`); +const Prestamo = require(`${dbPath}/Prestamo`); +const Usuario = require(`${dbPath}/Usuario`); const cancelarUsuario = async (body) => { const idPrestamo = validarNumeroEntero(body.idPrestamo, 'id préstamo', true); + const idUsuario = validarNumeroEntero(body.idUsuario, 'id usuario', true); - return Prestamo.findOne({ - where: { idPrestamo }, - include: [{ model: Equipo }], - }) + return Usuario.findOne({ where: { idUsuario } }) + .then((res) => { + if (!res) throw new Error('No existe este usuario.'); + return Prestamo.findOne({ + where: { idPrestamo }, + include: [{ model: Equipo }], + }); + }) .then((res) => { if (!res) throw new Error('Este préstamo no existe.'); if (!res.activo) @@ -21,6 +27,10 @@ const cancelarUsuario = async (body) => { throw new Error( 'El equipo ya fue entregado al usuario, no se puede cancelar.' ); + if (res.idUsuario != idUsuario) + throw new Error( + 'Este préstamo no pertenece al usuario mandado, no se puede cancelar.' + ); return Equipo.update( { idStatus: 4 }, { where: { idEquipo: res.idEquipo } } diff --git a/server/controller/Prestamo/entregar.js b/server/controller/Prestamo/entregar.js index e25d49e..d0b4d71 100644 --- a/server/controller/Prestamo/entregar.js +++ b/server/controller/Prestamo/entregar.js @@ -11,7 +11,7 @@ const TipoCarrito = require(`${dbPath}/TipoCarrito`); const entregar = async (body) => { const ahora = moment(); - const idPrestamo = validarNumeroEntero(body.idPrestamo, 'id prestamo', true); + const idPrestamo = validarNumeroEntero(body.idPrestamo, 'id préstamo', true); const idOperadorEntrega = validarNumeroEntero( body.idOperadorEntrega, 'id operador entrega', @@ -28,19 +28,20 @@ const entregar = async (body) => { }); }) .then(async (res) => { - if (!res) throw new Error('No existe este prestamo.'); - idEquipo = res.Equipo.idEquipo; - if (!res.activo) throw new Error('Este prestamo ya no esta activo.'); - else if (res.Equipo.idStatus === 2) + if (!res) throw new Error('No existe este préstamo.'); + idEquipo = res.idEquipo; + if (!res.activo) throw new Error('Este préstamo ya no esta activo.'); + if (res.Equipo.idStatus === 2) throw new Error('Ya se entrego el equipo al usuario.'); - else if (moment(res.horaMaxRecoger) < ahora) + if (moment(res.horaMaxRecoger) < ahora) await Equipo.update({ idStatus: 4 }, { where: { idEquipo } }) .then(() => Prestamo.update({ activo: false }, { where: { idPrestamo } }) ) .then(() => { + io.getIO().emit('actualizar'); throw new Error( - 'Ya paso el tiempo límite para recoger el equipo de cómputo.' + 'Ya pasó el tiempo límite para recoger el equipo de cómputo.' ); }); return Equipo.update({ idStatus: 2 }, { where: { idEquipo } }); diff --git a/server/controller/Prestamo/historial.js b/server/controller/Prestamo/historial.js index 6a3a2b2..13a4a1a 100644 --- a/server/controller/Prestamo/historial.js +++ b/server/controller/Prestamo/historial.js @@ -88,6 +88,7 @@ const historial = async (body) => { 'horaFin', 'horaEntrega', 'canceladoUsuario', + 'canceladoOperador', 'regresoInmediato', 'createdAt', ], diff --git a/server/controller/Prestamo/pedir.js b/server/controller/Prestamo/pedir.js index dea6359..4eecf53 100644 --- a/server/controller/Prestamo/pedir.js +++ b/server/controller/Prestamo/pedir.js @@ -32,14 +32,14 @@ const pedir = async (body) => { // if (ahora > horaMax) // throw new Error('Ya no se puede realizar un prestamo el día de hoy.'); // if (ahora < horaMin) - // throw new Error('Aun es muy temprano para realizar un prestamo.'); + // throw new Error('Aún es muy temprano para realizar un prestamo.'); return TipoCarrito.findOne({ where: { idTipoCarrito } }) .then((res) => { if (!res) throw new Error('No existe este tipo de equipo.'); return Modulo.findOne({ where: { idModulo } }); }) .then((res) => { - if (!res) throw new Error('No existe este modulo.'); + if (!res) throw new Error('No existe este módulo.'); return Programa.findOne({ where: { idPrograma } }); }) .then((res) => { @@ -51,7 +51,7 @@ const pedir = async (body) => { if (!res.activo) throw new Error('Este usuario no esta activo.'); if (res.multa) throw new Error( - 'Tienes una multa vigente, no puedes solicitar un equipo de computo.' + 'Tienes una multa vigente, no puedes solicitar un equipo de cómputo.' ); return Prestamo.findOne({ where: { @@ -75,7 +75,7 @@ const pedir = async (body) => { 'No puedes pedir otro equipo de cómputo hasta que un operador confirme la entrega del equipo de cómputo del anterior préstamo.' ); throw new Error( - 'Tienes un prestamo activo. No puedes solicitar otro equipo de cómputo.' + 'Tienes un préstamo activo. No puedes solicitar otro equipo de cómputo.' ); } return Equipo.findOne({ diff --git a/server/controller/Prestamo/prestamo.js b/server/controller/Prestamo/prestamo.js index deba1c2..615000e 100644 --- a/server/controller/Prestamo/prestamo.js +++ b/server/controller/Prestamo/prestamo.js @@ -52,6 +52,9 @@ const prestamo = async (body) => { 'horaInicio', 'horaFin', 'horaEntrega', + 'canceladoUsuario', + 'canceladoOperador', + 'regresoInmediato', 'createdAt', ], }).then((res) => { diff --git a/server/controller/Prestamo/prestamoUsuario.js b/server/controller/Prestamo/prestamoUsuario.js index 7dc52c2..891238b 100644 --- a/server/controller/Prestamo/prestamoUsuario.js +++ b/server/controller/Prestamo/prestamoUsuario.js @@ -38,6 +38,9 @@ const prestamo = async (body) => { 'horaInicio', 'horaFin', 'horaEntrega', + 'canceladoUsuario', + 'canceladoOperador', + 'regresoInmediato', 'createdAt', ], }); diff --git a/server/controller/Prestamo/regresar.js b/server/controller/Prestamo/regresar.js index 5d78903..662ca91 100644 --- a/server/controller/Prestamo/regresar.js +++ b/server/controller/Prestamo/regresar.js @@ -11,7 +11,7 @@ const Usuario = require(`${dbPath}/Usuario`); const regresar = async (body) => { const ahora = moment(); const ahoraAux = moment(); - const idPrestamo = validarNumeroEntero(body.idPrestamo, 'id prestamo', true); + const idPrestamo = validarNumeroEntero(body.idPrestamo, 'id préstamo', true); const idOperadorRegreso = validarNumeroEntero( body.idOperadorRegreso, 'id operador regreso', @@ -33,7 +33,7 @@ const regresar = async (body) => { if (!res.activo && res.idOperadorRegreso) throw new Error('Este préstamo ya no esta activo.'); if (res.Equipo.idStatus === 1) - throw new Error('Aun no se ha entregado el equipo al usuario.'); + throw new Error('Aún no se ha entregado el equipo al usuario.'); if (!res.regresoInmediato) { update.horaEntrega = ahora.format(); update.activo = false; diff --git a/server/controller/Prestamo/regresarNumeroInventario.js b/server/controller/Prestamo/regresarNumeroInventario.js index eb2b782..fd4932b 100644 --- a/server/controller/Prestamo/regresarNumeroInventario.js +++ b/server/controller/Prestamo/regresarNumeroInventario.js @@ -33,13 +33,13 @@ const regresarNumeroInventario = async (body) => { return Prestamo.findOne({ where: { [Op.or]: [ + { activo: true }, { [Op.and]: [ { regresoInmediato: true }, { idOperadorRegreso: null }, ], }, - { activo: true }, ], }, include: [{ model: Equipo, where: { numeroInventario } }], @@ -47,9 +47,11 @@ const regresarNumeroInventario = async (body) => { }) .then(async (res) => { if (!res) - throw new Error('No existe un prestamo activo con este equipo.'); + throw new Error( + 'No existe un préstamo activo con este equipo de cómputo.' + ); if (res.Equipo.idStatus === 1) - throw new Error('Aun no se ha entregado el equipo al usuario.'); + throw new Error('Aún no se ha entregado el equipo al usuario.'); idPrestamo = res.idPrestamo; if (!res.regresoInmediato) { update.horaEntrega = ahora.format(); @@ -74,9 +76,7 @@ const regresarNumeroInventario = async (body) => { { where: { idEquipo: res.idEquipo } } ); }) - .then(() => { - Prestamo.update(update, { where: { idPrestamo } }); - }) + .then(() => Prestamo.update(update, { where: { idPrestamo } })) .then(() => { io.getIO().emit('actualizar'); return { diff --git a/server/controller/Prestamo/regresoInmediato.js b/server/controller/Prestamo/regresoInmediato.js index 27a0e10..9f30560 100644 --- a/server/controller/Prestamo/regresoInmediato.js +++ b/server/controller/Prestamo/regresoInmediato.js @@ -10,7 +10,7 @@ const Usuario = require(`${dbPath}/Usuario`); const regresoInmediato = async (body) => { const ahora = moment(); const ahoraAux = moment(); - const idPrestamo = validarNumeroEntero(body.idPrestamo, 'id prestamo', true); + const idPrestamo = validarNumeroEntero(body.idPrestamo, 'id préstamo', true); let diferencia = null; return Prestamo.findOne({ @@ -21,7 +21,7 @@ const regresoInmediato = async (body) => { if (!res) throw new Error('No existe este préstamo.'); if (!res.activo) throw new Error('Este préstamo ya no esta activo.'); if (res.Equipo.idStatus === 1) - throw new Error('Aun no se ha entregado el equipo al usuario.'); + throw new Error('Aún no se ha entregado el equipo al usuario.'); diferencia = parseInt((ahora - moment(res.horaFin)) / 60000); if (diferencia >= 15) await Multa.create({ diff --git a/server/controller/Prestamo/regresoInmediatoNumeroInventario.js b/server/controller/Prestamo/regresoInmediatoNumeroInventario.js index a27e77f..4fe2c56 100644 --- a/server/controller/Prestamo/regresoInmediatoNumeroInventario.js +++ b/server/controller/Prestamo/regresoInmediatoNumeroInventario.js @@ -27,7 +27,7 @@ const regresoInmediatoNumeroInventario = async (body) => { if (!res) throw new Error('No existe este préstamo.'); if (!res.activo) throw new Error('Este préstamo ya no esta activo.'); if (res.Equipo.idStatus === 1) - throw new Error('Aun no se ha entregado el equipo al usuario.'); + throw new Error('Aún no se ha entregado el equipo al usuario.'); diferencia = parseInt((ahora - moment(res.horaFin)) / 60000); if (diferencia >= 15) await Multa.create({ diff --git a/server/controller/Prestamo/status.js b/server/controller/Prestamo/status.js index 962fc76..ab14a6b 100644 --- a/server/controller/Prestamo/status.js +++ b/server/controller/Prestamo/status.js @@ -12,7 +12,7 @@ const TipoCarrito = require(`${dbPath}/TipoCarrito`); const status = async (body) => { const ahora = moment(); - const idPrestamo = validarNumeroEntero(body.idPrestamo, 'id prestamo', true); + const idPrestamo = validarNumeroEntero(body.idPrestamo, 'id préstamo', true); let message = ''; let atraso = false; @@ -21,10 +21,10 @@ const status = async (body) => { include: [{ model: Equipo }], }) .then(async (res) => { - if (!res) throw new Error('No existe este prestamo.'); + if (!res) throw new Error('No existe este préstamo.'); if (!res.activo) { - if (!res.horaEntrega) message = 'Este prestamo fue cancelado.'; - else message = 'Este prestamo no es encuentra activo.'; + if (!res.horaEntrega) message = 'Este préstamo fue cancelado.'; + else message = 'Este préstamo no es encuentra activo.'; } else if (res.Equipo.idStatus === 2) { if (moment(res.horaFin) < ahora) { message = @@ -44,7 +44,7 @@ const status = async (body) => { message = 'Ya paso el tiempo limite para recoger el dispositivo. Se ha cancelado tu prestamo.'; io.getIO().emit('actualizar'); - } else message = 'Aun no se entrega el equipo al usuario.'; + } else message = 'Aún no se entrega el equipo al usuario.'; return Prestamo.findOne({ where: { idPrestamo }, include: [