mini cambios

This commit is contained in:
xXpuma99Xx
2022-02-13 13:34:54 -06:00
parent e23d4f15f5
commit 25d2112010
11 changed files with 38 additions and 65 deletions
+5 -4
View File
@@ -16,17 +16,18 @@ const update = async (body) => {
return TipoCarrito.findOne({ where: { idTipoCarrito } })
.then((res) => {
if (idTipoCarrito && !res)
throw new Error('No existe este tipo carrito.');
if (idTipoCarrito) {
if (!res) throw new Error('No existe este tipo carrito.');
update.idTipoCarrito = idTipoCarrito;
}
return Carrito.findOne({ where: { idCarrito } });
})
.then((res) => {
if (!res) throw new Error('No existe este carrito.');
if (idTipoCarrito) update.idTipoCarrito = idTipoCarrito;
if (body.activo === 'desactivar') update.activo = false;
else if (body.activo === 'activar') update.activo = true;
if (validar.validarObjetoVacio(update))
throw new Error('No se envio nada para actualizar.');
throw new Error('No se envió nada para actualizar.');
return Carrito.update(update, { where: { idCarrito } });
})
.then(() => ({ message: 'Se actualizó correctamente el carrito.' }));
+1 -1
View File
@@ -43,7 +43,7 @@ const update = async (body) => {
update.idPrograma = idPrograma;
}
if (validar.validarObjetoVacio(update))
throw new Error('No se envio nada para actualizar.');
throw new Error('No se envió nada para actualizar.');
return Equipo.findOne({ where: { idEquipo } });
})
.then((res) => {
@@ -13,17 +13,7 @@ const historialMultasEquipo = async (body) => {
{
model: Prestamo,
where: { idEquipo },
attributes: [
'idPrestamo',
'activo',
'horaMaxRecoger',
'horaInicio',
'horaFin',
'horaEntrega',
'canceladoUsuario',
'regresoInmediato',
'createdAt',
],
attributes: ['idPrestamo'],
},
{
model: Operador,
@@ -18,35 +18,25 @@ const historialMultasUsuario = async (body) => {
{
model: Prestamo,
where: { idUsuario },
include: [
{
model: Equipo,
include: [
{
model: Carrito,
include: [{ model: Modulo }, { model: TipoCarrito }],
attributes: ['idCarrito', 'carrito'],
},
],
attributes: [
'idEquipo',
'numeroSerie',
'numeroInventario',
'equipo',
],
},
],
attributes: [
'idPrestamo',
'activo',
'horaMaxRecoger',
'horaInicio',
'horaFin',
'horaEntrega',
'canceladoUsuario',
'regresoInmediato',
'createdAt',
],
// include: [
// {
// model: Equipo,
// include: [
// {
// model: Carrito,
// include: [{ model: Modulo }, { model: TipoCarrito }],
// attributes: ['idCarrito', 'carrito'],
// },
// ],
// attributes: [
// 'idEquipo',
// 'numeroSerie',
// 'numeroInventario',
// 'equipo',
// ],
// },
// ],
attributes: ['idPrestamo'],
},
{
model: Operador,
+1 -1
View File
@@ -21,7 +21,7 @@ const crear = async (body) => {
idTipoUsuario: 2,
});
})
.then(() => ({ message: 'Se creo un nuevo operador correctamente.' }));
.then(() => ({ message: 'Se creó un nuevo operador correctamente.' }));
};
module.exports = crear;
+1 -1
View File
@@ -16,7 +16,7 @@ const historial = async (body) => {
const usuario = body.usuario ? validar.validarNumeroCuenta(body.usuario) : '';
const idPrestamo = body.idPrestamo
? validar.validarNumeroEntero(body.idPrestamo, 'id préstamo', true)
: '';
: null;
const numeroInventario = body.numeroInventario
? validar.validarAlfanumerico(
body.numeroInventario,
+5 -5
View File
@@ -21,13 +21,13 @@ const reporte = async (body) => {
const fin = validar.validarFecha(body.fin, 'fecha fin', false);
const idCarrera = body.idCarrera
? validar.validarNumeroEntero(body.idCarrera, 'id carrera', true)
: '';
: null;
const idTipoUsuario = body.idTipoUsuario
? validar.validarNumeroEntero(body.idTipoUsuario, 'id tipo usuario', true)
: '';
: null;
const idTipoCarrito = body.idTipoCarrito
? validar.validarNumeroEntero(body.idTipoCarrito, 'id tipo carrito', true)
: '';
: null;
const path = `server/uploads/reporte.csv`;
const data = [];
@@ -98,8 +98,8 @@ const reporte = async (body) => {
horaInicio: moment(res[i].horaInicio).format('YYYY-MM-DD HH:mm'),
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,
canceladoUsuario: res[i].canceladoUsuario ? 'si' : 'no',
canceladoOperador: res[i].canceladoOperador ? 'si' : 'no',
createdAt: moment(res[i].createdAt).format('YYYY-MM-DD HH:mm'),
numeroInventario: res[i].Equipo.numeroInventario,
numeroSerie: res[i].Equipo.numeroSerie,
-1
View File
@@ -20,7 +20,6 @@ const crear = async (body) => {
.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.');
email = `${res.usuario}@pcpuma.acatlan.unam.mx`;
correo = correoPcPuma(password);
return Usuario.update(
+2 -2
View File
@@ -18,11 +18,11 @@ const login = async (body) => {
return Usuario.findOne({
where: { usuario, password: { [Op.ne]: null } },
attributes: ['idUsuario', 'password', 'multa', 'activo'],
attributes: ['idUsuario', 'password', 'activo'],
})
.then((res) => {
if (!res) throw new Error('No existe este usuario.');
if (!res.activo) throw new Error('Este usuario fue desactivado.');
if (!res.activo) throw new Error('Este cuenta se encuentra desactivada.');
if (!comparar(password, res.password))
throw new Error('La contraseña es incorrecta.');
return Usuario.findOne({
+1 -1
View File
@@ -14,7 +14,7 @@ const quitarMulta = async (body) => {
if (!res.multa) throw new Error('Este usuario no tiene multa.');
return Usuario.update({ multa: false }, { where: { idUsuario } });
})
.then((res) => ({
.then(() => ({
message: 'Se le quitó la multa a este usuario.',
}));
};
+2 -9
View File
@@ -6,21 +6,14 @@ const TipoUsuario = require(`${dbPath}/TipoUsuario`);
const Usuario = require(`${dbPath}/Usuario`);
const usuarios = async (body) => {
const pagina = validar.validarNumero(
body.pagina,
'página',
false,
null,
true,
true
);
const pagina = validar.validarNumeroEntero(body.pagina, 'página', false);
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)
: '';
: null;
return Usuario.findAndCountAll({
where: {