mini cambios#
This commit is contained in:
@@ -3,11 +3,10 @@ const Carrito = require(`${dbPath}/Carrito`);
|
||||
const Modulo = require(`${dbPath}/Modulo`);
|
||||
const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
||||
|
||||
const carritos = async () => {
|
||||
return Carrito.findAll({
|
||||
const carritos = async () =>
|
||||
Carrito.findAll({
|
||||
include: [{ model: TipoCarrito }, { model: Modulo }],
|
||||
attributes: ['idCarrito', 'sobrenombre', 'activo'],
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = carritos;
|
||||
|
||||
@@ -95,15 +95,17 @@ const cargaMasiva = async (file) => {
|
||||
{
|
||||
model: Carrito,
|
||||
include: [{ model: TipoCarrito }, { model: Modulo }],
|
||||
attributes: ['idCarrito', 'sobrenombre'],
|
||||
},
|
||||
],
|
||||
attributes: [
|
||||
'idEquipo',
|
||||
'numeroSerie',
|
||||
'numeroInventario',
|
||||
'sobrenombre',
|
||||
],
|
||||
})
|
||||
);
|
||||
delete existeEquipo.dataValues.idStatus;
|
||||
delete existeEquipo.dataValues.idCarrito;
|
||||
delete existeEquipo.dataValues.idPrograma;
|
||||
delete existeEquipo.dataValues.Carrito.dataValues.idModulo;
|
||||
delete existeEquipo.dataValues.Carrito.dataValues.idTipoCarrito;
|
||||
equiposNuevos.push(existeEquipo);
|
||||
}
|
||||
await eliminarArchivo(path);
|
||||
|
||||
@@ -4,8 +4,8 @@ const Equipo = require(`${dbPath}/Equipo`);
|
||||
const Modulo = require(`${dbPath}/Modulo`);
|
||||
const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
||||
|
||||
const equipos = async () => {
|
||||
return Carrito.findAll({
|
||||
const equipos = async () =>
|
||||
Carrito.findAll({
|
||||
include: [{ model: TipoCarrito }, { model: Modulo }],
|
||||
attributes: ['idCarrito', 'sobrenombre', 'activo'],
|
||||
}).then(async (res) => {
|
||||
@@ -21,6 +21,5 @@ const equipos = async () => {
|
||||
});
|
||||
return res;
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = equipos;
|
||||
|
||||
@@ -22,24 +22,30 @@ const update = async (body) => {
|
||||
: null;
|
||||
let update = {};
|
||||
|
||||
if (idStatus)
|
||||
await Status.findOne({ where: { idStatus } }).then((res) => {
|
||||
if (!res) throw new Error('No existe este status.');
|
||||
update.idStatus = idStatus;
|
||||
});
|
||||
if (idCarrito)
|
||||
await Carrito.findOne({ where: { idCarrito } }).then((res) => {
|
||||
if (!res) throw new Error('No existe este carrito.');
|
||||
update.idCarrito = idCarrito;
|
||||
});
|
||||
if (idPrograma)
|
||||
await Programa.findOne({ where: { idPrograma } }).then((res) => {
|
||||
if (!res) throw new Error('No existe este programa.');
|
||||
update.idPrograma = idPrograma;
|
||||
});
|
||||
if (validar.validarObjetoVacio(update))
|
||||
throw new Error('No se envio nada para actualizar.');
|
||||
return Equipo.findOne({ where: { idEquipo } })
|
||||
return Status.findOne({ where: { idStatus } })
|
||||
.then((res) => {
|
||||
if (idStatus) {
|
||||
if (!res) throw new Error('No existe este status.');
|
||||
update.idStatus = idStatus;
|
||||
}
|
||||
return Carrito.findOne({ where: { idCarrito } });
|
||||
})
|
||||
.then((res) => {
|
||||
if (idCarrito) {
|
||||
if (!res) throw new Error('No existe este carrito.');
|
||||
update.idCarrito = idCarrito;
|
||||
}
|
||||
return Programa.findOne({ where: { idPrograma } });
|
||||
})
|
||||
.then((res) => {
|
||||
if (idPrograma) {
|
||||
if (!res) throw new Error('No existe este programa.');
|
||||
update.idPrograma = idPrograma;
|
||||
}
|
||||
if (validar.validarObjetoVacio(update))
|
||||
throw new Error('No se envio nada para actualizar.');
|
||||
return Equipo.findOne({ where: { idEquipo } });
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe este equipo.');
|
||||
return Equipo.update(update, { where: { idEquipo } });
|
||||
|
||||
@@ -45,7 +45,7 @@ const historialMultasEquipo = async (body) => {
|
||||
limit: 25,
|
||||
offset: 25 * (pagina - 1),
|
||||
order: [['createdAt', 'DESC']],
|
||||
}).then((res) => ({ count: res.count, historialMultasEquipo: res.rows }));
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = historialMultasEquipo;
|
||||
|
||||
@@ -58,18 +58,18 @@ const historialMultasUsuario = async (body) => {
|
||||
'createdAt',
|
||||
],
|
||||
},
|
||||
{ model: Infraccion },
|
||||
{
|
||||
model: Operador,
|
||||
as: 'OperadorMulta',
|
||||
attributes: ['idOperador', 'operador'],
|
||||
},
|
||||
{ model: Infraccion },
|
||||
],
|
||||
attributes: ['idMulta', 'descripcion', 'fechaFin', 'createdAt'],
|
||||
limit: 25,
|
||||
offset: 25 * (pagina - 1),
|
||||
order: [['createdAt', 'DESC']],
|
||||
}).then((res) => ({ count: res.count, historialMultasUsuario: res.rows }));
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = historialMultasUsuario;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
const { Op } = require('sequelize');
|
||||
const validar = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Operador = require(`${dbPath}/Operador`);
|
||||
@@ -12,15 +13,17 @@ const operadores = async (body) => {
|
||||
true,
|
||||
true
|
||||
);
|
||||
// filtros
|
||||
const operador = body.operador
|
||||
? validar.validarTexto(body.operador, 'operador', true, 20)
|
||||
: '';
|
||||
|
||||
return Operador.findAndCountAll({
|
||||
where: { idTipoUsuario: 2 },
|
||||
where: { idTipoUsuario: 2, operador: { [Op.like]: `%${operador}%` } },
|
||||
include: [{ model: TipoUsuario }],
|
||||
attributes: ['idOperador', 'operador', 'activo'],
|
||||
limit: 25,
|
||||
offset: 25 * (pagina - 1),
|
||||
}).then((res) => ({ count: res.count, operadores: res.rows }));
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = operadores;
|
||||
|
||||
@@ -9,19 +9,19 @@ const update = async (body) => {
|
||||
'id operador',
|
||||
true
|
||||
);
|
||||
const password = body.password
|
||||
? validar.validarAlfanumerico(body.password, 'contraseña', false, 20)
|
||||
: '';
|
||||
let update = {};
|
||||
|
||||
if (body.activo === 'desactivar') update.activo = false;
|
||||
else if (body.activo === 'activar') update.activo = true;
|
||||
if (body.password)
|
||||
update.password = encriptar(
|
||||
validar.validarAlfanumerico(body.password, 'contraseña', false, 20)
|
||||
);
|
||||
if (validar.validarObjetoVacio(update))
|
||||
throw new Error('No se mando nada para actualizar.');
|
||||
return Operador.findOne({ where: { idOperador, idTipoUsuario: 2 } })
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe este operador.');
|
||||
if (body.activo === 'desactivar') update.activo = false;
|
||||
else if (body.activo === 'activar') update.activo = true;
|
||||
if (password) update.password = encriptar(password);
|
||||
if (validar.validarObjetoVacio(update))
|
||||
throw new Error('No se mando nada para actualizar.');
|
||||
return Operador.update(update, { where: { idOperador } });
|
||||
})
|
||||
.then((res) => ({ message: 'Se actualizó correctamente al operador.' }));
|
||||
|
||||
@@ -43,53 +43,51 @@ const activos = async (body) => {
|
||||
let whereCarrito = [{ idModulo }];
|
||||
|
||||
if (idTipoCarrito) whereCarrito.push({ idTipoCarrito });
|
||||
return Modulo.findOne({ where: { idModulo } })
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe este modulo.');
|
||||
return Prestamo.findAndCountAll({
|
||||
where: { activo: true, idPrestamo: { [Op.like]: `%${idPrestamo}%` } },
|
||||
include: [
|
||||
{
|
||||
model: Equipo,
|
||||
where: { numeroInventario: { [Op.like]: `%${numeroInventario}%` } },
|
||||
include: [
|
||||
{
|
||||
model: Carrito,
|
||||
where: { [Op.and]: whereCarrito },
|
||||
include: [{ model: TipoCarrito }, { model: Modulo }],
|
||||
attributes: ['idCarrito', 'sobrenombre'],
|
||||
},
|
||||
{ model: Status },
|
||||
],
|
||||
attributes: [
|
||||
'idEquipo',
|
||||
'numeroSerie',
|
||||
'numeroInventario',
|
||||
'sobrenombre',
|
||||
],
|
||||
},
|
||||
{
|
||||
model: Usuario,
|
||||
where: { usuario: { [Op.like]: `%${usuario}%` } },
|
||||
include: [{ model: TipoUsuario }, { model: Carrera }],
|
||||
attributes: ['idUsuario', 'usuario', 'nombre'],
|
||||
},
|
||||
],
|
||||
attributes: [
|
||||
'idPrestamo',
|
||||
'activo',
|
||||
'horaMaxRecoger',
|
||||
'horaInicio',
|
||||
'horaFin',
|
||||
'horaEntrega',
|
||||
'createdAt',
|
||||
],
|
||||
limit: 25,
|
||||
offset: 25 * (pagina - 1),
|
||||
order: [['createdAt', 'DESC']],
|
||||
});
|
||||
})
|
||||
.then((res) => ({ count: res.count, activos: res.rows }));
|
||||
return Modulo.findOne({ where: { idModulo } }).then((res) => {
|
||||
if (!res) throw new Error('No existe este modulo.');
|
||||
return Prestamo.findAndCountAll({
|
||||
where: { activo: true, idPrestamo: { [Op.like]: `%${idPrestamo}%` } },
|
||||
include: [
|
||||
{
|
||||
model: Equipo,
|
||||
where: { numeroInventario: { [Op.like]: `%${numeroInventario}%` } },
|
||||
include: [
|
||||
{
|
||||
model: Carrito,
|
||||
where: { [Op.and]: whereCarrito },
|
||||
include: [{ model: TipoCarrito }, { model: Modulo }],
|
||||
attributes: ['idCarrito', 'sobrenombre'],
|
||||
},
|
||||
{ model: Status },
|
||||
],
|
||||
attributes: [
|
||||
'idEquipo',
|
||||
'numeroSerie',
|
||||
'numeroInventario',
|
||||
'sobrenombre',
|
||||
],
|
||||
},
|
||||
{
|
||||
model: Usuario,
|
||||
where: { usuario: { [Op.like]: `%${usuario}%` } },
|
||||
include: [{ model: TipoUsuario }, { model: Carrera }],
|
||||
attributes: ['idUsuario', 'usuario', 'nombre'],
|
||||
},
|
||||
],
|
||||
attributes: [
|
||||
'idPrestamo',
|
||||
'activo',
|
||||
'horaMaxRecoger',
|
||||
'horaInicio',
|
||||
'horaFin',
|
||||
'horaEntrega',
|
||||
'createdAt',
|
||||
],
|
||||
limit: 25,
|
||||
offset: 25 * (pagina - 1),
|
||||
order: [['createdAt', 'DESC']],
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = activos;
|
||||
|
||||
@@ -20,7 +20,6 @@ const cancelarOperador = async (body) => {
|
||||
include: [{ model: Equipo }],
|
||||
});
|
||||
})
|
||||
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('Este prestamo no existe.');
|
||||
if (!res.activo)
|
||||
|
||||
@@ -100,7 +100,7 @@ const historial = async (body) => {
|
||||
limit: 25,
|
||||
offset: 25 * (pagina - 1),
|
||||
order: [['createdAt', 'DESC']],
|
||||
}).then((res) => ({ count: res.count, historial: res.rows }));
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = historial;
|
||||
|
||||
@@ -68,7 +68,7 @@ const historialEquipo = async (body) => {
|
||||
limit: 25,
|
||||
offset: 25 * (pagina - 1),
|
||||
order: [['createdAt', 'DESC']],
|
||||
}).then((res) => ({ count: res.count, historialEquipo: res.rows }));
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = historialEquipo;
|
||||
|
||||
@@ -77,7 +77,7 @@ const historialUsuario = async (body) => {
|
||||
'canceladoUsuario',
|
||||
'createdAt',
|
||||
],
|
||||
}).then((res) => ({ count: res.count, historialUsuario: res.rows }));
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = historialUsuario;
|
||||
|
||||
@@ -12,14 +12,15 @@ const crear = async (body) => {
|
||||
);
|
||||
const telefono = validar.validarNumero(body.telefono, 'teléfono', true, 15);
|
||||
const password = encriptar.generarPassword();
|
||||
let correo = '@pcpuma.acatlan.unam.mx';
|
||||
let correo = '';
|
||||
|
||||
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 + correo;
|
||||
// correo = `${res.usuario}@pcpuma.acatlan.unam.mx`;
|
||||
correo = 'lemuelhelonmarquezrosas@gmail.com';
|
||||
return Usuario.update(
|
||||
{
|
||||
password: encriptar.encriptar(password),
|
||||
@@ -28,10 +29,7 @@ const crear = async (body) => {
|
||||
{ where: { idUsuario } }
|
||||
);
|
||||
})
|
||||
.then((res) => {
|
||||
// return gmail('Contraseña',correo,"")
|
||||
return gmail('Contraseña', 'lemuelhelonmarquezrosas@gmail.com', password);
|
||||
})
|
||||
.then((res) => gmail('Contraseña', correo, password))
|
||||
.then((res) => ({
|
||||
message:
|
||||
'Se creó correctamente tu cuenta, ingresa a tu correo @pcpuma para consultar tu contraseña para este servicio.',
|
||||
|
||||
@@ -14,22 +14,26 @@ const usuarios = async (body) => {
|
||||
true,
|
||||
true
|
||||
);
|
||||
// filtros
|
||||
const usuario = body.usuario ? validar.validarNumeroCuenta(body.usuario) : '';
|
||||
const nombre = body.nombre
|
||||
? validar.validarTexto(body.nombre, 'nombre', true, 70)
|
||||
: '';
|
||||
const idTipoUsuario = body.idTipoUsuario
|
||||
? validar.validarNumeroEntero(body.idTipoUsuario, 'id tipo usuario', true)
|
||||
: '';
|
||||
|
||||
return Usuario.findAndCountAll({
|
||||
where: { password: { [Op.ne]: null } },
|
||||
where: {
|
||||
usuario: { [Op.like]: `%${usuario}%` },
|
||||
nombre: { [Op.like]: `%${nombre}%` },
|
||||
password: { [Op.ne]: null },
|
||||
idTipoUsuario: { [Op.like]: `%${idTipoUsuario}%` },
|
||||
},
|
||||
include: [{ model: TipoUsuario }, { model: Carrera }],
|
||||
attributes: [
|
||||
'idUsuario',
|
||||
'usuario',
|
||||
'nombre',
|
||||
'telefono',
|
||||
'multa',
|
||||
'activo',
|
||||
],
|
||||
attributes: ['idUsuario', 'usuario', 'nombre', 'multa', 'activo'],
|
||||
limit: 25,
|
||||
offset: 25 * (pagina - 1),
|
||||
}).then((res) => ({ count: res.count, usuarios: res.rows }));
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = usuarios;
|
||||
|
||||
Reference in New Issue
Block a user