This commit is contained in:
xXpuma99Xx
2022-02-13 17:29:26 -06:00
parent 25d2112010
commit 8429cd74e3
13 changed files with 53 additions and 35 deletions
+2 -2
View File
@@ -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]: [
@@ -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.'
+15 -5
View File
@@ -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 } }
+8 -7
View File
@@ -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 } });
+1
View File
@@ -88,6 +88,7 @@ const historial = async (body) => {
'horaFin',
'horaEntrega',
'canceladoUsuario',
'canceladoOperador',
'regresoInmediato',
'createdAt',
],
+4 -4
View File
@@ -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({
+3
View File
@@ -52,6 +52,9 @@ const prestamo = async (body) => {
'horaInicio',
'horaFin',
'horaEntrega',
'canceladoUsuario',
'canceladoOperador',
'regresoInmediato',
'createdAt',
],
}).then((res) => {
@@ -38,6 +38,9 @@ const prestamo = async (body) => {
'horaInicio',
'horaFin',
'horaEntrega',
'canceladoUsuario',
'canceladoOperador',
'regresoInmediato',
'createdAt',
],
});
+2 -2
View File
@@ -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;
@@ -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 {
@@ -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({
@@ -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({
+5 -5
View File
@@ -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: [