diff --git a/server/controller/Multa/multarUsuario.js b/server/controller/Multa/multarUsuario.js new file mode 100644 index 0000000..4035771 --- /dev/null +++ b/server/controller/Multa/multarUsuario.js @@ -0,0 +1,27 @@ +const validar = require('../../helper/validar'); +const dbPath = '../../db/tablas'; +const Multa = require(`${dbPath}/Multa`); +const Usuario = require(`${dbPath}/Usuario`); + +const multar = async (body) => { + const idUsuario = validar.validarNumeroEntero( + body.idUsuario, + 'id usuario', + true + ); + + return Usuario.findOne({ where: { idUsuario } }) + .then((res) => { + if (!res) throw new Error('No existe este usuario.'); + return Multa.findAll({ where: { idUsuario, activo: true } }); + }) + .then((res) => { + if (res.length > 2) + throw new Error( + 'El usuario tiene más de 2 multas activas, favor de notificar a un operador sobre este problema.' + ); + return res; + }); +}; + +module.exports = multar; diff --git a/server/controller/Prestamo/historial.js b/server/controller/Prestamo/historial.js index 8986572..916ba4b 100644 --- a/server/controller/Prestamo/historial.js +++ b/server/controller/Prestamo/historial.js @@ -94,7 +94,6 @@ const historial = async (body) => { ], limit: 25, offset: 25 * (pagina - 1), - order: [['createdAt', 'DESC']], }); }; diff --git a/server/db/tablas/Multa.js b/server/db/tablas/Multa.js index 2d0ad74..b62565d 100644 --- a/server/db/tablas/Multa.js +++ b/server/db/tablas/Multa.js @@ -22,6 +22,11 @@ Multa.init( type: DataTypes.DATE, allowNull: false, }, + activo: { + type: DataTypes.BOOLEAN, + allowNull: false, + defaultValue: true, + }, }, { sequelize, diff --git a/server/helper/equiposDiario.js b/server/helper/equiposDiario.js new file mode 100644 index 0000000..b7fb3a8 --- /dev/null +++ b/server/helper/equiposDiario.js @@ -0,0 +1,3 @@ +const Equipo = require('../db/tablas/Equipo'); + +Equipo.update({ prestado: false }); diff --git a/server/middleware/autentificacion.js b/server/middleware/autentificacion.js index dbf9e97..110056e 100644 --- a/server/middleware/autentificacion.js +++ b/server/middleware/autentificacion.js @@ -13,7 +13,7 @@ const verificaToken = (req, res, next) => { let message = ''; if (err.message === 'invalid signature') - message = 'El token no es valido. Inicia sesión de nuevo.'; + message = 'Se termino el tiempo de tu sesión. Inicia sesión de nuevo.'; if (err.message === 'jwt expired') message = 'El token expiro. Inicia sesión de nuevo.'; if (err.message === 'jwt malformed') diff --git a/server/socket.js b/server/socket.js index 15560d0..87fe162 100644 --- a/server/socket.js +++ b/server/socket.js @@ -8,10 +8,10 @@ module.exports = { origin: [ // 'http://localhost:3046', // 'http://localhost:3056', - 'http://132.248.80.196:3045', - 'http://132.248.80.196:3055', - // 'https://pcpuma.acatlan.unam.mx', - // 'https://pcpuma.acatlan.unam.mx:8080', + // 'http://132.248.80.196:3045', + // 'http://132.248.80.196:3055', + 'https://pcpuma.acatlan.unam.mx', + 'https://pcpuma.acatlan.unam.mx:8080', ], }, });