This commit is contained in:
2022-02-05 21:22:51 -06:00
parent 3f360879e6
commit 69cd00bc43
7 changed files with 86 additions and 41 deletions
+20 -20
View File
@@ -17,6 +17,7 @@ const regresar = async (body) => {
'id operador regreso',
true
);
const update = { idOperadorRegreso };
let diferencia = null;
return Operador.findOne({ where: { idOperador: idOperadorRegreso } })
@@ -33,31 +34,30 @@ const regresar = async (body) => {
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.');
diferencia = parseInt((ahora - moment(res.horaFin)) / 60000);
if (diferencia >= 15)
await Multa.create({
idPrestamo,
idInfraccion: 1,
idOperadorMulta: idOperadorRegreso,
descripcion: `Se paso por ${diferencia} minutos para entregar el equipo.`,
fechaFin: ahoraAux.add(parseInt(diferencia / 15) * 7, 'd').format(),
}).then((res) =>
Usuario.update(
{ multa: true },
{ where: { idUsuario: res.idUsuario } }
)
);
if (!res.regresoInmediato) {
update.horaEntrega = ahora.format();
update.activo = false;
diferencia = parseInt((ahora - moment(res.horaFin)) / 60000);
if (diferencia >= 15)
await Multa.create({
idPrestamo,
idInfraccion: 1,
idOperadorMulta: 1,
descripcion: `Se paso por ${diferencia} minutos para entregar el equipo.`,
fechaFin: ahoraAux.add(parseInt(diferencia / 15) * 7, 'd').format(),
}).then((res) =>
Usuario.update(
{ multa: true },
{ where: { idUsuario: res.idUsuario } }
)
);
}
return Equipo.update(
{ idStatus: 4 },
{ where: { idEquipo: res.idEquipo } }
);
})
.then(() =>
Prestamo.update(
{ idOperadorRegreso, horaEntrega: ahora.format(), activo: false },
{ where: { idPrestamo } }
)
)
.then(() => Prestamo.update(update, { where: { idPrestamo } }))
.then(() => {
io.getIO().emit('actualizar');
return {
@@ -7,6 +7,7 @@ const Equipo = require(`${dbPath}/Equipo`);
const Multa = require(`${dbPath}/Multa`);
const Operador = require(`${dbPath}/Operador`);
const Prestamo = require(`${dbPath}/Prestamo`);
const Usuario = require(`${dbPath}/Usuario`);
const regresarNumeroInventario = async (body) => {
const ahora = moment();
@@ -22,6 +23,7 @@ const regresarNumeroInventario = async (body) => {
'id operador regreso',
true
);
const update = { idOperadorRegreso };
let diferencia = null;
let idPrestamo = null;
@@ -49,25 +51,31 @@ const regresarNumeroInventario = async (body) => {
if (res.Equipo.idStatus === 1)
throw new Error('Aun no se ha entregado el equipo al usuario.');
idPrestamo = res.idPrestamo;
diferencia = parseInt((ahora - moment(res.horaFin)) / 60000);
if (diferencia >= 15)
await Multa.create({
idPrestamo,
idInfraccion: 1,
idOperadorMulta: idOperadorRegreso,
descripcion: `Se paso por ${diferencia} minutos para entregar el equipo.`,
fechaFin: ahoraAux.add(parseInt(diferencia / 15) * 7, 'd').format(),
});
if (!res.regresoInmediato) {
update.horaEntrega = ahora.format();
update.activo = false;
diferencia = parseInt((ahora - moment(res.horaFin)) / 60000);
if (diferencia >= 15)
await Multa.create({
idPrestamo,
idInfraccion: 1,
idOperadorMulta: 1,
descripcion: `Se paso por ${diferencia} minutos para entregar el equipo.`,
fechaFin: ahoraAux.add(parseInt(diferencia / 15) * 7, 'd').format(),
}).then((res) =>
Usuario.update(
{ multa: true },
{ where: { idUsuario: res.idUsuario } }
)
);
}
return Equipo.update(
{ idStatus: 4 },
{ where: { idEquipo: res.idEquipo } }
);
})
.then(() => {
Prestamo.update(
{ idOperadorRegreso, horaEntrega: ahora.format(), activo: false },
{ where: { idPrestamo } }
);
Prestamo.update(update, { where: { idPrestamo } });
})
.then(() => {
io.getIO().emit('actualizar');
@@ -27,6 +27,7 @@ const regresoInmediato = async (body) => {
await Multa.create({
idPrestamo,
idInfraccion: 1,
idOperadorMulta: 1,
descripcion: `Se paso por ${diferencia} minutos para entregar el equipo.`,
fechaFin: ahoraAux.add(parseInt(diferencia / 15) * 7, 'd').format(),
}).then((res) =>
@@ -33,6 +33,7 @@ const regresoInmediatoNumeroInventario = async (body) => {
await Multa.create({
idPrestamo,
idInfraccion: 1,
idOperadorMulta: 1,
descripcion: `Se paso por ${diferencia} minutos para entregar el equipo.`,
fechaFin: ahoraAux.add(parseInt(diferencia / 15) * 7, 'd').format(),
}).then((res) =>
+8 -6
View File
@@ -1,6 +1,7 @@
const helperPath = '../../helper';
const gmail = require(`${helperPath}/gmail`);
const correoPcPuma = require(`${helperPath}/correo`);
const encriptar = require(`${helperPath}/encriptar`);
const gmail = require(`${helperPath}/gmail`);
const validar = require(`${helperPath}/validar`);
const Usuario = require('../../db/tablas/Usuario');
@@ -12,15 +13,16 @@ const crear = async (body) => {
);
const telefono = validar.validarNumero(body.telefono, 'teléfono', true, 15);
const password = encriptar.generarPassword();
let correo = '';
let correo = {};
let email = '';
return Usuario.findOne({ where: { idUsuario } })
.then((res) => {
if (!res) throw new Error('No existe este usuario.');
if (res.password) throw new Error('Este usuario ya fue registrado.');
if (!res.activo) throw new Error('Este usuario no esta activo.');
// correo = `${res.usuario}@pcpuma.acatlan.unam.mx`;
correo = 'lemuelhelonmarquezrosas@gmail.com';
email = `${res.usuario}@pcpuma.acatlan.unam.mx`;
correo = correoPcPuma(password);
return Usuario.update(
{
password: encriptar.encriptar(password),
@@ -29,8 +31,8 @@ const crear = async (body) => {
{ where: { idUsuario } }
);
})
.then((res) => gmail('Contraseña', correo, password))
.then((res) => ({
.then(() => gmail(correo.subject, email, correo.msj))
.then(() => ({
message:
'Se creó correctamente tu cuenta, ingresa a tu correo @pcpuma para consultar tu contraseña para este servicio.',
}));