diff --git a/server/controller/Multa/historialMultasEquipo.js b/server/controller/Multa/historialMultasEquipo.js index 587bd6c..82a1c12 100644 --- a/server/controller/Multa/historialMultasEquipo.js +++ b/server/controller/Multa/historialMultasEquipo.js @@ -15,12 +15,10 @@ const historialMultasEquipo = async (body) => { { model: Prestamo, where: { idEquipo }, - include: [ - { model: Usuario }, - { model: Operador, as: 'OperadorRegreso' }, - ], + include: [{ model: Usuario }], }, { model: Infraccion }, + { model: Operador, as: 'OperadorMulta' }, ], limit: 25, offset: 25 * (pagina - 1), @@ -29,14 +27,15 @@ const historialMultasEquipo = async (body) => { for (let i = 0; i < res.rows.length; i++) { delete res.rows[i].dataValues.idInfraccion; delete res.rows[i].dataValues.idPrestamo; + delete res.rows[i].dataValues.idOperadorMulta; + delete res.rows[i].dataValues.OperadorMulta.dataValues.password; + delete res.rows[i].dataValues.OperadorMulta.dataValues.idTipoUsuario; + delete res.rows[i].dataValues.OperadorMulta.dataValues.activo; delete res.rows[i].dataValues.Prestamo.dataValues.idOperadorEntrega; delete res.rows[i].dataValues.Prestamo.dataValues.idOperadorRegreso; + delete res.rows[i].dataValues.Prestamo.dataValues.idOperadorCancelacion; delete res.rows[i].dataValues.Prestamo.dataValues.idUsuario; delete res.rows[i].dataValues.Prestamo.dataValues.idEquipo; - delete res.rows[i].dataValues.Prestamo.dataValues.OperadorRegreso - .dataValues.password; - delete res.rows[i].dataValues.Prestamo.dataValues.OperadorRegreso - .dataValues.idTipoUsuario; delete res.rows[i].dataValues.Prestamo.dataValues.Usuario.dataValues .password; delete res.rows[i].dataValues.Prestamo.dataValues.Usuario.dataValues diff --git a/server/controller/Multa/historialMultasUsuario.js b/server/controller/Multa/historialMultasUsuario.js index 589fb65..dda52e3 100644 --- a/server/controller/Multa/historialMultasUsuario.js +++ b/server/controller/Multa/historialMultasUsuario.js @@ -28,10 +28,10 @@ const historialMultasUsuario = async (body) => { }, ], }, - { model: Operador, as: 'OperadorRegreso' }, ], }, { model: Infraccion }, + { model: Operador, as: 'OperadorMulta' }, ], limit: 25, offset: 25 * (pagina - 1), @@ -40,14 +40,15 @@ const historialMultasUsuario = async (body) => { for (let i = 0; i < res.rows.length; i++) { delete res.rows[i].dataValues.idInfraccion; delete res.rows[i].dataValues.idPrestamo; + delete res.rows[i].dataValues.idOperadorMulta; + delete res.rows[i].dataValues.OperadorMulta.dataValues.password; + delete res.rows[i].dataValues.OperadorMulta.dataValues.idTipoUsuario; + delete res.rows[i].dataValues.OperadorMulta.dataValues.activo; delete res.rows[i].dataValues.Prestamo.dataValues.idOperadorEntrega; delete res.rows[i].dataValues.Prestamo.dataValues.idOperadorRegreso; + delete res.rows[i].dataValues.Prestamo.dataValues.idOperadorCancelacion; delete res.rows[i].dataValues.Prestamo.dataValues.idUsuario; delete res.rows[i].dataValues.Prestamo.dataValues.idEquipo; - delete res.rows[i].dataValues.Prestamo.dataValues.OperadorRegreso - .dataValues.password; - delete res.rows[i].dataValues.Prestamo.dataValues.OperadorRegreso - .dataValues.idTipoUsuario; delete res.rows[i].dataValues.Prestamo.dataValues.Equipo.dataValues .idCarrito; delete res.rows[i].dataValues.Prestamo.dataValues.Equipo.dataValues diff --git a/server/controller/Multa/multar.js b/server/controller/Multa/multar.js index 8f025a0..27141ee 100644 --- a/server/controller/Multa/multar.js +++ b/server/controller/Multa/multar.js @@ -2,11 +2,13 @@ const moment = require('moment'); const validar = require('../../helper/validar'); const dbPath = '../../db/tablas'; const Infraccion = require(`${dbPath}/Infraccion`); +const Multa = require(`${dbPath}/Multa`); +const Operador = require(`${dbPath}/Operador`); const Prestamo = require(`${dbPath}/Prestamo`); const Usuario = require(`${dbPath}/Usuario`); -const Multa = require(`${dbPath}/Multa`); const multar = async (body) => { + const idOperadorMulta = validar.validarId(body.idOperadorMulta); const idInfraccion = validar.validarId(body.idInfraccion); const idPrestamo = validar.validarId(body.idPrestamo); const descripcion = validar.validarAlfanumerico( @@ -17,7 +19,11 @@ const multar = async (body) => { let prestamo = {}; let fechaFin = moment(); - return Infraccion.findOne({ where: { idInfraccion } }) + return Operador.findOne({ where: { idOperador: idOperadorMulta } }) + .then((res) => { + if (!res) throw new Error('No existe esta este operador.'); + return Infraccion.findOne({ where: { idInfraccion } }); + }) .then((res) => { if (!res) throw new Error('No existe esta infracción.'); if (res.gravedad == '1') fechaFin.add(7, 'd'); @@ -44,6 +50,7 @@ const multar = async (body) => { Multa.create({ descripcion, fechaFin: fechaFin.format(), + idOperadorMulta, idInfraccion, idPrestamo, }) diff --git a/server/controller/Multa/multarNumeroInventario.js b/server/controller/Multa/multarNumeroInventario.js index ed5447c..3546cd0 100644 --- a/server/controller/Multa/multarNumeroInventario.js +++ b/server/controller/Multa/multarNumeroInventario.js @@ -8,6 +8,7 @@ const Prestamo = require(`${dbPath}/Prestamo`); const Usuario = require(`${dbPath}/Usuario`); const multar = async (body) => { + const idOperadorMulta = validar.validarId(body.idOperadorMulta); const idInfraccion = validar.validarId(body.idInfraccion); const numeroInventario = validar.validarAlfanumerico( body.numeroInventario, @@ -22,7 +23,11 @@ const multar = async (body) => { let prestamo = {}; let fechaFin = moment(); - return Infraccion.findOne({ where: { idInfraccion } }) + return Operador.findOne({ where: { idOperador: idOperadorMulta } }) + .then((res) => { + if (!res) throw new Error('No existe esta este operador.'); + return Infraccion.findOne({ where: { idInfraccion } }); + }) .then((res) => { if (!res) throw new Error('No existe esta infracción.'); if (res.gravedad == '1') fechaFin.add(7, 'd'); @@ -52,6 +57,7 @@ const multar = async (body) => { .then((res) => Multa.create({ descripcion, + idOperadorMulta, idInfraccion, idPrestamo: prestamo.idPrestamo, fechaFin: fechaFin.format(), diff --git a/server/controller/Prestamo/activos.js b/server/controller/Prestamo/activos.js index 63a42e6..c633182 100644 --- a/server/controller/Prestamo/activos.js +++ b/server/controller/Prestamo/activos.js @@ -61,6 +61,7 @@ const activos = async (body) => { delete res.rows[i].dataValues.idUsuario; delete res.rows[i].dataValues.idOperadorEntrega; delete res.rows[i].dataValues.idOperadorRegreso; + delete res.rows[i].dataValues.idOperadorCancelacion; delete res.rows[i].dataValues.idEquipo; delete res.rows[i].dataValues.Equipo.dataValues.idPrograma; delete res.rows[i].dataValues.Equipo.dataValues.idStatus; diff --git a/server/controller/Prestamo/cancelarOperador.js b/server/controller/Prestamo/cancelarOperador.js index d2e16f2..e45be19 100644 --- a/server/controller/Prestamo/cancelarOperador.js +++ b/server/controller/Prestamo/cancelarOperador.js @@ -1,15 +1,22 @@ const { validarId } = require('../../helper/validar'); const dbPath = '../../db/tablas'; -const Prestamo = require(`${dbPath}/Prestamo`); const Equipo = require(`${dbPath}/Equipo`); +const Operador = require(`${dbPath}/Operador`); +const Prestamo = require(`${dbPath}/Prestamo`); const cancelarOperador = async (body) => { const idPrestamo = validarId(body.idPrestamo); + const idOperadorCancelacion = validarId(body.idOperadorCancelacion); + + return Operador.findOne({ where: { idOperador: idOperadorCancelacion } }) + .then((res) => { + if (!res) throw new Error('No existe esta este operador.'); + return Prestamo.findOne({ + where: { idPrestamo }, + include: [{ model: Equipo }], + }); + }) - return Prestamo.findOne({ - where: { idPrestamo }, - include: [{ model: Equipo }], - }) .then((res) => { if (!res) throw new Error('Este prestamo no existe.'); if (!res.activo) @@ -27,7 +34,7 @@ const cancelarOperador = async (body) => { }) .then((res) => Prestamo.update( - { activo: false, canceladoOperador: true }, + { activo: false, idOperadorCancelacion }, { where: { idPrestamo } } ) ) diff --git a/server/controller/Prestamo/historial.js b/server/controller/Prestamo/historial.js index 7f60b9e..994850a 100644 --- a/server/controller/Prestamo/historial.js +++ b/server/controller/Prestamo/historial.js @@ -67,6 +67,7 @@ const historial = async (body) => { delete res.rows[i].dataValues.idOperadorEntrega; delete res.rows[i].dataValues.idOperadorRegreso; delete res.rows[i].dataValues.idEquipo; + delete res.rows[i].dataValues.idOperadorCancelacion; delete res.rows[i].dataValues.Equipo.dataValues.idPrograma; delete res.rows[i].dataValues.Equipo.dataValues.idStatus; delete res.rows[i].dataValues.Equipo.dataValues.idCarrito; diff --git a/server/controller/Prestamo/historialEquipo.js b/server/controller/Prestamo/historialEquipo.js index 7e42de5..358a6b3 100644 --- a/server/controller/Prestamo/historialEquipo.js +++ b/server/controller/Prestamo/historialEquipo.js @@ -17,6 +17,7 @@ const historialEquipo = async (body) => { { model: Usuario, include: [{ model: TipoUsuario }, { model: Carrera }] }, { model: Operador, as: 'OperadorRegreso' }, { model: Operador, as: 'OperadorEntrega' }, + { model: Operador, as: 'OperadorCancelacion' }, ], limit: 25, offset: 25 * (pagina - 1), @@ -26,6 +27,7 @@ const historialEquipo = async (body) => { delete res.rows[i].dataValues.idUsuario; delete res.rows[i].dataValues.idOperadorEntrega; delete res.rows[i].dataValues.idOperadorRegreso; + delete res.rows[i].dataValues.idOperadorCancelacion; delete res.rows[i].dataValues.idEquipo; delete res.rows[i].dataValues.Equipo; delete res.rows[i].dataValues.Usuario.dataValues.idTipoUsuario; @@ -43,6 +45,12 @@ const historialEquipo = async (body) => { delete res.rows[i].dataValues.OperadorRegreso.dataValues.activo; delete res.rows[i].dataValues.OperadorRegreso.dataValues.idTipoUsuario; } + if (res.rows[i].OperadorCancelacion) { + delete res.rows[i].dataValues.OperadorCancelacion.dataValues.password; + delete res.rows[i].dataValues.OperadorCancelacion.dataValues.activo; + delete res.rows[i].dataValues.OperadorCancelacion.dataValues + .idTipoUsuario; + } } return { count: res.count, historialEquipo: res.rows }; }); diff --git a/server/controller/Prestamo/historialUsuario.js b/server/controller/Prestamo/historialUsuario.js index be3e9a3..1539293 100644 --- a/server/controller/Prestamo/historialUsuario.js +++ b/server/controller/Prestamo/historialUsuario.js @@ -28,6 +28,7 @@ const historialUsuario = async (body) => { { model: Usuario, where: { idUsuario } }, { model: Operador, as: 'OperadorRegreso' }, { model: Operador, as: 'OperadorEntrega' }, + { model: Operador, as: 'OperadorCancelacion' }, ], limit: 25, offset: 25 * (pagina - 1), @@ -36,6 +37,7 @@ const historialUsuario = async (body) => { for (let i = 0; i < res.rows.length; i++) { delete res.rows[i].dataValues.idOperadorEntrega; delete res.rows[i].dataValues.idOperadorRegreso; + delete res.rows[i].dataValues.idOperadorCancelacion; delete res.rows[i].dataValues.idUsuario; delete res.rows[i].dataValues.idEquipo; delete res.rows[i].dataValues.Usuario; @@ -58,6 +60,12 @@ const historialUsuario = async (body) => { delete res.rows[i].dataValues.OperadorRegreso.dataValues.activo; delete res.rows[i].dataValues.OperadorRegreso.dataValues.idTipoUsuario; } + if (res.rows[i].OperadorCancelacion) { + delete res.rows[i].dataValues.OperadorCancelacion.dataValues.password; + delete res.rows[i].dataValues.OperadorCancelacion.dataValues.activo; + delete res.rows[i].dataValues.OperadorCancelacion.dataValues + .idTipoUsuario; + } } return { count: res.count, historialUsuario: res.rows }; }); diff --git a/server/controller/Prestamo/pedir.js b/server/controller/Prestamo/pedir.js index 4fd46f3..5db4fe9 100644 --- a/server/controller/Prestamo/pedir.js +++ b/server/controller/Prestamo/pedir.js @@ -102,6 +102,7 @@ const pedir = async (body) => { delete res.dataValues.idUsuario; delete res.dataValues.idOperadorEntrega; delete res.dataValues.idOperadorRegreso; + delete res.dataValues.idOperadorCancelacion; delete res.dataValues.idEquipo; delete res.dataValues.Equipo.dataValues.idCarrito; delete res.dataValues.Equipo.dataValues.idStatus; diff --git a/server/controller/Prestamo/prestamo.js b/server/controller/Prestamo/prestamo.js index e475b46..4436487 100644 --- a/server/controller/Prestamo/prestamo.js +++ b/server/controller/Prestamo/prestamo.js @@ -36,6 +36,7 @@ const prestamo = async (body) => { delete res.dataValues.idUsuario; delete res.dataValues.idOperadorEntrega; delete res.dataValues.idOperadorRegreso; + delete res.dataValues.idOperadorCancelacion; delete res.dataValues.idEquipo; delete res.dataValues.Equipo.dataValues.idPrograma; delete res.dataValues.Equipo.dataValues.idStatus; diff --git a/server/controller/Prestamo/prestamoUsuario.js b/server/controller/Prestamo/prestamoUsuario.js index c0d4489..58dde8d 100644 --- a/server/controller/Prestamo/prestamoUsuario.js +++ b/server/controller/Prestamo/prestamoUsuario.js @@ -36,6 +36,7 @@ const prestamo = async (body) => { delete res.dataValues.idUsuario; delete res.dataValues.idOperadorEntrega; delete res.dataValues.idOperadorRegreso; + delete res.dataValues.idOperadorCancelacion; delete res.dataValues.idEquipo; delete res.dataValues.Equipo.dataValues.idPrograma; delete res.dataValues.Equipo.dataValues.idStatus; diff --git a/server/controller/Prestamo/status.js b/server/controller/Prestamo/status.js index b14c0fd..09274d3 100644 --- a/server/controller/Prestamo/status.js +++ b/server/controller/Prestamo/status.js @@ -31,6 +31,7 @@ const status = async (body) => { delete res.dataValues.idUsuario; delete res.dataValues.idOperadorEntrega; delete res.dataValues.idOperadorRegreso; + delete res.dataValues.idOperadorCancelacion; delete res.dataValues.idEquipo; delete res.dataValues.Equipo.dataValues.idPrograma; delete res.dataValues.Equipo.dataValues.idStatus; diff --git a/server/db/tablas/Multa.js b/server/db/tablas/Multa.js index e06d28e..d03b3a6 100644 --- a/server/db/tablas/Multa.js +++ b/server/db/tablas/Multa.js @@ -1,6 +1,7 @@ const { DataTypes, Model } = require('sequelize'); const sequelize = require('../../config/sequelize.conf'); const Infraccion = require('./Infraccion'); +const Operador = require('./Operador'); const Prestamo = require('./Prestamo'); class Multa extends Model {} @@ -48,4 +49,13 @@ Multa.belongsTo(Prestamo, { }, }); +Multa.belongsTo(Operador, { + as: 'OperadorMulta', + foreignKey: { + name: 'idOperadorMulta', + type: DataTypes.INTEGER, + allowNull: false, + }, +}); + module.exports = Multa; diff --git a/server/db/tablas/Prestamo.js b/server/db/tablas/Prestamo.js index 896e8bc..71b820b 100644 --- a/server/db/tablas/Prestamo.js +++ b/server/db/tablas/Prestamo.js @@ -14,6 +14,15 @@ Prestamo.init( unique: true, autoIncrement: true, }, + activo: { + type: DataTypes.BOOLEAN, + allowNull: false, + defaultValue: true, + }, + horaMaxRecoger: { + type: DataTypes.DATE, + allowNull: false, + }, horaInicio: { type: DataTypes.DATE, allowNull: true, @@ -29,25 +38,11 @@ Prestamo.init( allowNull: true, defaultValue: null, }, - horaMaxRecoger: { - type: DataTypes.DATE, - allowNull: false, - }, - activo: { - type: DataTypes.BOOLEAN, - allowNull: false, - defaultValue: true, - }, canceladoUsuario: { type: DataTypes.BOOLEAN, allowNull: true, defaultValue: null, }, - canceladoOperador: { - type: DataTypes.BOOLEAN, - allowNull: true, - defaultValue: null, - }, }, { sequelize, @@ -79,6 +74,16 @@ Prestamo.belongsTo(Operador, { }, }); +Prestamo.belongsTo(Operador, { + as: 'OperadorCancelacion', + foreignKey: { + name: 'idOperadorCancelacion', + type: DataTypes.INTEGER, + allowNull: true, + defaultValue: null, + }, +}); + Prestamo.belongsTo(Usuario, { foreignKey: { name: 'idUsuario',