This commit is contained in:
2022-02-05 21:40:39 -06:00
parent 69cd00bc43
commit 564be23729
6 changed files with 15 additions and 35 deletions
@@ -7,13 +7,9 @@ const Prestamo = require(`${dbPath}/Prestamo`);
const cancelarOperador = async (body) => {
const idPrestamo = validarNumeroEntero(body.idPrestamo, 'id préstamo', true);
const idOperadorCancelacion = validarNumeroEntero(
body.idOperadorCancelacion,
'id operador cancelación',
true
);
const idOperador = validarNumeroEntero(body.idOperador, 'id operador', true);
return Operador.findOne({ where: { idOperador: idOperadorCancelacion } })
return Operador.findOne({ where: { idOperador: idOperador } })
.then((res) => {
if (!res) throw new Error('No existe este operador.');
return Prestamo.findOne({ where: { idPrestamo } });
@@ -31,7 +27,7 @@ const cancelarOperador = async (body) => {
})
.then(() =>
Prestamo.update(
{ activo: false, idOperadorCancelacion },
{ activo: false, idOperador, canceladoOperador: true },
{ where: { idPrestamo } }
)
)
@@ -42,11 +42,6 @@ const historialEquipo = async (body) => {
as: 'OperadorRegreso',
attributes: ['idOperador', 'operador'],
},
{
model: Operador,
as: 'OperadorCancelacion',
attributes: ['idOperador', 'operador'],
},
],
attributes: [
'idPrestamo',
@@ -56,6 +51,7 @@ const historialEquipo = async (body) => {
'horaFin',
'horaEntrega',
'canceladoUsuario',
'canceladoOperador',
'regresoInmediato',
'createdAt',
],
@@ -51,11 +51,6 @@ const historialUsuario = async (body) => {
as: 'OperadorRegreso',
attributes: ['idOperador', 'operador'],
},
{
model: Operador,
as: 'OperadorCancelacion',
attributes: ['idOperador', 'operador'],
},
],
limit: 25,
offset: 25 * (pagina - 1),
@@ -68,6 +63,7 @@ const historialUsuario = async (body) => {
'horaFin',
'horaEntrega',
'canceladoUsuario',
'canceladoOperador',
'regresoInmediato',
'createdAt',
],
+1 -7
View File
@@ -61,10 +61,6 @@ const reporte = async (body) => {
model: Operador,
as: 'OperadorRegreso',
},
{
model: Operador,
as: 'OperadorCancelacion',
},
],
})
.then(async (res) => {
@@ -103,6 +99,7 @@ const reporte = async (body) => {
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,
createdAt: moment(res[i].createdAt).format('YYYY-MM-DD HH:mm'),
numeroInventario: res[i].Equipo.numeroInventario,
numeroSerie: res[i].Equipo.numeroSerie,
@@ -123,9 +120,6 @@ const reporte = async (body) => {
operadorRegreso: res[i].OperadorRegreso
? res[i].OperadorRegreso.operador
: null,
operadorCancelacion: res[i].OperadorCancelacion
? res[i].OperadorCancelacion.operador
: null,
});
}
await helper.eliminarArchivo(path).catch((err) => {});
+4 -1
View File
@@ -36,7 +36,10 @@ const status = async (body) => {
{ idStatus: 4 },
{ where: { idEquipo: res.Equipo.idEquipo } }
).then(() =>
Prestamo.update({ activo: false }, { where: { idPrestamo } })
Prestamo.update(
{ activo: false, canceladoOperador: true, idOperador: 1 },
{ where: { idPrestamo } }
)
);
message =
'Ya paso el tiempo limite para recoger el dispositivo. Se ha cancelado tu prestamo.';
+5 -10
View File
@@ -43,6 +43,11 @@ Prestamo.init(
allowNull: true,
defaultValue: null,
},
canceladoOperador: {
type: DataTypes.BOOLEAN,
allowNull: true,
defaultValue: null,
},
regresoInmediato: {
type: DataTypes.BOOLEAN,
allowNull: true,
@@ -79,16 +84,6 @@ Prestamo.belongsTo(Operador, {
},
});
Prestamo.belongsTo(Operador, {
as: 'OperadorCancelacion',
foreignKey: {
name: 'idOperadorCancelacion',
type: DataTypes.INTEGER,
allowNull: true,
defaultValue: null,
},
});
Prestamo.belongsTo(Usuario, {
foreignKey: {
name: 'idUsuario',