Compare commits
112 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0c51bd1b35 | |||
| 0f8237a205 | |||
| 19f436b325 | |||
| 1fc4734079 | |||
| 173140257a | |||
| 8192645db6 | |||
| 2ec1584064 | |||
| df96fc3f6a | |||
| 51851a500f | |||
| 7d18612953 | |||
| ec27f5b542 | |||
| 2809958203 | |||
| c04ca252df | |||
| b33deda664 | |||
| 9af53a7859 | |||
| 1137eb5d91 | |||
| f303e5c869 | |||
| 2dfbc7708b | |||
| 9799336008 | |||
| 96e5121119 | |||
| 02ec8c2b73 | |||
| 2a8c990358 | |||
| 387603650d | |||
| d63ca1e05c | |||
| 456967b036 | |||
| d5413a5fe8 | |||
| c4e233c696 | |||
| e1b0e21ed7 | |||
| 5f5a0e9e28 | |||
| 1d1461cf1b | |||
| 7177449531 | |||
| 5aa6544e30 | |||
| 9741afc8ae | |||
| 8599203a80 | |||
| 48d882bbd2 | |||
| d2751a07f1 | |||
| ee27a9db64 | |||
| 9c321c622f | |||
| d38ede21d5 | |||
| dfa0951a49 | |||
| 70cc64a813 | |||
| 0504d8c947 | |||
| 3fe19b0350 | |||
| 1f69b98585 | |||
| cb52150249 | |||
| e27646fc0f | |||
| de1bb72c20 | |||
| 8de1aa564e | |||
| f7f4fbf617 | |||
| 27e3aa52cf | |||
| 9dabe6f502 | |||
| 8e1592f769 | |||
| cd90641c07 | |||
| e285fe893d | |||
| 8429cd74e3 | |||
| 25d2112010 | |||
| e23d4f15f5 | |||
| fb1f3d8258 | |||
| 79f61d5a1e | |||
| 7555a28093 | |||
| 1cf61c3d88 | |||
| 258e0c4feb | |||
| 7a79f3109a | |||
| 4e60b25996 | |||
| 28c86b9bfb | |||
| 9fa297e612 | |||
| 3960ed1e95 | |||
| e7c966313e | |||
| b9aeb96d91 | |||
| a3010af959 | |||
| 66e8144417 | |||
| 6c90b0339f | |||
| 85c1a6a63f | |||
| c9c388b6c6 | |||
| c535ecc28a | |||
| 564be23729 | |||
| 69cd00bc43 | |||
| 3f360879e6 | |||
| c52ed2c0cd | |||
| c1998a0b1e | |||
| 1d5eaf8c97 | |||
| 658f37820d | |||
| 262d44a519 | |||
| 4435544e9b | |||
| 33fa2bebdb | |||
| 1bd65011c4 | |||
| 4437ade10c | |||
| b3851fd6a1 | |||
| f0cd2fa0b2 | |||
| f32ce95a55 | |||
| 6ac74c5232 | |||
| 833dc127be | |||
| e8f9a96ecf | |||
| ffadb76178 | |||
| 9af90dc0cf | |||
| 539933e065 | |||
| 0b6c48c7ac | |||
| b1970fe4a5 | |||
| 8d302d43b0 | |||
| d81d6d8be2 | |||
| 07e160d8b8 | |||
| 1b32dcb96a | |||
| 7b5a6262ee | |||
| b3cc4a594d | |||
| a8335ffe1b | |||
| dd4af627f5 | |||
| 1d93d9f5fa | |||
| 3a8f02d3ee | |||
| de4007768a | |||
| 2bda454e1c | |||
| 648af4ed38 | |||
| f8766e199e |
@@ -2,3 +2,4 @@ node_modules/
|
||||
|
||||
.env
|
||||
|
||||
server/uploads/*
|
||||
Generated
+1152
-963
File diff suppressed because it is too large
Load Diff
+2
-1
@@ -12,7 +12,7 @@
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": ""
|
||||
"url": "https://repositorio.acatlan.unam.mx/CIDWA/pcpuma_acatlan_api.git"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
@@ -31,6 +31,7 @@
|
||||
"moment": "^2.29.1",
|
||||
"multer": "^1.4.2",
|
||||
"sequelize": "^6.6.2",
|
||||
"socket.io": "^4.4.1",
|
||||
"validator": "^13.6.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
+5
-4
@@ -4,6 +4,9 @@ const bodyParser = require('body-parser');
|
||||
const cors = require('cors');
|
||||
const express = require('express');
|
||||
const app = express();
|
||||
const { createServer } = require('http');
|
||||
const httpServer = createServer(app);
|
||||
const io = require('./socket').init(httpServer);
|
||||
|
||||
app.use(cors());
|
||||
|
||||
@@ -19,8 +22,6 @@ app.get('/', (req, res) => res.send('API Pcpuma'));
|
||||
|
||||
app.use(require('./routes/index'));
|
||||
|
||||
app.listen(Number(process.env.PORT), () =>
|
||||
console.log(
|
||||
`API Pcpuma corriendo en el puerto: ${process.env.PORT}`.rainbow
|
||||
)
|
||||
httpServer.listen(Number(process.env.PORT), () =>
|
||||
console.log(`API Pcpuma corriendo en el puerto: ${process.env.PORT}`.rainbow)
|
||||
);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
require('./config');
|
||||
const mariadb = require('mariadb');
|
||||
require('./config');
|
||||
|
||||
const pool = mariadb.createPool({
|
||||
host: process.env.ESCOLARES_HOST,
|
||||
@@ -29,7 +29,7 @@ const obtenerAlumno = async (numeroCuenta) => {
|
||||
})
|
||||
.catch((err) => {
|
||||
conn.end();
|
||||
throw new Error('Hubo un problema con el querry.' + err);
|
||||
throw new Error('Hubo un problema, intenta más tarde.');
|
||||
});
|
||||
};
|
||||
|
||||
@@ -39,7 +39,9 @@ const obtenerProfesor = async (numeroCuenta) => {
|
||||
});
|
||||
|
||||
return conn
|
||||
.query(`SELECT * FROM Profesor WHERE NumTrabajador = ${numeroCuenta}`)
|
||||
.query(
|
||||
`SELECT * FROM ${process.env.TABLA_PROFESORES} WHERE NumTrabajador = ${numeroCuenta}`
|
||||
)
|
||||
.then((rows) => {
|
||||
conn.end();
|
||||
if (rows.length === 0) return null;
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
const Carrera = require('../../db/tablas/Carrera');
|
||||
|
||||
const get = async () => Carrera.findAll();
|
||||
|
||||
module.exports = get;
|
||||
@@ -1,19 +1,18 @@
|
||||
const { validarId } = require('../../helper/validar');
|
||||
const { validarNumeroEntero } = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Carrito = require(`${dbPath}/Carrito`);
|
||||
const Modulo = require(`${dbPath}/Modulo`);
|
||||
const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
||||
|
||||
const carrito = async (body) => {
|
||||
const idCarrito = validarId(body.idCarrito);
|
||||
const idCarrito = validarNumeroEntero(body.idCarrito, 'id carrito', true);
|
||||
|
||||
return Carrito.findOne({
|
||||
where: { idCarrito },
|
||||
include: [{ model: TipoCarrito }, { model: Modulo }],
|
||||
attributes: ['idCarrito', 'carrito', 'activo'],
|
||||
}).then((res) => {
|
||||
if (!res) throw new Error('No existe este carrito.');
|
||||
delete res.dataValues.idTipoCarrito;
|
||||
delete res.dataValues.idModulo;
|
||||
return res;
|
||||
});
|
||||
};
|
||||
|
||||
@@ -3,16 +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 }],
|
||||
}).then((res) => {
|
||||
for (let i = 0; i < res.length; i++) {
|
||||
delete res[i].dataValues.idTipoCarrito;
|
||||
delete res[i].dataValues.idModulo;
|
||||
}
|
||||
return res;
|
||||
attributes: ['idCarrito', 'carrito', 'activo'],
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = carritos;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const { validarId } = require('../../helper/validar');
|
||||
const { validarNumeroEntero } = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Carrito = require(`${dbPath}/Carrito`);
|
||||
const Equipo = require(`${dbPath}/Equipo`);
|
||||
@@ -6,24 +6,16 @@ const Programa = require(`${dbPath}/Programa`);
|
||||
const Status = require(`${dbPath}/Status`);
|
||||
|
||||
const equiposCarrito = async (body) => {
|
||||
const idCarrito = validarId(body.idCarrito);
|
||||
const idCarrito = validarNumeroEntero(body.idCarrito, 'id carrito', true);
|
||||
|
||||
return Carrito.findOne({ where: { idCarrito } })
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe este carrito.');
|
||||
return Equipo.findAll({
|
||||
where: { idCarrito },
|
||||
include: [{ model: Status }, { model: Programa }],
|
||||
});
|
||||
})
|
||||
.then((res) => {
|
||||
for (let i = 0; i < res.length; i++) {
|
||||
delete res[i].dataValues.idCarrito;
|
||||
delete res[i].dataValues.idStatus;
|
||||
delete res[i].dataValues.idPrograma;
|
||||
}
|
||||
return res;
|
||||
return Carrito.findOne({ where: { idCarrito } }).then((res) => {
|
||||
if (!res) throw new Error('No existe este carrito.');
|
||||
return Equipo.findAll({
|
||||
where: { idCarrito },
|
||||
include: [{ model: Status }, { model: Programa }],
|
||||
attributes: ['idEquipo', 'numeroSerie', 'numeroInventario', 'equipo'],
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = equiposCarrito;
|
||||
|
||||
@@ -1,20 +1,36 @@
|
||||
const { validarId } = require('../../helper/validar');
|
||||
const validar = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Carrito = require(`${dbPath}/Carrito`);
|
||||
const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
||||
|
||||
const update = async (body) => {
|
||||
const idCarrito = validarId(body.idCarrito);
|
||||
const idCarrito = validar.validarNumeroEntero(
|
||||
body.idCarrito,
|
||||
'id carrito',
|
||||
true
|
||||
);
|
||||
const idTipoCarrito = body.idTipoCarrito
|
||||
? validar.validarNumeroEntero(body.idTipoCarrito, 'id tipo carrito', true)
|
||||
: '';
|
||||
let update = {};
|
||||
|
||||
if (body.activo === 'desactivar') update.activo = false;
|
||||
else if (body.activo === 'activar') update.activo = true;
|
||||
else throw new Error('No se envio nada para actualizar.');
|
||||
return Carrito.findOne({ where: { idCarrito } })
|
||||
return TipoCarrito.findOne({ where: { idTipoCarrito } })
|
||||
.then((res) => {
|
||||
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 (body.activo === 'desactivar') update.activo = false;
|
||||
else if (body.activo === 'activar') update.activo = true;
|
||||
if (validar.validarObjetoVacio(update))
|
||||
throw new Error('No se envió nada para actualizar.');
|
||||
return Carrito.update(update, { where: { idCarrito } });
|
||||
})
|
||||
.then((res) => ({ message: 'Se actualizó correctamente el carrito.' }));
|
||||
.then(() => ({ message: 'Se actualizó correctamente el carrito.' }));
|
||||
};
|
||||
|
||||
module.exports = update;
|
||||
|
||||
@@ -29,7 +29,7 @@ const cargaMasiva = async (file) => {
|
||||
: {};
|
||||
let existeCarrito = await Carrito.findOne({
|
||||
where: {
|
||||
sobrenombre: equipos[i].carritoSobrenombre,
|
||||
idCarrito: equipos[i].carrito,
|
||||
idModulo: existeModulo.idModulo,
|
||||
},
|
||||
});
|
||||
@@ -63,12 +63,12 @@ const cargaMasiva = async (file) => {
|
||||
}
|
||||
if (!existeCarrito) {
|
||||
existeCarrito = await Carrito.create({
|
||||
sobrenombre: equipos[i].carritoSobrenombre,
|
||||
carrito: equipos[i].carritoSobrenombre,
|
||||
idTipoCarrito: existeTipoCarrito.idTipoCarrito,
|
||||
idModulo: existeModulo.idModulo,
|
||||
});
|
||||
avisos.push(
|
||||
`Se creo el carrito ${existeCarrito.sobrenombre} que pretenece al modulo ${existeModulo.idModulo}`
|
||||
`Se creo el carrito ${existeCarrito.carrito} que pretenece al modulo ${existeModulo.idModulo}`
|
||||
);
|
||||
}
|
||||
existeEquipo = await Equipo.findAll({
|
||||
@@ -78,7 +78,7 @@ const cargaMasiva = async (file) => {
|
||||
Equipo.create({
|
||||
numeroSerie: equipos[i].numeroSerie,
|
||||
numeroInventario: equipos[i].numeroInventario,
|
||||
sobrenombre: `${existeTipoCarrito.letra}${
|
||||
equipo: `${existeTipoCarrito.letra}${
|
||||
res.length < 9 ? '0' + (res.length + 1) : res.length + 1
|
||||
}`,
|
||||
idCarrito: existeCarrito.idCarrito,
|
||||
@@ -95,21 +95,23 @@ const cargaMasiva = async (file) => {
|
||||
{
|
||||
model: Carrito,
|
||||
include: [{ model: TipoCarrito }, { model: Modulo }],
|
||||
attributes: ['idCarrito', 'carrito'],
|
||||
},
|
||||
],
|
||||
attributes: [
|
||||
'idEquipo',
|
||||
'numeroSerie',
|
||||
'numeroInventario',
|
||||
'equipo',
|
||||
],
|
||||
})
|
||||
);
|
||||
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);
|
||||
});
|
||||
return {
|
||||
message: 'Se subio correctamente el archivo csv.',
|
||||
message: 'Se subió correctamente el archivo csv.',
|
||||
equiposNuevos,
|
||||
errores,
|
||||
avisos,
|
||||
|
||||
@@ -10,25 +10,25 @@ const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
||||
const equipo = async (body) => {
|
||||
const numeroInventario = validarAlfanumerico(
|
||||
body.numeroInventario,
|
||||
'El numero de inventario',
|
||||
'numero de inventario',
|
||||
true,
|
||||
20
|
||||
);
|
||||
|
||||
return Equipo.findOne({
|
||||
where: { numeroInventario },
|
||||
include: [
|
||||
{ model: Carrito, include: [{ model: TipoCarrito }, { model: Modulo }] },
|
||||
{
|
||||
model: Carrito,
|
||||
include: [{ model: TipoCarrito }, { model: Modulo }],
|
||||
attributes: ['idCarrito', 'carrito', 'activo'],
|
||||
},
|
||||
{ model: Status },
|
||||
{ model: Programa },
|
||||
],
|
||||
attributes: ['idEquipo', 'numeroSerie', 'numeroInventario', 'equipo'],
|
||||
}).then((res) => {
|
||||
if (!res) throw new Error('No existe este equipo.');
|
||||
delete res.dataValues.idCarrito;
|
||||
delete res.dataValues.idPrograma;
|
||||
delete res.dataValues.idStatus;
|
||||
delete res.dataValues.Carrito.dataValues.idTipoCarrito;
|
||||
delete res.dataValues.Carrito.dataValues.idModulo;
|
||||
if (!res.Programa) delete res.dataValues.Programa;
|
||||
return res;
|
||||
});
|
||||
};
|
||||
|
||||
@@ -2,28 +2,22 @@ const dbPath = '../../db/tablas';
|
||||
const Carrito = require(`${dbPath}/Carrito`);
|
||||
const Equipo = require(`${dbPath}/Equipo`);
|
||||
const Modulo = require(`${dbPath}/Modulo`);
|
||||
const Status = require(`${dbPath}/Status`);
|
||||
const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
||||
|
||||
const equipos = async () => {
|
||||
return Carrito.findAll({
|
||||
const equipos = async () =>
|
||||
Carrito.findAll({
|
||||
include: [{ model: TipoCarrito }, { model: Modulo }],
|
||||
attributes: ['idCarrito', 'carrito', 'activo'],
|
||||
}).then(async (res) => {
|
||||
for (let i = 0; i < res.length; i++) {
|
||||
for (let i = 0; i < res.length; i++)
|
||||
res[i].dataValues.Equipos = await Equipo.findAll({
|
||||
where: { idCarrito: res[i].idCarrito },
|
||||
}).then((res) => {
|
||||
for (let j = 0; j < res.length; j++) {
|
||||
delete res[j].dataValues.idCarrito;
|
||||
delete res[j].dataValues.idStatus;
|
||||
delete res[j].dataValues.idPrograma;
|
||||
}
|
||||
return res;
|
||||
include: [{ model: Status }],
|
||||
attributes: ['idEquipo', 'numeroSerie', 'numeroInventario', 'equipo'],
|
||||
order: [['equipo', 'ASC']],
|
||||
});
|
||||
delete res[i].dataValues.idTipoCarrito;
|
||||
delete res[i].dataValues.idModulo;
|
||||
}
|
||||
return res;
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = equipos;
|
||||
|
||||
@@ -2,41 +2,63 @@ const validar = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Carrito = require(`${dbPath}/Carrito`);
|
||||
const Equipo = require(`${dbPath}/Equipo`);
|
||||
const Motivo = require(`${dbPath}/Motivo`);
|
||||
const Programa = require(`${dbPath}/Programa`);
|
||||
const Status = require(`${dbPath}/Status`);
|
||||
|
||||
const update = async (body) => {
|
||||
const idEquipo = validar.validarId(body.idEquipo);
|
||||
const idStatus = body.idStatus ? validar.validarId(body.idStatus) : null;
|
||||
const idCarrito = body.idCarrito ? validar.validarId(body.idCarrito) : null;
|
||||
const idEquipo = validar.validarNumeroEntero(
|
||||
body.idEquipo,
|
||||
'id equipo',
|
||||
true
|
||||
);
|
||||
const idStatus = body.idStatus
|
||||
? validar.validarNumeroEntero(body.idStatus, 'id status', true)
|
||||
: '';
|
||||
const idCarrito = body.idCarrito
|
||||
? validar.validarNumeroEntero(body.idCarrito, 'id carrito', true)
|
||||
: '';
|
||||
const idPrograma = body.idPrograma
|
||||
? validar.validarId(body.idPrograma)
|
||||
: null;
|
||||
? validar.validarNumeroEntero(body.idPrograma, 'id programa', true)
|
||||
: '';
|
||||
const motivo = body.motivo
|
||||
? validar.validarAlfanumerico(body.motivo, 'motivo', true, 500)
|
||||
: '';
|
||||
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.');
|
||||
if (!motivo)
|
||||
throw new Error('No se mando el motivo de cambio de 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 envió nada para actualizar.');
|
||||
return Equipo.findOne({ where: { idEquipo } });
|
||||
})
|
||||
.then(async (res) => {
|
||||
if (!res) throw new Error('No existe este equipo.');
|
||||
if (idStatus) await Motivo.create({ motivo, idEquipo, idStatus });
|
||||
return Equipo.update(update, { where: { idEquipo } });
|
||||
})
|
||||
.then((res) => ({ message: 'Se actualizó correctamente el equipo.' }));
|
||||
.then(() => ({ message: 'Se actualizó correctamente el equipo.' }));
|
||||
};
|
||||
|
||||
module.exports = update;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const Infraccion = require('../../db/tablas/Infraccion');
|
||||
const { Op } = require('sequelize');
|
||||
const Infraccion = require('../../db/tablas/Infraccion');
|
||||
|
||||
const get = async () =>
|
||||
Infraccion.findAll({ where: { idInfraccion: { [Op.ne]: 1 } } });
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
const { validarNumeroEntero } = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Motivo = require(`${dbPath}/Motivo`);
|
||||
const Equipo = require(`${dbPath}/Equipo`);
|
||||
const Status = require(`${dbPath}/Status`);
|
||||
|
||||
const historialMotivosEquipo = async (body) => {
|
||||
const pagina = validarNumeroEntero(body.pagina, 'página', false);
|
||||
const idEquipo = validarNumeroEntero(body.idEquipo, 'id equipo', true);
|
||||
|
||||
return Motivo.findAndCountAll({
|
||||
include: [
|
||||
{
|
||||
model: Equipo,
|
||||
where: { idEquipo },
|
||||
attributes: [],
|
||||
},
|
||||
{ model: Status },
|
||||
],
|
||||
attributes: ['idMotivo', 'motivo'],
|
||||
limit: 25,
|
||||
offset: 25 * (pagina - 1),
|
||||
order: [['idMotivo', 'DESC']],
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = historialMotivosEquipo;
|
||||
@@ -1,39 +1,30 @@
|
||||
const validar = require('../../helper/validar');
|
||||
const { validarNumeroEntero } = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Multa = require(`${dbPath}/Multa`);
|
||||
const Operador = require(`${dbPath}/Operador`);
|
||||
const Prestamo = require(`${dbPath}/Prestamo`);
|
||||
|
||||
const historialMultasEquipo = async (body) => {
|
||||
const idEquipo = validar.validarId(body.idEquipo);
|
||||
const pagina = validar.validarNumero(body.pagina, true);
|
||||
const pagina = validarNumeroEntero(body.pagina, 'página', false);
|
||||
const idEquipo = validarNumeroEntero(body.idEquipo, 'id equipo', true);
|
||||
|
||||
return Multa.findAndCountAll({
|
||||
include: [
|
||||
{
|
||||
model: Prestamo,
|
||||
where: { idEquipo },
|
||||
attributes: ['idPrestamo'],
|
||||
},
|
||||
{
|
||||
model: Operador,
|
||||
as: 'OperadorMulta',
|
||||
attributes: ['idOperador', 'operador'],
|
||||
},
|
||||
{ model: Operador, as: 'OperadorMulta' },
|
||||
],
|
||||
attributes: ['idMulta', 'descripcion', 'fechaFin', 'createdAt'],
|
||||
limit: 25,
|
||||
offset: 25 * (pagina - 1),
|
||||
order: [['createdAt', 'DESC']],
|
||||
}).then((res) => {
|
||||
for (let i = 0; i < res.rows.length; i++) {
|
||||
delete res.rows[i].dataValues.idInfraccion;
|
||||
delete res.rows[i].dataValues.idPrestamo;
|
||||
delete res.rows[i].dataValues.idOperadorMulta;
|
||||
delete res.rows[i].dataValues.OperadorMulta.dataValues.password;
|
||||
delete res.rows[i].dataValues.OperadorMulta.dataValues.idTipoUsuario;
|
||||
delete res.rows[i].dataValues.OperadorMulta.dataValues.activo;
|
||||
delete res.rows[i].dataValues.Prestamo.dataValues.idOperadorEntrega;
|
||||
delete res.rows[i].dataValues.Prestamo.dataValues.idOperadorRegreso;
|
||||
delete res.rows[i].dataValues.Prestamo.dataValues.idOperadorCancelacion;
|
||||
delete res.rows[i].dataValues.Prestamo.dataValues.idUsuario;
|
||||
delete res.rows[i].dataValues.Prestamo.dataValues.idEquipo;
|
||||
}
|
||||
return { count: res.count, historialMultasEquipo: res.rows };
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const validar = require('../../helper/validar');
|
||||
const { validarNumeroEntero } = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Carrito = require(`${dbPath}/Carrito`);
|
||||
const Equipo = require(`${dbPath}/Equipo`);
|
||||
@@ -10,57 +10,27 @@ const Prestamo = require(`${dbPath}/Prestamo`);
|
||||
const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
||||
|
||||
const historialMultasUsuario = async (body) => {
|
||||
const idUsuario = validar.validarId(body.idUsuario);
|
||||
const pagina = validar.validarNumero(body.pagina, true);
|
||||
const pagina = validarNumeroEntero(body.pagina, 'página', false);
|
||||
const idUsuario = validarNumeroEntero(body.idUsuario, 'id usuario', true);
|
||||
|
||||
return Multa.findAndCountAll({
|
||||
include: [
|
||||
{
|
||||
model: Prestamo,
|
||||
where: { idUsuario },
|
||||
include: [
|
||||
{
|
||||
model: Equipo,
|
||||
include: [
|
||||
{
|
||||
model: Carrito,
|
||||
include: [{ model: Modulo }, { model: TipoCarrito }],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
attributes: ['idPrestamo'],
|
||||
},
|
||||
{
|
||||
model: Operador,
|
||||
as: 'OperadorMulta',
|
||||
attributes: ['idOperador', 'operador'],
|
||||
},
|
||||
{ model: Infraccion },
|
||||
{ model: Operador, as: 'OperadorMulta' },
|
||||
],
|
||||
attributes: ['idMulta', 'descripcion', 'fechaFin', 'createdAt'],
|
||||
limit: 25,
|
||||
offset: 25 * (pagina - 1),
|
||||
order: [['createdAt', 'DESC']],
|
||||
}).then((res) => {
|
||||
for (let i = 0; i < res.rows.length; i++) {
|
||||
delete res.rows[i].dataValues.idInfraccion;
|
||||
delete res.rows[i].dataValues.idPrestamo;
|
||||
delete res.rows[i].dataValues.idOperadorMulta;
|
||||
delete res.rows[i].dataValues.OperadorMulta.dataValues.password;
|
||||
delete res.rows[i].dataValues.OperadorMulta.dataValues.idTipoUsuario;
|
||||
delete res.rows[i].dataValues.OperadorMulta.dataValues.activo;
|
||||
delete res.rows[i].dataValues.Prestamo.dataValues.idOperadorEntrega;
|
||||
delete res.rows[i].dataValues.Prestamo.dataValues.idOperadorRegreso;
|
||||
delete res.rows[i].dataValues.Prestamo.dataValues.idOperadorCancelacion;
|
||||
delete res.rows[i].dataValues.Prestamo.dataValues.idUsuario;
|
||||
delete res.rows[i].dataValues.Prestamo.dataValues.idEquipo;
|
||||
delete res.rows[i].dataValues.Prestamo.dataValues.Equipo.dataValues
|
||||
.idCarrito;
|
||||
delete res.rows[i].dataValues.Prestamo.dataValues.Equipo.dataValues
|
||||
.idStatus;
|
||||
delete res.rows[i].dataValues.Prestamo.dataValues.Equipo.dataValues
|
||||
.idPrograma;
|
||||
delete res.rows[i].dataValues.Prestamo.dataValues.Equipo.dataValues
|
||||
.Carrito.dataValues.idTipoCarrito;
|
||||
delete res.rows[i].dataValues.Prestamo.dataValues.Equipo.dataValues
|
||||
.Carrito.dataValues.idModulo;
|
||||
}
|
||||
return { count: res.count, historialMultasUsuario: res.rows };
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
const moment = require('moment');
|
||||
const { Op } = require('sequelize');
|
||||
const validar = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Infraccion = require(`${dbPath}/Infraccion`);
|
||||
@@ -8,16 +9,32 @@ const Prestamo = require(`${dbPath}/Prestamo`);
|
||||
const Usuario = require(`${dbPath}/Usuario`);
|
||||
|
||||
const multar = async (body) => {
|
||||
const idOperadorMulta = validar.validarId(body.idOperadorMulta);
|
||||
const idInfraccion = validar.validarId(body.idInfraccion);
|
||||
const idPrestamo = validar.validarId(body.idPrestamo);
|
||||
const ahora = moment();
|
||||
const idOperadorMulta = validar.validarNumeroEntero(
|
||||
body.idOperadorMulta,
|
||||
'id operador multa',
|
||||
true
|
||||
);
|
||||
const idInfraccion = validar.validarNumeroEntero(
|
||||
body.idInfraccion,
|
||||
'id infracción',
|
||||
true
|
||||
);
|
||||
const idPrestamo = validar.validarNumeroEntero(
|
||||
body.idPrestamo,
|
||||
'id préstamo',
|
||||
true
|
||||
);
|
||||
const descripcion = validar.validarAlfanumerico(
|
||||
body.descripcion,
|
||||
'La descripción',
|
||||
'descripción',
|
||||
false,
|
||||
500
|
||||
);
|
||||
let prestamo = {};
|
||||
let fechaFin = moment();
|
||||
let prestamo = {};
|
||||
let gravedad = '';
|
||||
|
||||
return Operador.findOne({ where: { idOperador: idOperadorMulta } })
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe este operador.');
|
||||
@@ -25,36 +42,76 @@ const multar = async (body) => {
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe esta infracción.');
|
||||
if (res.gravedad == '1') fechaFin.add(7, 'd');
|
||||
else fechaFin.add(100, 'y');
|
||||
gravedad = res.gravedad;
|
||||
return Prestamo.findOne({
|
||||
where: { idPrestamo },
|
||||
include: [{ model: Usuario }],
|
||||
});
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe este prestamo.');
|
||||
if (!res) throw new Error('No existe este préstamo.');
|
||||
if (res.canceladoUsuario || res.canceladoOperador)
|
||||
throw new Error(
|
||||
'No se puede usar un préstamo cancelado para multar a un usuario.'
|
||||
);
|
||||
prestamo = res;
|
||||
return Multa.findOne({ where: { idPrestamo } });
|
||||
return Prestamo.findOne({
|
||||
where: { idUsuario: prestamo.idUsuario, activo: true },
|
||||
});
|
||||
})
|
||||
.then((res) => {
|
||||
if (res)
|
||||
throw new Error('A este prestamo ya se le ha asignado una multa.');
|
||||
throw new Error(
|
||||
'No se puede multar a un usuario mientras tenga un préstamo activo.'
|
||||
);
|
||||
return Multa.findOne({
|
||||
where: { idPrestamo, idInfraccion: { [Op.ne]: 1 } },
|
||||
});
|
||||
})
|
||||
.then(async (res) => {
|
||||
if (res)
|
||||
throw new Error(
|
||||
'Este préstamo ya ha sido usado para multar a un usuario.'
|
||||
);
|
||||
if (prestamo.Usuario.multa) {
|
||||
await Multa.findOne({
|
||||
where: {
|
||||
createdAt: { [Op.gte]: ahora },
|
||||
fechaFin: { [Op.lte]: ahora },
|
||||
},
|
||||
include: [
|
||||
{
|
||||
model: Prestamo,
|
||||
include: [
|
||||
{ model: Usuario, where: { idUsuario: prestamo.idUsuario } },
|
||||
],
|
||||
},
|
||||
],
|
||||
}).then((res) => {
|
||||
if (!res)
|
||||
throw new Error(
|
||||
'El usuario esta multado pero no se encontro una multa activa. Favor de comunicarse con los desarrolladores.'
|
||||
);
|
||||
fechaFin.moment(res.fechaFin);
|
||||
});
|
||||
}
|
||||
if (gravedad === '1') fechaFin.add(7, 'd');
|
||||
else fechaFin.add(100, 'y');
|
||||
return Usuario.update(
|
||||
{ multa: true },
|
||||
{ where: { idUsuario: prestamo.Usuario.idUsuario } }
|
||||
{ where: { idUsuario: prestamo.idUsuario } }
|
||||
);
|
||||
})
|
||||
.then((res) =>
|
||||
.then(() =>
|
||||
Multa.create({
|
||||
descripcion,
|
||||
fechaFin: fechaFin.format(),
|
||||
idPrestamo,
|
||||
idOperadorMulta,
|
||||
idInfraccion,
|
||||
idPrestamo,
|
||||
descripcion,
|
||||
fechaFin: fechaFin.format('YYYY-MM-DD'),
|
||||
})
|
||||
)
|
||||
.then((res) => ({
|
||||
.then(() => ({
|
||||
message: `Se levantó correctamente el reporte de multa.`,
|
||||
}));
|
||||
};
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
const moment = require('moment');
|
||||
const validar = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Infraccion = require(`${dbPath}/Infraccion`);
|
||||
const Multa = require(`${dbPath}/Multa`);
|
||||
const Operador = require(`${dbPath}/Operador`);
|
||||
const Prestamo = require(`${dbPath}/Prestamo`);
|
||||
const Usuario = require(`${dbPath}/Usuario`);
|
||||
|
||||
const multar = async (body) => {
|
||||
const idOperadorMulta = validar.validarNumeroEntero(
|
||||
body.idOperadorMulta,
|
||||
'id operador multa',
|
||||
true
|
||||
);
|
||||
const idInfraccion = validar.validarNumeroEntero(
|
||||
body.idInfraccion,
|
||||
'id infracción',
|
||||
true
|
||||
);
|
||||
const idPrestamo = validar.validarNumeroEntero(
|
||||
body.idPrestamo,
|
||||
'id préstamo',
|
||||
true
|
||||
);
|
||||
const descripcion = validar.validarAlfanumerico(
|
||||
body.descripcion,
|
||||
'descripción',
|
||||
false,
|
||||
500
|
||||
);
|
||||
let fechaFin = moment();
|
||||
|
||||
return Operador.findOne({ where: { idOperador: idOperadorMulta } })
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe este operador.');
|
||||
return Infraccion.findOne({ where: { idInfraccion } });
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe esta infracción.');
|
||||
if (res.gravedad === '1') fechaFin.add(7, 'd');
|
||||
else fechaFin.add(100, 'y');
|
||||
return Prestamo.findOne({ where: { idPrestamo } });
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe este préstamo.');
|
||||
return Usuario.update(
|
||||
{ multa: true },
|
||||
{ where: { idUsuario: res.idUsuario } }
|
||||
);
|
||||
})
|
||||
.then(() =>
|
||||
Multa.create({
|
||||
idPrestamo,
|
||||
idOperadorMulta,
|
||||
idInfraccion,
|
||||
descripcion,
|
||||
fechaFin: fechaFin.format('YYYY-MM-DD'),
|
||||
})
|
||||
)
|
||||
.then(() => ({
|
||||
message: `Se levantó correctamente el reporte de multa.`,
|
||||
}));
|
||||
};
|
||||
|
||||
module.exports = multar;
|
||||
@@ -1,69 +1,72 @@
|
||||
const moment = require('moment');
|
||||
const { Op } = require('sequelize');
|
||||
const validar = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Infraccion = require(`${dbPath}/Infraccion`);
|
||||
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 multarNumeroInventario = async (body) => {
|
||||
const idOperadorMulta = validar.validarId(body.idOperadorMulta);
|
||||
const idInfraccion = validar.validarId(body.idInfraccion);
|
||||
const idOperadorMulta = validar.validarNumeroEntero(
|
||||
body.idOperadorMulta,
|
||||
'id operador multa',
|
||||
true
|
||||
);
|
||||
const idInfraccion = validar.validarNumeroEntero(
|
||||
body.idInfraccion,
|
||||
'id infracción',
|
||||
true
|
||||
);
|
||||
const numeroInventario = validar.validarAlfanumerico(
|
||||
body.numeroInventario,
|
||||
'El numero de inventario',
|
||||
'número de inventario',
|
||||
20
|
||||
);
|
||||
const descripcion = validar.validarAlfanumerico(
|
||||
body.descripcion,
|
||||
'La descripción',
|
||||
'descripción',
|
||||
false,
|
||||
500
|
||||
);
|
||||
let prestamo = {};
|
||||
let fechaFin = moment();
|
||||
let idPrestamo = null;
|
||||
|
||||
return Operador.findOne({ where: { idOperador: idOperadorMulta } })
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe esta este operador.');
|
||||
if (!res) throw new Error('No existe este operador.');
|
||||
return Infraccion.findOne({ where: { idInfraccion } });
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe esta infracción.');
|
||||
if (res.gravedad == '1') fechaFin.add(7, 'd');
|
||||
if (res.gravedad === '1') fechaFin.add(7, 'd');
|
||||
else fechaFin.add(100, 'y');
|
||||
return Prestamo.findOne({
|
||||
where: { activo: true },
|
||||
include: [
|
||||
{ model: Equipo, where: { numeroInventario } },
|
||||
{ model: Usuario },
|
||||
],
|
||||
include: [{ model: Equipo, where: { numeroInventario } }],
|
||||
});
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res)
|
||||
throw new Error('No existe un prestamo activo con este equipo.');
|
||||
prestamo = res;
|
||||
return Multa.findOne({ where: { idPrestamo: prestamo.idPrestamo } });
|
||||
})
|
||||
.then((res) => {
|
||||
if (res)
|
||||
throw new Error('A este prestamo ya se le ha asignado una multa.');
|
||||
idPrestamo = res.idPrestamo;
|
||||
return Usuario.update(
|
||||
{ multa: true },
|
||||
{ where: { idUsuario: prestamo.Usuario.idUsuario } }
|
||||
{ where: { idUsuario: res.idUsuario } }
|
||||
);
|
||||
})
|
||||
.then((res) =>
|
||||
.then(() =>
|
||||
Multa.create({
|
||||
descripcion,
|
||||
idPrestamo,
|
||||
idOperadorMulta,
|
||||
idInfraccion,
|
||||
idPrestamo: prestamo.idPrestamo,
|
||||
fechaFin: fechaFin.format(),
|
||||
descripcion,
|
||||
fechaFin: fechaFin.format('YYYY-MM-DD'),
|
||||
})
|
||||
)
|
||||
.then((res) => ({
|
||||
.then(() => ({
|
||||
message: `Se levantó correctamente el reporte de multa.`,
|
||||
}));
|
||||
};
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
const validar = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Multa = require(`${dbPath}/Multa`);
|
||||
const Usuario = require(`${dbPath}/Usuario`);
|
||||
|
||||
const multar = async (body) => {
|
||||
const idUsuario = validar.validarNumeroEntero(
|
||||
body.idUsuario,
|
||||
'id usuario',
|
||||
true
|
||||
);
|
||||
|
||||
return Usuario.findOne({ where: { idUsuario } })
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe este usuario.');
|
||||
return Multa.findAll({ where: { idUsuario, activo: true } });
|
||||
})
|
||||
.then((res) => {
|
||||
if (res.length > 2)
|
||||
throw new Error(
|
||||
'El usuario tiene más de 2 multas activas, favor de notificar a un operador sobre este problema.'
|
||||
);
|
||||
return res;
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = multar;
|
||||
@@ -4,10 +4,11 @@ const validar = require(`${helperPath}/validar`);
|
||||
const Operador = require('../../db/tablas/Operador');
|
||||
|
||||
const crear = async (body) => {
|
||||
const operador = validar.validarTexto(body.operador, 'El operador', 60);
|
||||
const operador = validar.validarTexto(body.operador, 'operador', true, 60);
|
||||
const password = validar.validarAlfanumerico(
|
||||
body.password,
|
||||
'La contraseña',
|
||||
'contraseña',
|
||||
false,
|
||||
20
|
||||
);
|
||||
|
||||
@@ -20,7 +21,7 @@ const crear = async (body) => {
|
||||
idTipoUsuario: 2,
|
||||
});
|
||||
})
|
||||
.then((res) => ({ message: 'Se creo un nuevo operador correctamente.' }));
|
||||
.then(() => ({ message: 'Se creó un nuevo operador correctamente.' }));
|
||||
};
|
||||
|
||||
module.exports = crear;
|
||||
|
||||
@@ -7,33 +7,33 @@ const Operador = require(`${dbPath}/Operador`);
|
||||
const TipoUsuario = require(`${dbPath}/TipoUsuario`);
|
||||
|
||||
const login = async (body) => {
|
||||
const operador = validar.validarTexto(body.operador, 'El operador', 60);
|
||||
const operador = validar.validarTexto(body.operador, 'operador', true, 60);
|
||||
const password = validar.validarAlfanumerico(
|
||||
body.password,
|
||||
'La contraseña',
|
||||
'contraseña',
|
||||
false,
|
||||
20
|
||||
);
|
||||
|
||||
return Operador.findOne({
|
||||
where: { operador },
|
||||
include: [{ model: TipoUsuario }],
|
||||
}).then((res) => {
|
||||
if (!res) throw new Error('No existe este operador.');
|
||||
if (!res.activo) throw new Error('Este operador no esta activo.');
|
||||
if (comparar(password, res.password)) {
|
||||
delete res.dataValues.password;
|
||||
delete res.dataValues.activo;
|
||||
delete res.dataValues.idTipoUsuario;
|
||||
return {
|
||||
Operador: res,
|
||||
token: crearTokenOperador({
|
||||
idOperador: res.idOperador,
|
||||
idTipoUsuario: res.TipoUsuario.idTipoUsuario,
|
||||
}),
|
||||
};
|
||||
}
|
||||
throw new Error('La contraseña es incorrecta.');
|
||||
});
|
||||
return Operador.findOne({ where: { operador } })
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe este operador.');
|
||||
if (!res.activo) throw new Error('Este operador no esta activo.');
|
||||
if (!comparar(password, res.password))
|
||||
throw new Error('La contraseña es incorrecta.');
|
||||
return Operador.findOne({
|
||||
where: { operador },
|
||||
include: [{ model: TipoUsuario }],
|
||||
attributes: ['idOperador', 'operador', 'activo'],
|
||||
});
|
||||
})
|
||||
.then((res) => ({
|
||||
Operador: res,
|
||||
token: crearTokenOperador({
|
||||
idOperador: res.idOperador,
|
||||
idTipoUsuario: res.TipoUsuario.idTipoUsuario,
|
||||
}),
|
||||
}));
|
||||
};
|
||||
|
||||
module.exports = login;
|
||||
|
||||
@@ -1,23 +1,21 @@
|
||||
const { Op } = require('sequelize');
|
||||
const validar = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Operador = require(`${dbPath}/Operador`);
|
||||
const TipoUsuario = require(`${dbPath}/TipoUsuario`);
|
||||
|
||||
const operadores = async (body) => {
|
||||
const pagina = validar.validarNumero(body.pagina, true);
|
||||
// filtros
|
||||
const pagina = validar.validarNumeroEntero(body.pagina, 'página', false);
|
||||
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) => {
|
||||
for (let i = 0; i < res.rows.length; i++) {
|
||||
delete res.rows[i].dataValues.password;
|
||||
delete res.rows[i].dataValues.idTipoUsuario;
|
||||
}
|
||||
return { count: res.count, operadores: res.rows };
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -4,23 +4,31 @@ const validar = require(`${helperPath}/validar`);
|
||||
const Operador = require(`../../db/tablas/Operador`);
|
||||
|
||||
const update = async (body) => {
|
||||
const idOperador = validar.validarId(body.idOperador);
|
||||
const idOperador = validar.validarNumeroEntero(
|
||||
body.idOperador,
|
||||
'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, 'La Contraseña', 20)
|
||||
);
|
||||
if (validar.validarObjetoVacio(update))
|
||||
throw new Error('No se mando nada para actualizar.');
|
||||
return Operador.findOne({ where: { idOperador, idTipoUsuario: 2 } })
|
||||
return Operador.findOne({ where: { idOperador } })
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe este operador.');
|
||||
if (res.idTipoUsuario != 2)
|
||||
throw new Error(
|
||||
'Este usuario no es de tipo operador, no se pueda actualizar su información.'
|
||||
);
|
||||
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.' }));
|
||||
.then(() => ({ message: 'Se actualizó correctamente al operador.' }));
|
||||
};
|
||||
|
||||
module.exports = update;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const { Op } = require('sequelize');
|
||||
const { Op, where } = require('sequelize');
|
||||
const validar = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Carrera = require(`${dbPath}/Carrera`);
|
||||
@@ -6,80 +6,97 @@ const Carrito = require(`${dbPath}/Carrito`);
|
||||
const Equipo = require(`${dbPath}/Equipo`);
|
||||
const Modulo = require(`${dbPath}/Modulo`);
|
||||
const Prestamo = require(`${dbPath}/Prestamo`);
|
||||
const Status = require(`${dbPath}/Status`);
|
||||
const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
||||
const TipoUsuario = require(`${dbPath}/TipoUsuario`);
|
||||
const Usuario = require(`${dbPath}/Usuario`);
|
||||
|
||||
const activos = async (body) => {
|
||||
const idModulo = validar.validarId(body.idModulo);
|
||||
const pagina = validar.validarNumero(body.pagina, true);
|
||||
const pagina = validar.validarNumeroEntero(body.pagina, 'página', false);
|
||||
const idModulo = validar.validarNumeroEntero(
|
||||
body.idModulo,
|
||||
'id modulo',
|
||||
true
|
||||
);
|
||||
const idPrestamo = body.idPrestamo
|
||||
? validar.validarNumeroEntero(body.idPrestamo, 'id préstamo', true)
|
||||
: '';
|
||||
const idTipoCarrito = body.idTipoCarrito
|
||||
? validar.validarNumeroEntero(body.idTipoCarrito, 'id tipo carrito', true)
|
||||
: '';
|
||||
const usuario = body.usuario ? validar.validarNumeroCuenta(body.usuario) : '';
|
||||
const idPrestamo = body.idPrestamo ? validar.validarId(body.idPrestamo) : '';
|
||||
const numeroInventario = body.numeroInventario
|
||||
? validar.validarAlfanumerico(
|
||||
body.numeroInventario,
|
||||
'El numero de inventario',
|
||||
'numero de inventario',
|
||||
true,
|
||||
20
|
||||
)
|
||||
: '';
|
||||
const idTipoCarrito = body.idTipoCarrito
|
||||
? validar.validarId(body.idTipoCarrito)
|
||||
: null;
|
||||
const carrito = body.carrito
|
||||
? validar.validarAlfanumerico(body.carrito, 'carrito', true)
|
||||
: '';
|
||||
const equipo = body.equipo
|
||||
? validar.validarAlfanumerico(body.equipo, 'equipo', true)
|
||||
: '';
|
||||
let wherePrestamo = {
|
||||
[Op.or]: [
|
||||
{ activo: true },
|
||||
{
|
||||
[Op.and]: [{ regresoInmediato: true }, { idOperadorRegreso: null }],
|
||||
},
|
||||
],
|
||||
};
|
||||
let whereCarrito = [{ idModulo }];
|
||||
let whereEquipo = {};
|
||||
|
||||
if (equipo) whereEquipo.equipo = equipo;
|
||||
if (numeroInventario)
|
||||
whereEquipo.numeroInventario = { [Op.like]: `%${numeroInventario}%` };
|
||||
if (carrito) whereCarrito.push({ carrito });
|
||||
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 }],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
model: Usuario,
|
||||
where: { usuario: { [Op.like]: `%${usuario}%` } },
|
||||
include: [{ model: TipoUsuario }, { model: Carrera }],
|
||||
},
|
||||
],
|
||||
limit: 25,
|
||||
offset: 25 * (pagina - 1),
|
||||
order: [['createdAt', 'DESC']],
|
||||
});
|
||||
})
|
||||
.then((res) => {
|
||||
for (let i = 0; i < res.rows.length; i++) {
|
||||
delete res.rows[i].dataValues.idUsuario;
|
||||
delete res.rows[i].dataValues.idOperadorEntrega;
|
||||
delete res.rows[i].dataValues.idOperadorRegreso;
|
||||
delete res.rows[i].dataValues.idOperadorCancelacion;
|
||||
delete res.rows[i].dataValues.idEquipo;
|
||||
delete res.rows[i].dataValues.Equipo.dataValues.idPrograma;
|
||||
delete res.rows[i].dataValues.Equipo.dataValues.idStatus;
|
||||
delete res.rows[i].dataValues.Equipo.dataValues.idCarrito;
|
||||
delete res.rows[i].dataValues.Equipo.dataValues.Carrito.dataValues
|
||||
.idTipoCarrito;
|
||||
delete res.rows[i].dataValues.Equipo.dataValues.Carrito.dataValues
|
||||
.idModulo;
|
||||
delete res.rows[i].dataValues.Equipo.dataValues.Carrito.dataValues
|
||||
.activo;
|
||||
delete res.rows[i].dataValues.Usuario.dataValues.idTipoUsuario;
|
||||
delete res.rows[i].dataValues.Usuario.dataValues.multa;
|
||||
delete res.rows[i].dataValues.Usuario.dataValues.activo;
|
||||
delete res.rows[i].dataValues.Usuario.dataValues.idCarrera;
|
||||
delete res.rows[i].dataValues.Usuario.dataValues.password;
|
||||
}
|
||||
return { count: res.count, activos: res.rows };
|
||||
if (idPrestamo) wherePrestamo.idPrestamo = { [Op.like]: `%${idPrestamo}%` };
|
||||
return Modulo.findOne({ where: { idModulo } }).then((res) => {
|
||||
if (!res) throw new Error('No existe este módulo.');
|
||||
return Prestamo.findAndCountAll({
|
||||
where: wherePrestamo,
|
||||
include: [
|
||||
{
|
||||
model: Equipo,
|
||||
where: whereEquipo,
|
||||
include: [
|
||||
{
|
||||
model: Carrito,
|
||||
where: { [Op.and]: whereCarrito },
|
||||
include: [{ model: TipoCarrito }, { model: Modulo }],
|
||||
attributes: ['idCarrito', 'carrito'],
|
||||
},
|
||||
{ model: Status },
|
||||
],
|
||||
attributes: ['idEquipo', 'numeroSerie', 'numeroInventario', 'equipo'],
|
||||
},
|
||||
{
|
||||
model: Usuario,
|
||||
where: { usuario: { [Op.like]: `%${usuario}%` } },
|
||||
include: [{ model: TipoUsuario }, { model: Carrera }],
|
||||
attributes: ['idUsuario', 'usuario', 'nombre'],
|
||||
},
|
||||
],
|
||||
attributes: [
|
||||
'idPrestamo',
|
||||
'activo',
|
||||
'horaMaxRecoger',
|
||||
'horaInicio',
|
||||
'horaFin',
|
||||
'horaEntrega',
|
||||
'regresoInmediato',
|
||||
'createdAt',
|
||||
],
|
||||
limit: 25,
|
||||
offset: 25 * (pagina - 1),
|
||||
order: [['idPrestamo', 'ASC']],
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = activos;
|
||||
|
||||
@@ -1,44 +1,57 @@
|
||||
const { validarId } = require('../../helper/validar');
|
||||
const io = require('../../socket');
|
||||
const validar = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Equipo = require(`${dbPath}/Equipo`);
|
||||
const Motivo = require(`${dbPath}/Motivo`);
|
||||
const Operador = require(`${dbPath}/Operador`);
|
||||
const Prestamo = require(`${dbPath}/Prestamo`);
|
||||
|
||||
const cancelarOperador = async (body) => {
|
||||
const idPrestamo = validarId(body.idPrestamo);
|
||||
const idOperadorCancelacion = validarId(body.idOperadorCancelacion);
|
||||
const idPrestamo = validar.validarNumeroEntero(
|
||||
body.idPrestamo,
|
||||
'id préstamo',
|
||||
true
|
||||
);
|
||||
const idOperador = validar.validarNumeroEntero(
|
||||
body.idOperador,
|
||||
'id operador',
|
||||
true
|
||||
);
|
||||
const motivo = validar.validarAlfanumerico(body.motivo, 'motivo', true, 500);
|
||||
let idUsuario = null;
|
||||
|
||||
return Operador.findOne({ where: { idOperador: idOperadorCancelacion } })
|
||||
return Operador.findOne({ where: { idOperador } })
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe esta este operador.');
|
||||
return Prestamo.findOne({
|
||||
where: { idPrestamo },
|
||||
include: [{ model: Equipo }],
|
||||
});
|
||||
if (!res) throw new Error('No existe este operador.');
|
||||
return Prestamo.findOne({ where: { idPrestamo } });
|
||||
})
|
||||
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('Este prestamo no existe.');
|
||||
.then(async (res) => {
|
||||
if (!res) throw new Error('Este préstamo no existe.');
|
||||
idUsuario = res.idUsuario;
|
||||
if (!res.activo)
|
||||
throw new Error(
|
||||
'Este prestamo ya no esta activo, ya no se puede cancelar.'
|
||||
);
|
||||
if (res.Equipo.enUso)
|
||||
throw new Error(
|
||||
'El equipo ya fue entregado al usuario, ya no se puede cancelar.'
|
||||
'Este préstamo ya no esta activo, no se puede cancelar.'
|
||||
);
|
||||
await Motivo.create({ motivo, idEquipo: res.idEquipo, idStatus: 9 });
|
||||
return Equipo.update(
|
||||
{ apartado: false },
|
||||
{ where: { idEquipo: res.Equipo.idEquipo } }
|
||||
{ idStatus: 9 },
|
||||
{ where: { idEquipo: res.idEquipo } }
|
||||
);
|
||||
})
|
||||
.then((res) =>
|
||||
.then(() =>
|
||||
Prestamo.update(
|
||||
{ activo: false, idOperadorCancelacion },
|
||||
{
|
||||
activo: false,
|
||||
idOperadorRegreso: idOperador,
|
||||
canceladoOperador: true,
|
||||
},
|
||||
{ where: { idPrestamo } }
|
||||
)
|
||||
)
|
||||
.then((res) => ({ message: 'Se cancelo el prestamo correctamente.' }));
|
||||
.then(() => {
|
||||
io.getIO().emit('actualizar', { idUsuario });
|
||||
return { message: 'Se canceló el préstamo correctamente.' };
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = cancelarOperador;
|
||||
|
||||
@@ -1,37 +1,51 @@
|
||||
const { validarId } = require('../../helper/validar');
|
||||
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 = validarId(body.idPrestamo);
|
||||
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('Este prestamo no existe.');
|
||||
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)
|
||||
throw new Error(
|
||||
'Este prestamo ya no esta activo, ya no se puede cancelar.'
|
||||
'Este préstamo ya no esta activo, no se puede cancelar.'
|
||||
);
|
||||
if (res.Equipo.enUso)
|
||||
if (res.Equipo.idStatus === 2)
|
||||
throw new Error(
|
||||
'El equipo ya fue entregado al usuario, ya no se puede cancelar.'
|
||||
'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(
|
||||
{ apartado: false },
|
||||
{ where: { idEquipo: res.Equipo.idEquipo } }
|
||||
{ idStatus: 4 },
|
||||
{ where: { idEquipo: res.idEquipo } }
|
||||
);
|
||||
})
|
||||
.then((res) =>
|
||||
.then(() =>
|
||||
Prestamo.update(
|
||||
{ activo: false, canceladoUsuario: true },
|
||||
{ where: { idPrestamo } }
|
||||
)
|
||||
)
|
||||
.then((res) => ({ message: 'Se cancelo el prestamo correctamente.' }));
|
||||
.then(() => {
|
||||
io.getIO().emit('actualizar', { idUsuario });
|
||||
return { message: 'Se canceló el préstamo correctamente.' };
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = cancelarUsuario;
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
const dbPath = '../../db/tablas';
|
||||
const Prestamo = require(`${dbPath}/Prestamo`);
|
||||
|
||||
const diezMinutos = async (body) => {
|
||||
return Prestamo.findAll({
|
||||
where: { activo: true, idOperadorEntrega: null },
|
||||
attributes: ['idPrestamo', 'activo', 'horaMaxRecoger', 'idOperadorEntrega'],
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = diezMinutos;
|
||||
@@ -1,5 +1,6 @@
|
||||
const moment = require('moment');
|
||||
const { validarId } = require('../../helper/validar');
|
||||
const io = require('../../socket');
|
||||
const { validarNumeroEntero } = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Carrito = require(`${dbPath}/Carrito`);
|
||||
const Equipo = require(`${dbPath}/Equipo`);
|
||||
@@ -10,9 +11,18 @@ const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
||||
|
||||
const entregar = async (body) => {
|
||||
const ahora = moment();
|
||||
const idPrestamo = validarId(body.idPrestamo);
|
||||
const idOperadorEntrega = validarId(body.idOperadorEntrega);
|
||||
let idEquipo;
|
||||
const idPrestamo = validarNumeroEntero(body.idPrestamo, 'id préstamo', true);
|
||||
const idOperadorEntrega = validarNumeroEntero(
|
||||
body.idOperadorEntrega,
|
||||
'id operador entrega',
|
||||
true
|
||||
);
|
||||
let update = {
|
||||
idOperadorEntrega,
|
||||
horaInicio: ahora.format(),
|
||||
};
|
||||
let idEquipo = null;
|
||||
let idUsuario = null;
|
||||
|
||||
return Operador.findOne({ where: { idOperador: idOperadorEntrega } })
|
||||
.then((res) => {
|
||||
@@ -23,47 +33,47 @@ 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.enUso)
|
||||
if (!res) throw new Error('No existe este préstamo.');
|
||||
idEquipo = res.idEquipo;
|
||||
idUsuario = res.idUsuario;
|
||||
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) {
|
||||
await Equipo.update({ apartado: false }, { where: { idEquipo } });
|
||||
await Prestamo.update({ activo: false }, { where: { idPrestamo } });
|
||||
throw new Error(
|
||||
'Ya paso el tiempo limite para recoger el dispositivo.'
|
||||
);
|
||||
}
|
||||
return Equipo.update({ enUso: true }, { where: { idEquipo } });
|
||||
})
|
||||
.then((res) => {
|
||||
Prestamo.update(
|
||||
{
|
||||
idOperadorEntrega,
|
||||
horaInicio: ahora.format(),
|
||||
horaFin: ahora.add(2, 'h').format(),
|
||||
},
|
||||
{ where: { idPrestamo } }
|
||||
if (moment(res.horaMaxRecoger) < ahora)
|
||||
await Equipo.update({ idStatus: 4 }, { where: { idEquipo } })
|
||||
.then(() =>
|
||||
Prestamo.update({ activo: false }, { where: { idPrestamo } })
|
||||
)
|
||||
.then(() => {
|
||||
io.getIO().emit('actualizar', { idUsuario });
|
||||
throw new Error(
|
||||
'Ya pasó el tiempo límite para recoger el equipo de cómputo.'
|
||||
);
|
||||
});
|
||||
if (ahora > moment(`${ahora.format('YYYY-MM-DD')} 17:45`))
|
||||
update.horaFin = moment(`${ahora.format('YYYY-MM-DD')} 19:45`);
|
||||
else update.horaFin = ahora.add(2, 'h').format();
|
||||
return Equipo.update(
|
||||
{ idStatus: 2, prestado: true },
|
||||
{ where: { idEquipo } }
|
||||
);
|
||||
})
|
||||
.then((res) => {
|
||||
return Equipo.findOne({
|
||||
.then(() => Prestamo.update(update, { where: { idPrestamo } }))
|
||||
.then(() =>
|
||||
Equipo.findOne({
|
||||
where: { idEquipo },
|
||||
include: [
|
||||
{
|
||||
model: Carrito,
|
||||
include: [{ model: TipoCarrito }, { model: Modulo }],
|
||||
attributes: ['idCarrito', 'carrito'],
|
||||
},
|
||||
],
|
||||
});
|
||||
})
|
||||
attributes: ['idEquipo', 'numeroSerie', 'numeroInventario', 'equipo'],
|
||||
})
|
||||
)
|
||||
.then((res) => {
|
||||
delete res.dataValues.idCarrito;
|
||||
delete res.dataValues.idStatus;
|
||||
delete res.dataValues.idPrograma;
|
||||
delete res.dataValues.Carrito.dataValues.idTipoCarrito;
|
||||
delete res.dataValues.Carrito.dataValues.idModulo;
|
||||
io.getIO().emit('actualizar', { idUsuario });
|
||||
return res;
|
||||
});
|
||||
};
|
||||
|
||||
@@ -12,20 +12,25 @@ const TipoUsuario = require(`${dbPath}/TipoUsuario`);
|
||||
const Usuario = require(`${dbPath}/Usuario`);
|
||||
|
||||
const historial = async (body) => {
|
||||
const pagina = validar.validarNumero(body.pagina, true);
|
||||
const pagina = validar.validarNumeroEntero(body.pagina, 'página', false);
|
||||
const usuario = body.usuario ? validar.validarNumeroCuenta(body.usuario) : '';
|
||||
const idPrestamo = body.idPrestamo ? validar.validarId(body.idPrestamo) : '';
|
||||
const idPrestamo = body.idPrestamo
|
||||
? validar.validarNumeroEntero(body.idPrestamo, 'id préstamo', true)
|
||||
: '';
|
||||
const numeroInventario = body.numeroInventario
|
||||
? validar.validarAlfanumerico(
|
||||
body.numeroInventario,
|
||||
'El numero de inventario',
|
||||
'numero de inventario',
|
||||
true,
|
||||
20
|
||||
)
|
||||
: '';
|
||||
const idModulo = body.idModulo ? validar.validarId(body.idModulo) : null;
|
||||
const idModulo = body.idModulo
|
||||
? validar.validarNumeroEntero(body.idModulo, 'id módulo', true)
|
||||
: '';
|
||||
const idTipoCarrito = body.idTipoCarrito
|
||||
? validar.validarId(body.idTipoCarrito)
|
||||
: null;
|
||||
? validar.validarNumeroEntero(body.idTipoCarrito, 'id tipo carrito', true)
|
||||
: '';
|
||||
let whereCarrito = [];
|
||||
|
||||
if (idTipoCarrito) whereCarrito.push({ idTipoCarrito });
|
||||
@@ -47,53 +52,49 @@ const historial = async (body) => {
|
||||
model: Carrito,
|
||||
where: { [Op.and]: whereCarrito },
|
||||
include: [{ model: TipoCarrito }, { model: Modulo }],
|
||||
attributes: ['idCarrito', 'carrito'],
|
||||
},
|
||||
],
|
||||
attributes: [
|
||||
'idEquipo',
|
||||
'numeroSerie',
|
||||
'numeroInventario',
|
||||
'equipo',
|
||||
'updatedAt',
|
||||
],
|
||||
},
|
||||
{
|
||||
model: Usuario,
|
||||
where: { usuario: { [Op.like]: `%${usuario}%` } },
|
||||
include: [{ model: TipoUsuario }, { model: Carrera }],
|
||||
attributes: ['idUsuario', 'usuario', 'nombre'],
|
||||
},
|
||||
{
|
||||
model: Operador,
|
||||
as: 'OperadorEntrega',
|
||||
attributes: ['idOperador', 'operador'],
|
||||
},
|
||||
{
|
||||
model: Operador,
|
||||
as: 'OperadorRegreso',
|
||||
attributes: ['idOperador', 'operador'],
|
||||
},
|
||||
{ model: Operador, as: 'OperadorRegreso' },
|
||||
{ model: Operador, as: 'OperadorEntrega' },
|
||||
],
|
||||
attributes: [
|
||||
'idPrestamo',
|
||||
'activo',
|
||||
'horaMaxRecoger',
|
||||
'horaInicio',
|
||||
'horaFin',
|
||||
'horaEntrega',
|
||||
'canceladoUsuario',
|
||||
'canceladoOperador',
|
||||
'regresoInmediato',
|
||||
'createdAt',
|
||||
],
|
||||
order: [['idPrestamo', 'DESC']],
|
||||
limit: 25,
|
||||
offset: 25 * (pagina - 1),
|
||||
order: [['createdAt', 'DESC']],
|
||||
}).then((res) => {
|
||||
for (let i = 0; i < res.rows.length; i++) {
|
||||
delete res.rows[i].dataValues.idUsuario;
|
||||
delete res.rows[i].dataValues.idOperadorEntrega;
|
||||
delete res.rows[i].dataValues.idOperadorRegreso;
|
||||
delete res.rows[i].dataValues.idEquipo;
|
||||
delete res.rows[i].dataValues.idOperadorCancelacion;
|
||||
delete res.rows[i].dataValues.Equipo.dataValues.idPrograma;
|
||||
delete res.rows[i].dataValues.Equipo.dataValues.idStatus;
|
||||
delete res.rows[i].dataValues.Equipo.dataValues.idCarrito;
|
||||
delete res.rows[i].dataValues.Equipo.dataValues.updatedAt;
|
||||
delete res.rows[i].dataValues.Equipo.dataValues.Carrito.dataValues
|
||||
.idTipoCarrito;
|
||||
delete res.rows[i].dataValues.Equipo.dataValues.Carrito.dataValues
|
||||
.idModulo;
|
||||
delete res.rows[i].dataValues.Equipo.dataValues.Carrito.dataValues.activo;
|
||||
delete res.rows[i].dataValues.Usuario.dataValues.idTipoUsuario;
|
||||
delete res.rows[i].dataValues.Usuario.dataValues.idCarrera;
|
||||
delete res.rows[i].dataValues.Usuario.dataValues.password;
|
||||
delete res.rows[i].dataValues.Usuario.dataValues.activo;
|
||||
delete res.rows[i].dataValues.Usuario.dataValues.multa;
|
||||
if (res.rows[i].OperadorEntrega) {
|
||||
delete res.rows[i].dataValues.OperadorEntrega.dataValues.password;
|
||||
delete res.rows[i].dataValues.OperadorEntrega.dataValues.activo;
|
||||
delete res.rows[i].dataValues.OperadorEntrega.dataValues.idTipoUsuario;
|
||||
}
|
||||
if (res.rows[i].OperadorRegreso) {
|
||||
delete res.rows[i].dataValues.OperadorRegreso.dataValues.password;
|
||||
delete res.rows[i].dataValues.OperadorRegreso.dataValues.activo;
|
||||
delete res.rows[i].dataValues.OperadorRegreso.dataValues.idTipoUsuario;
|
||||
}
|
||||
}
|
||||
return { count: res.count, historial: res.rows };
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -8,51 +8,51 @@ const TipoUsuario = require(`${dbPath}/TipoUsuario`);
|
||||
const Usuario = require(`${dbPath}/Usuario`);
|
||||
|
||||
const historialEquipo = async (body) => {
|
||||
const idEquipo = validar.validarId(body.idEquipo);
|
||||
const pagina = validar.validarNumero(body.pagina, true);
|
||||
const pagina = validar.validarNumeroEntero(body.pagina, 'página', false);
|
||||
const idEquipo = validar.validarNumeroEntero(
|
||||
body.idEquipo,
|
||||
'id equipo',
|
||||
true
|
||||
);
|
||||
|
||||
return Prestamo.findAndCountAll({
|
||||
include: [
|
||||
{ model: Equipo, where: { idEquipo } },
|
||||
{ model: Usuario, include: [{ model: TipoUsuario }, { model: Carrera }] },
|
||||
{ model: Operador, as: 'OperadorRegreso' },
|
||||
{ model: Operador, as: 'OperadorEntrega' },
|
||||
{ model: Operador, as: 'OperadorCancelacion' },
|
||||
{
|
||||
model: Equipo,
|
||||
where: { idEquipo },
|
||||
attributes: ['idEquipo', 'numeroSerie', 'numeroInventario', 'equipo'],
|
||||
},
|
||||
{
|
||||
model: Usuario,
|
||||
include: [{ model: TipoUsuario }, { model: Carrera }],
|
||||
attributes: ['idUsuario', 'usuario', 'nombre'],
|
||||
},
|
||||
{
|
||||
model: Operador,
|
||||
as: 'OperadorEntrega',
|
||||
attributes: ['idOperador', 'operador'],
|
||||
},
|
||||
{
|
||||
model: Operador,
|
||||
as: 'OperadorRegreso',
|
||||
attributes: ['idOperador', 'operador'],
|
||||
},
|
||||
],
|
||||
attributes: [
|
||||
'idPrestamo',
|
||||
'activo',
|
||||
'horaMaxRecoger',
|
||||
'horaInicio',
|
||||
'horaFin',
|
||||
'horaEntrega',
|
||||
'canceladoUsuario',
|
||||
'canceladoOperador',
|
||||
'regresoInmediato',
|
||||
'createdAt',
|
||||
],
|
||||
limit: 25,
|
||||
offset: 25 * (pagina - 1),
|
||||
order: [['createdAt', 'DESC']],
|
||||
}).then((res) => {
|
||||
for (let i = 0; i < res.rows.length; i++) {
|
||||
delete res.rows[i].dataValues.idUsuario;
|
||||
delete res.rows[i].dataValues.idOperadorEntrega;
|
||||
delete res.rows[i].dataValues.idOperadorRegreso;
|
||||
delete res.rows[i].dataValues.idOperadorCancelacion;
|
||||
delete res.rows[i].dataValues.idEquipo;
|
||||
delete res.rows[i].dataValues.Equipo;
|
||||
delete res.rows[i].dataValues.Usuario.dataValues.idTipoUsuario;
|
||||
delete res.rows[i].dataValues.Usuario.dataValues.idCarrera;
|
||||
delete res.rows[i].dataValues.Usuario.dataValues.password;
|
||||
delete res.rows[i].dataValues.Usuario.dataValues.multa;
|
||||
delete res.rows[i].dataValues.Usuario.dataValues.activo;
|
||||
if (res.rows[i].OperadorEntrega) {
|
||||
delete res.rows[i].dataValues.OperadorEntrega.dataValues.password;
|
||||
delete res.rows[i].dataValues.OperadorEntrega.dataValues.activo;
|
||||
delete res.rows[i].dataValues.OperadorEntrega.dataValues.idTipoUsuario;
|
||||
}
|
||||
if (res.rows[i].OperadorRegreso) {
|
||||
delete res.rows[i].dataValues.OperadorRegreso.dataValues.password;
|
||||
delete res.rows[i].dataValues.OperadorRegreso.dataValues.activo;
|
||||
delete res.rows[i].dataValues.OperadorRegreso.dataValues.idTipoUsuario;
|
||||
}
|
||||
if (res.rows[i].OperadorCancelacion) {
|
||||
delete res.rows[i].dataValues.OperadorCancelacion.dataValues.password;
|
||||
delete res.rows[i].dataValues.OperadorCancelacion.dataValues.activo;
|
||||
delete res.rows[i].dataValues.OperadorCancelacion.dataValues
|
||||
.idTipoUsuario;
|
||||
}
|
||||
}
|
||||
return { count: res.count, historialEquipo: res.rows };
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -10,8 +10,12 @@ const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
||||
const Usuario = require(`${dbPath}/Usuario`);
|
||||
|
||||
const historialUsuario = async (body) => {
|
||||
const idUsuario = validar.validarId(body.idUsuario);
|
||||
const pagina = validar.validarNumero(body.pagina, true);
|
||||
const pagina = validar.validarNumeroEntero(body.pagina, 'página', false);
|
||||
const idUsuario = validar.validarNumeroEntero(
|
||||
body.idUsuario,
|
||||
'id usuario',
|
||||
true
|
||||
);
|
||||
|
||||
return Prestamo.findAndCountAll({
|
||||
include: [
|
||||
@@ -21,53 +25,43 @@ const historialUsuario = async (body) => {
|
||||
{
|
||||
model: Carrito,
|
||||
include: [{ model: TipoCarrito }, { model: Modulo }],
|
||||
attributes: ['idCarrito', 'carrito'],
|
||||
},
|
||||
{ model: Programa },
|
||||
],
|
||||
attributes: ['idEquipo', 'numeroSerie', 'numeroInventario', 'equipo'],
|
||||
},
|
||||
{
|
||||
model: Usuario,
|
||||
where: { idUsuario },
|
||||
attributes: ['idUsuario', 'usuario', 'nombre'],
|
||||
},
|
||||
{
|
||||
model: Operador,
|
||||
as: 'OperadorEntrega',
|
||||
attributes: ['idOperador', 'operador'],
|
||||
},
|
||||
{
|
||||
model: Operador,
|
||||
as: 'OperadorRegreso',
|
||||
attributes: ['idOperador', 'operador'],
|
||||
},
|
||||
{ model: Usuario, where: { idUsuario } },
|
||||
{ model: Operador, as: 'OperadorRegreso' },
|
||||
{ model: Operador, as: 'OperadorEntrega' },
|
||||
{ model: Operador, as: 'OperadorCancelacion' },
|
||||
],
|
||||
limit: 25,
|
||||
offset: 25 * (pagina - 1),
|
||||
order: [['createdAt', 'DESC']],
|
||||
}).then((res) => {
|
||||
for (let i = 0; i < res.rows.length; i++) {
|
||||
delete res.rows[i].dataValues.idOperadorEntrega;
|
||||
delete res.rows[i].dataValues.idOperadorRegreso;
|
||||
delete res.rows[i].dataValues.idOperadorCancelacion;
|
||||
delete res.rows[i].dataValues.idUsuario;
|
||||
delete res.rows[i].dataValues.idEquipo;
|
||||
delete res.rows[i].dataValues.Usuario;
|
||||
delete res.rows[i].dataValues.Equipo.dataValues.idCarrito;
|
||||
delete res.rows[i].dataValues.Equipo.dataValues.idStatus;
|
||||
delete res.rows[i].dataValues.Equipo.dataValues.idPrograma;
|
||||
delete res.rows[i].dataValues.Equipo.dataValues.updatedAt;
|
||||
delete res.rows[i].dataValues.Equipo.dataValues.Carrito.dataValues
|
||||
.idModulo;
|
||||
delete res.rows[i].dataValues.Equipo.dataValues.Carrito.dataValues
|
||||
.idTipoCarrito;
|
||||
delete res.rows[i].dataValues.Equipo.dataValues.Carrito.dataValues.activo;
|
||||
if (res.rows[i].OperadorEntrega) {
|
||||
delete res.rows[i].dataValues.OperadorEntrega.dataValues.password;
|
||||
delete res.rows[i].dataValues.OperadorEntrega.dataValues.activo;
|
||||
delete res.rows[i].dataValues.OperadorEntrega.dataValues.idTipoUsuario;
|
||||
}
|
||||
if (res.rows[i].OperadorRegreso) {
|
||||
delete res.rows[i].dataValues.OperadorRegreso.dataValues.password;
|
||||
delete res.rows[i].dataValues.OperadorRegreso.dataValues.activo;
|
||||
delete res.rows[i].dataValues.OperadorRegreso.dataValues.idTipoUsuario;
|
||||
}
|
||||
if (res.rows[i].OperadorCancelacion) {
|
||||
delete res.rows[i].dataValues.OperadorCancelacion.dataValues.password;
|
||||
delete res.rows[i].dataValues.OperadorCancelacion.dataValues.activo;
|
||||
delete res.rows[i].dataValues.OperadorCancelacion.dataValues
|
||||
.idTipoUsuario;
|
||||
}
|
||||
}
|
||||
return { count: res.count, historialUsuario: res.rows };
|
||||
attributes: [
|
||||
'idPrestamo',
|
||||
'activo',
|
||||
'horaMaxRecoger',
|
||||
'horaInicio',
|
||||
'horaFin',
|
||||
'horaEntrega',
|
||||
'canceladoUsuario',
|
||||
'canceladoOperador',
|
||||
'regresoInmediato',
|
||||
'createdAt',
|
||||
],
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -1,43 +1,55 @@
|
||||
const moment = require('moment');
|
||||
const { validarId } = require('../../helper/validar');
|
||||
const { Op } = require('sequelize');
|
||||
const io = require('../../socket');
|
||||
const { validarNumeroEntero } = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Carrito = require(`${dbPath}/Carrito`);
|
||||
const Equipo = require(`${dbPath}/Equipo`);
|
||||
const Modulo = require(`${dbPath}/Modulo`);
|
||||
const Prestamo = require(`${dbPath}/Prestamo`);
|
||||
const Programa = require(`${dbPath}/Programa`);
|
||||
const Status = require(`${dbPath}/Status`);
|
||||
const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
||||
const Usuario = require(`${dbPath}/Usuario`);
|
||||
|
||||
const pedir = async (body) => {
|
||||
const ahora = moment();
|
||||
const horaMax = moment().format('20:00:00');
|
||||
const horaMin = moment().format('09:00:00');
|
||||
const idUsuario = validarId(body.idUsuario);
|
||||
const idTipoCarrito = validarId(body.idTipoCarrito);
|
||||
const idPrograma = body.idPrograma ? validarId(body.idPrograma) : null;
|
||||
const idModulo = idPrograma ? 1 : validarId(body.idModulo);
|
||||
const horaMax = moment(`${ahora.format('YYYY-MM-DD')} 18:45`);
|
||||
const horaMin = moment(`${ahora.format('YYYY-MM-DD')} 09:00`);
|
||||
const idUsuario = validarNumeroEntero(body.idUsuario, 'id usuario', true);
|
||||
const idTipoCarrito = validarNumeroEntero(
|
||||
body.idTipoCarrito,
|
||||
'id tipo carrito',
|
||||
true
|
||||
);
|
||||
const idPrograma = body.idPrograma
|
||||
? validarNumeroEntero(body.idPrograma, 'id programa', true)
|
||||
: '';
|
||||
const idModulo = idPrograma
|
||||
? 1
|
||||
: validarNumeroEntero(body.idModulo, 'id modulo', true);
|
||||
let whereEquipo = { idStatus: 4 };
|
||||
let idEquipo;
|
||||
|
||||
if (ahora.day() === 6 || ahora.day() === 0)
|
||||
throw new Error(
|
||||
'No se puede pedir un equipo de cómputo los días sabados y domingos.'
|
||||
);
|
||||
if (ahora > horaMax)
|
||||
throw new Error('Ya no se puede realizar un préstamo el día de hoy.');
|
||||
if (ahora < horaMin)
|
||||
throw new Error('Aún es muy temprano para realizar un préstamo.');
|
||||
return TipoCarrito.findOne({ where: { idTipoCarrito } })
|
||||
.then((res) => {
|
||||
if (ahora.format('HH:mm:ss') > horaMax)
|
||||
throw new Error('Es demasido tarde para otorgar prestamos');
|
||||
if (ahora.format('HH:mm:ss') < horaMin)
|
||||
throw new Error('Es demasido temprano para otorgar prestamos');
|
||||
return Prestamo.findOne({ where: { idUsuario } });
|
||||
})
|
||||
.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) => {
|
||||
if (!res && idPrograma) throw new Error('No existe este programa.');
|
||||
if (idPrograma) whereEquipo.idPrograma = idPrograma;
|
||||
return Usuario.findOne({ where: { idUsuario } });
|
||||
})
|
||||
.then((res) => {
|
||||
@@ -45,31 +57,84 @@ const pedir = async (body) => {
|
||||
if (!res.activo) throw new Error('Este usuario no esta activo.');
|
||||
if (res.multa)
|
||||
throw new Error(
|
||||
'Este usuario tiene una multa activa, no puede solicitar un equipo de computo.'
|
||||
'Tienes una multa vigente, no puedes solicitar un equipo de cómputo.'
|
||||
);
|
||||
return Prestamo.findOne({ where: { idUsuario, activo: true } });
|
||||
return Prestamo.findOne({
|
||||
where: {
|
||||
idUsuario,
|
||||
[Op.or]: [
|
||||
{ activo: true },
|
||||
{
|
||||
[Op.and]: [
|
||||
{ regresoInmediato: true },
|
||||
{ idOperadorRegreso: null },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
})
|
||||
.then((res) => {
|
||||
if (res)
|
||||
if (res) {
|
||||
if (res.regresoInmediato)
|
||||
throw new Error(
|
||||
'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(
|
||||
'Este usuario ya cuenta con un prestamo activo. No sepuede solicitar otro equipo de computo.'
|
||||
'Tienes un préstamo activo. No puedes solicitar otro equipo de cómputo.'
|
||||
);
|
||||
return Equipo.findOne({
|
||||
where: {
|
||||
apartado: false,
|
||||
idStatus: 1,
|
||||
idPrograma,
|
||||
},
|
||||
}
|
||||
return Equipo.count({
|
||||
where: whereEquipo,
|
||||
include: [
|
||||
{
|
||||
model: Carrito,
|
||||
where: { idTipoCarrito, idModulo, activo: true },
|
||||
include: [{ model: TipoCarrito }, { model: Modulo }],
|
||||
},
|
||||
{ model: Status },
|
||||
{ model: Programa },
|
||||
],
|
||||
order: [['updatedAt']],
|
||||
});
|
||||
})
|
||||
.then((res) => {
|
||||
if (res === 0)
|
||||
throw new Error(
|
||||
'No existe un equipo de cómputo con las características solicitadas. Intenta elegir otro tipo de equipo.'
|
||||
);
|
||||
return Equipo.count({
|
||||
where: { ...whereEquipo, prestado: false },
|
||||
include: [
|
||||
{
|
||||
model: Carrito,
|
||||
where: { idTipoCarrito, idModulo, activo: true },
|
||||
},
|
||||
],
|
||||
});
|
||||
})
|
||||
.then(async (res) => {
|
||||
if (res === 0)
|
||||
await Equipo.update(
|
||||
{ prestado: false },
|
||||
{
|
||||
where: { ...whereEquipo, prestado: true },
|
||||
include: [
|
||||
{
|
||||
model: Carrito,
|
||||
where: { idTipoCarrito, idModulo, activo: true },
|
||||
},
|
||||
],
|
||||
}
|
||||
);
|
||||
return Equipo.findOne({
|
||||
where: { ...whereEquipo, prestado: false },
|
||||
include: [
|
||||
{
|
||||
model: Carrito,
|
||||
where: { idTipoCarrito, idModulo, activo: true },
|
||||
},
|
||||
],
|
||||
order: [
|
||||
['idCarrito', 'ASC'],
|
||||
['equipo', 'ASC'],
|
||||
],
|
||||
});
|
||||
})
|
||||
.then((res) => {
|
||||
@@ -78,46 +143,21 @@ const pedir = async (body) => {
|
||||
'No hay un equipo de cómputo disponible con las características solicitadas. Intenta más tarde o elige otro tipo de equipo.'
|
||||
);
|
||||
idEquipo = res.idEquipo;
|
||||
return Equipo.update({ apartado: true }, { where: { idEquipo } });
|
||||
return Equipo.update({ idStatus: 1 }, { where: { idEquipo } });
|
||||
})
|
||||
.then((res) =>
|
||||
.then(() =>
|
||||
Prestamo.create({
|
||||
horaMaxRecoger: ahora.add(10, 'm'),
|
||||
idUsuario,
|
||||
idEquipo,
|
||||
})
|
||||
)
|
||||
.then((res) => {
|
||||
return Prestamo.findOne({
|
||||
where: { idPrestamo: res.idPrestamo },
|
||||
include: [
|
||||
{
|
||||
model: Equipo,
|
||||
include: [
|
||||
{
|
||||
model: Carrito,
|
||||
include: [{ model: Modulo }, { model: TipoCarrito }],
|
||||
},
|
||||
{ model: Programa },
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
})
|
||||
.then((res) => {
|
||||
delete res.dataValues.idUsuario;
|
||||
delete res.dataValues.idOperadorEntrega;
|
||||
delete res.dataValues.idOperadorRegreso;
|
||||
delete res.dataValues.idOperadorCancelacion;
|
||||
delete res.dataValues.idEquipo;
|
||||
delete res.dataValues.Equipo.dataValues.idCarrito;
|
||||
delete res.dataValues.Equipo.dataValues.idStatus;
|
||||
delete res.dataValues.Equipo.dataValues.idPrograma;
|
||||
delete res.dataValues.Equipo.dataValues.updatedAt;
|
||||
delete res.dataValues.Equipo.dataValues.Carrito.dataValues.idTipoCarrito;
|
||||
delete res.dataValues.Equipo.dataValues.Carrito.dataValues.idModulo;
|
||||
delete res.dataValues.Equipo.dataValues.Carrito.dataValues.activo;
|
||||
return res;
|
||||
.then(() => {
|
||||
io.getIO().emit('actualizar', { idUsuario });
|
||||
return {
|
||||
message:
|
||||
'Haz solicitado un equipo de cómputo correctamente. Presentate al módulo señalado y muestra tu QR.',
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const { validarId } = require('../../helper/validar');
|
||||
const { validarNumeroEntero } = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Carrera = require(`${dbPath}/Carrera`);
|
||||
const Carrito = require(`${dbPath}/Carrito`);
|
||||
@@ -7,12 +7,13 @@ const Modulo = require(`${dbPath}/Modulo`);
|
||||
const Operador = require(`${dbPath}/Operador`);
|
||||
const Prestamo = require(`${dbPath}/Prestamo`);
|
||||
const Programa = require(`${dbPath}/Programa`);
|
||||
const Status = require(`${dbPath}/Status`);
|
||||
const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
||||
const TipoUsuario = require(`${dbPath}/TipoUsuario`);
|
||||
const Usuario = require(`${dbPath}/Usuario`);
|
||||
|
||||
const prestamo = async (body) => {
|
||||
const idPrestamo = validarId(body.idPrestamo);
|
||||
const idPrestamo = validarNumeroEntero(body.idPrestamo, 'id préstamo', true);
|
||||
|
||||
return Prestamo.findOne({
|
||||
where: { idPrestamo },
|
||||
@@ -23,43 +24,43 @@ const prestamo = async (body) => {
|
||||
{
|
||||
model: Carrito,
|
||||
include: [{ model: TipoCarrito }, { model: Modulo }],
|
||||
attributes: ['idCarrito', 'carrito'],
|
||||
},
|
||||
{ model: Programa },
|
||||
{ model: Status },
|
||||
],
|
||||
attributes: ['idEquipo', 'numeroSerie', 'numeroInventario', 'equipo'],
|
||||
},
|
||||
{ model: Usuario, include: [{ model: TipoUsuario }, { model: Carrera }] },
|
||||
{ model: Operador, as: 'OperadorRegreso' },
|
||||
{ model: Operador, as: 'OperadorEntrega' },
|
||||
{
|
||||
model: Usuario,
|
||||
include: [{ model: TipoUsuario }, { model: Carrera }],
|
||||
attributes: ['idUsuario', 'usuario', 'nombre'],
|
||||
},
|
||||
{
|
||||
model: Operador,
|
||||
as: 'OperadorEntrega',
|
||||
attributes: ['idOperador', 'operador'],
|
||||
},
|
||||
{
|
||||
model: Operador,
|
||||
as: 'OperadorRegreso',
|
||||
attributes: ['idOperador', 'operador'],
|
||||
},
|
||||
],
|
||||
attributes: [
|
||||
'idPrestamo',
|
||||
'activo',
|
||||
'horaMaxRecoger',
|
||||
'horaInicio',
|
||||
'horaFin',
|
||||
'horaEntrega',
|
||||
'canceladoUsuario',
|
||||
'canceladoOperador',
|
||||
'regresoInmediato',
|
||||
'createdAt',
|
||||
],
|
||||
}).then((res) => {
|
||||
if (!res) throw new Error('No existe este prestamo.');
|
||||
delete res.dataValues.idUsuario;
|
||||
delete res.dataValues.idOperadorEntrega;
|
||||
delete res.dataValues.idOperadorRegreso;
|
||||
delete res.dataValues.idOperadorCancelacion;
|
||||
delete res.dataValues.idEquipo;
|
||||
delete res.dataValues.Equipo.dataValues.idPrograma;
|
||||
delete res.dataValues.Equipo.dataValues.idStatus;
|
||||
delete res.dataValues.Equipo.dataValues.idCarrito;
|
||||
delete res.dataValues.Equipo.dataValues.updatedAt;
|
||||
delete res.dataValues.Equipo.dataValues.Carrito.dataValues.idTipoCarrito;
|
||||
delete res.dataValues.Equipo.dataValues.Carrito.dataValues.idModulo;
|
||||
delete res.dataValues.Equipo.dataValues.Carrito.dataValues.activo;
|
||||
delete res.dataValues.Usuario.dataValues.idTipoUsuario;
|
||||
delete res.dataValues.Usuario.dataValues.idCarrera;
|
||||
delete res.dataValues.Usuario.dataValues.password;
|
||||
delete res.dataValues.Usuario.dataValues.multa;
|
||||
delete res.dataValues.Usuario.dataValues.activo;
|
||||
if (res.OperadorEntrega) {
|
||||
delete res.dataValues.OperadorEntrega.dataValues.password;
|
||||
delete res.dataValues.OperadorEntrega.dataValues.activo;
|
||||
delete res.dataValues.OperadorEntrega.dataValues.idTipoUsuario;
|
||||
}
|
||||
if (res.OperadorRegreso) {
|
||||
delete res.dataValues.OperadorRegreso.dataValues.password;
|
||||
delete res.dataValues.OperadorRegreso.dataValues.activo;
|
||||
delete res.dataValues.OperadorRegreso.dataValues.idTipoUsuario;
|
||||
}
|
||||
if (!res) throw new Error('No existe este préstamo.');
|
||||
return res;
|
||||
});
|
||||
};
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
const { Op } = require('sequelize');
|
||||
const { validarAlfanumerico } = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Carrera = require(`${dbPath}/Carrera`);
|
||||
const Carrito = require(`${dbPath}/Carrito`);
|
||||
const Equipo = require(`${dbPath}/Equipo`);
|
||||
const Modulo = require(`${dbPath}/Modulo`);
|
||||
const Operador = require(`${dbPath}/Operador`);
|
||||
const Prestamo = require(`${dbPath}/Prestamo`);
|
||||
const Programa = require(`${dbPath}/Programa`);
|
||||
const Status = require(`${dbPath}/Status`);
|
||||
const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
||||
const TipoUsuario = require(`${dbPath}/TipoUsuario`);
|
||||
const Usuario = require(`${dbPath}/Usuario`);
|
||||
|
||||
const prestamoNumeroInventario = async (body) => {
|
||||
const numeroInventario = validarAlfanumerico(
|
||||
body.numeroInventario,
|
||||
'numero de inventario',
|
||||
true,
|
||||
20
|
||||
);
|
||||
|
||||
return Prestamo.findOne({
|
||||
where: {
|
||||
[Op.or]: [
|
||||
{ activo: true },
|
||||
{
|
||||
[Op.and]: [{ regresoInmediato: true }, { idOperadorRegreso: null }],
|
||||
},
|
||||
],
|
||||
},
|
||||
include: [
|
||||
{
|
||||
model: Equipo,
|
||||
where: { numeroInventario },
|
||||
include: [
|
||||
{
|
||||
model: Carrito,
|
||||
include: [{ model: TipoCarrito }, { model: Modulo }],
|
||||
attributes: ['idCarrito', 'carrito'],
|
||||
},
|
||||
{ model: Programa },
|
||||
{ model: Status },
|
||||
],
|
||||
attributes: ['idEquipo', 'numeroSerie', 'numeroInventario', 'equipo'],
|
||||
},
|
||||
{
|
||||
model: Usuario,
|
||||
include: [{ model: TipoUsuario }, { model: Carrera }],
|
||||
attributes: ['idUsuario', 'usuario', 'nombre'],
|
||||
},
|
||||
{
|
||||
model: Operador,
|
||||
as: 'OperadorEntrega',
|
||||
attributes: ['idOperador', 'operador'],
|
||||
},
|
||||
{
|
||||
model: Operador,
|
||||
as: 'OperadorRegreso',
|
||||
attributes: ['idOperador', 'operador'],
|
||||
},
|
||||
],
|
||||
attributes: [
|
||||
'idPrestamo',
|
||||
'activo',
|
||||
'horaMaxRecoger',
|
||||
'horaInicio',
|
||||
'horaFin',
|
||||
'horaEntrega',
|
||||
'canceladoUsuario',
|
||||
'canceladoOperador',
|
||||
'regresoInmediato',
|
||||
'createdAt',
|
||||
],
|
||||
}).then((res) => {
|
||||
if (!res)
|
||||
throw new Error(
|
||||
'No existe un préstamo activo con este número de inventario.'
|
||||
);
|
||||
return res;
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = prestamoNumeroInventario;
|
||||
@@ -1,52 +1,50 @@
|
||||
const { validarId } = require('../../helper/validar');
|
||||
const { validarNumeroEntero } = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Carrito = require(`${dbPath}/Carrito`);
|
||||
const Equipo = require(`${dbPath}/Equipo`);
|
||||
const Modulo = require(`${dbPath}/Modulo`);
|
||||
const Prestamo = require(`${dbPath}/Prestamo`);
|
||||
const Programa = require(`${dbPath}/Programa`);
|
||||
const Status = require(`${dbPath}/Status`);
|
||||
const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
||||
const Usuario = require(`${dbPath}/Usuario`);
|
||||
|
||||
const prestamo = async (body) => {
|
||||
const idUsuario = validarId(body.idUsuario);
|
||||
const prestamoUsuario = async (body) => {
|
||||
const idUsuario = validarNumeroEntero(body.idUsuario, 'id usuario', true);
|
||||
|
||||
return Usuario.findOne({ where: { idUsuario } })
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe este usuario.');
|
||||
|
||||
return Prestamo.findOne({
|
||||
where: { idUsuario, activo: true },
|
||||
include: [
|
||||
{
|
||||
model: Equipo,
|
||||
include: [
|
||||
{
|
||||
model: Carrito,
|
||||
include: [{ model: TipoCarrito }, { model: Modulo }],
|
||||
},
|
||||
{ model: Programa },
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) return null;
|
||||
delete res.dataValues.idUsuario;
|
||||
delete res.dataValues.idOperadorEntrega;
|
||||
delete res.dataValues.idOperadorRegreso;
|
||||
delete res.dataValues.idOperadorCancelacion;
|
||||
delete res.dataValues.idEquipo;
|
||||
delete res.dataValues.Equipo.dataValues.idPrograma;
|
||||
delete res.dataValues.Equipo.dataValues.idStatus;
|
||||
delete res.dataValues.Equipo.dataValues.idCarrito;
|
||||
delete res.dataValues.Equipo.dataValues.updatedAt;
|
||||
delete res.dataValues.Equipo.dataValues.Carrito.dataValues.idTipoCarrito;
|
||||
delete res.dataValues.Equipo.dataValues.Carrito.dataValues.idModulo;
|
||||
delete res.dataValues.Equipo.dataValues.Carrito.dataValues.activo;
|
||||
return res;
|
||||
return Usuario.findOne({ where: { idUsuario } }).then((res) => {
|
||||
if (!res) throw new Error('No existe este usuario.');
|
||||
return Prestamo.findOne({
|
||||
where: { idUsuario, activo: true },
|
||||
include: [
|
||||
{
|
||||
model: Equipo,
|
||||
include: [
|
||||
{
|
||||
model: Carrito,
|
||||
include: [{ model: TipoCarrito }, { model: Modulo }],
|
||||
attributes: ['idCarrito', 'carrito'],
|
||||
},
|
||||
{ model: Status },
|
||||
{ model: Programa },
|
||||
],
|
||||
attributes: ['idEquipo', 'numeroSerie', 'numeroInventario', 'equipo'],
|
||||
},
|
||||
],
|
||||
attributes: [
|
||||
'idPrestamo',
|
||||
'activo',
|
||||
'horaMaxRecoger',
|
||||
'horaInicio',
|
||||
'horaFin',
|
||||
'horaEntrega',
|
||||
'canceladoUsuario',
|
||||
'canceladoOperador',
|
||||
'regresoInmediato',
|
||||
'createdAt',
|
||||
],
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = prestamo;
|
||||
module.exports = prestamoUsuario;
|
||||
|
||||
@@ -1,16 +1,25 @@
|
||||
const moment = require('moment');
|
||||
const multar = require('../Multa/multar');
|
||||
const { validarId } = require('../../helper/validar');
|
||||
const prestamo = require('./prestamoUsuario');
|
||||
const io = require('../../socket');
|
||||
const { validarNumeroEntero } = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
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 regresar = async (body) => {
|
||||
const idPrestamo = validarId(body.idPrestamo);
|
||||
const idOperadorRegreso = validarId(body.idOperadorRegreso);
|
||||
const ahora = moment();
|
||||
const ahoraAux = moment();
|
||||
const idPrestamo = validarNumeroEntero(body.idPrestamo, 'id préstamo', true);
|
||||
const idOperadorRegreso = validarNumeroEntero(
|
||||
body.idOperadorRegreso,
|
||||
'id operador regreso',
|
||||
true
|
||||
);
|
||||
const update = { idOperadorRegreso };
|
||||
let diferencia = null;
|
||||
let idUsuario = null;
|
||||
|
||||
return Operador.findOne({ where: { idOperador: idOperadorRegreso } })
|
||||
.then((res) => {
|
||||
@@ -22,33 +31,38 @@ const regresar = async (body) => {
|
||||
})
|
||||
.then(async (res) => {
|
||||
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.enUso)
|
||||
throw new Error('Aun no se ha entregado el equipo al usuario.');
|
||||
|
||||
if (res.horaFin < ahora) {
|
||||
await multar({
|
||||
idOperadorMulta: idOperadorRegreso,
|
||||
idPrestamo: res.idPrestamo,
|
||||
idInfraccion: 1,
|
||||
descripcion: 'Demora',
|
||||
});
|
||||
idUsuario = res.idUsuario;
|
||||
if (!res.activo && res.idOperadorRegreso)
|
||||
throw new Error('Este préstamo ya no esta activo.');
|
||||
if (res.Equipo.idStatus === 1)
|
||||
throw new Error('Aún no se ha entregado el equipo al usuario.');
|
||||
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(() =>
|
||||
Usuario.update({ multa: true }, { where: { idUsuario } })
|
||||
);
|
||||
}
|
||||
|
||||
return Equipo.update(
|
||||
{ enUso: false, apartado: false },
|
||||
{ where: { idEquipo: res.Equipo.idEquipo } }
|
||||
{ idStatus: 4 },
|
||||
{ where: { idEquipo: res.idEquipo } }
|
||||
);
|
||||
})
|
||||
.then(async (res) => {
|
||||
await Prestamo.update(
|
||||
{ idOperadorRegreso, horaEntrega: ahora.format(), activo: false },
|
||||
{ where: { idPrestamo } }
|
||||
);
|
||||
})
|
||||
.then((res) => ({
|
||||
message: 'Se ha regresado correctamente el equipo de cómputo.',
|
||||
}));
|
||||
.then(() => Prestamo.update(update, { where: { idPrestamo } }))
|
||||
.then(() => {
|
||||
io.getIO().emit('actualizar', { idUsuario });
|
||||
return {
|
||||
message: 'Se ha regresado correctamente el equipo de cómputo.',
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = regresar;
|
||||
|
||||
@@ -1,58 +1,87 @@
|
||||
const moment = require('moment');
|
||||
const multar = require('../Multa/multar');
|
||||
const { Op } = require('sequelize');
|
||||
const io = require('../../socket');
|
||||
const validar = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
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();
|
||||
const ahoraAux = moment();
|
||||
const numeroInventario = validar.validarAlfanumerico(
|
||||
body.numeroInventario,
|
||||
'El numero de inventario',
|
||||
'numero de inventario',
|
||||
true,
|
||||
20
|
||||
);
|
||||
const idOperadorRegreso = validar.validarId(body.idOperadorRegreso);
|
||||
const ahora = moment();
|
||||
let idPrestamo;
|
||||
const idOperadorRegreso = validar.validarNumeroEntero(
|
||||
body.idOperadorRegreso,
|
||||
'id operador regreso',
|
||||
true
|
||||
);
|
||||
const update = { idOperadorRegreso };
|
||||
let diferencia = null;
|
||||
let idPrestamo = null;
|
||||
let idUsuario = null;
|
||||
|
||||
return Operador.findOne({ where: { idOperador: idOperadorRegreso } })
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe este operador.');
|
||||
return Prestamo.findOne({
|
||||
where: { activo: true },
|
||||
where: {
|
||||
[Op.or]: [
|
||||
{ activo: true },
|
||||
{
|
||||
[Op.and]: [
|
||||
{ regresoInmediato: true },
|
||||
{ idOperadorRegreso: null },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
include: [{ model: Equipo, where: { numeroInventario } }],
|
||||
});
|
||||
})
|
||||
.then(async (res) => {
|
||||
if (!res)
|
||||
throw new Error('No existe un prestamo activo con este equipo.');
|
||||
if (!res.Equipo.enUso)
|
||||
throw new Error('Aun no se ha entregado el equipo al usuario.');
|
||||
throw new Error(
|
||||
'No existe un préstamo activo con este equipo de cómputo.'
|
||||
);
|
||||
if (res.Equipo.idStatus === 1)
|
||||
throw new Error('Aún no se ha entregado el equipo al usuario.');
|
||||
idPrestamo = res.idPrestamo;
|
||||
|
||||
if (res.horaFin < ahora) {
|
||||
await multar({
|
||||
idOperadorMulta: idOperadorRegreso,
|
||||
idPrestamo: res.idPrestamo,
|
||||
idInfraccion: 1,
|
||||
descripcion: 'Demora',
|
||||
});
|
||||
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(() =>
|
||||
Usuario.update({ multa: true }, { where: { idUsuario } })
|
||||
);
|
||||
}
|
||||
return Equipo.update(
|
||||
{ enUso: false, apartado: false },
|
||||
{ where: { idEquipo: res.Equipo.idEquipo } }
|
||||
{ idStatus: 4 },
|
||||
{ where: { idEquipo: res.idEquipo } }
|
||||
);
|
||||
})
|
||||
.then((res) => {
|
||||
Prestamo.update(
|
||||
{ idOperadorRegreso, horaEntrega: ahora.format(), activo: false },
|
||||
{ where: { idPrestamo } }
|
||||
);
|
||||
})
|
||||
.then((res) => ({
|
||||
message: 'Se ha regresado correctamente el equio de computo.',
|
||||
}));
|
||||
.then(() => Prestamo.update(update, { where: { idPrestamo } }))
|
||||
.then(() => {
|
||||
io.getIO().emit('actualizar', { idUsuario });
|
||||
return {
|
||||
message: 'Se ha regresado correctamente el equipo de cómputo.',
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = regresarNumeroInventario;
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
const moment = require('moment');
|
||||
const io = require('../../socket');
|
||||
const { validarNumeroEntero } = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Equipo = require(`${dbPath}/Equipo`);
|
||||
const Multa = require(`${dbPath}/Multa`);
|
||||
const Prestamo = require(`${dbPath}/Prestamo`);
|
||||
const Usuario = require(`${dbPath}/Usuario`);
|
||||
|
||||
const regresoInmediato = async (body) => {
|
||||
const ahora = moment();
|
||||
const ahoraAux = moment();
|
||||
const idPrestamo = validarNumeroEntero(body.idPrestamo, 'id préstamo', true);
|
||||
let diferencia = null;
|
||||
let idUsuario = null;
|
||||
|
||||
return Prestamo.findOne({
|
||||
where: { idPrestamo },
|
||||
include: [{ model: Equipo }],
|
||||
})
|
||||
.then(async (res) => {
|
||||
if (!res) throw new Error('No existe este préstamo.');
|
||||
idUsuario = res.idUsuario;
|
||||
if (!res.activo) throw new Error('Este préstamo ya no esta activo.');
|
||||
if (res.Equipo.idStatus === 1)
|
||||
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({
|
||||
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(() =>
|
||||
Usuario.update({ multa: true }, { where: { idUsuario } })
|
||||
);
|
||||
return Equipo.update(
|
||||
{ idStatus: 3 },
|
||||
{ where: { idEquipo: res.idEquipo } }
|
||||
);
|
||||
})
|
||||
.then(() =>
|
||||
Prestamo.update(
|
||||
{ horaEntrega: ahora.format(), activo: false, regresoInmediato: true },
|
||||
{ where: { idPrestamo } }
|
||||
)
|
||||
)
|
||||
.then(() => {
|
||||
io.getIO().emit('actualizar', { idUsuario });
|
||||
return {
|
||||
message: 'Se ha regresado correctamente el equipo de cómputo.',
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = regresoInmediato;
|
||||
@@ -0,0 +1,67 @@
|
||||
const moment = require('moment');
|
||||
const io = require('../../socket');
|
||||
const { validarAlfanumerico } = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Equipo = require(`${dbPath}/Equipo`);
|
||||
const Multa = require(`${dbPath}/Multa`);
|
||||
const Prestamo = require(`${dbPath}/Prestamo`);
|
||||
const Usuario = require(`${dbPath}/Usuario`);
|
||||
|
||||
const regresoInmediatoNumeroInventario = async (body) => {
|
||||
const ahora = moment();
|
||||
const ahoraAux = moment();
|
||||
const numeroInventario = validarAlfanumerico(
|
||||
body.numeroInventario,
|
||||
'numero de inventario',
|
||||
true,
|
||||
20
|
||||
);
|
||||
let diferencia = null;
|
||||
let idPrestamo = null;
|
||||
let idUsuario = null;
|
||||
|
||||
return Prestamo.findOne({
|
||||
where: { activo: true },
|
||||
include: [{ model: Equipo, where: { numeroInventario } }],
|
||||
})
|
||||
.then(async (res) => {
|
||||
if (!res)
|
||||
throw new Error(
|
||||
'No existe un préstamo activo con este número de inventario.'
|
||||
);
|
||||
idUsuario = res.idUsuario;
|
||||
if (!res.activo) throw new Error('Este préstamo ya no esta activo.');
|
||||
if (res.Equipo.idStatus === 1)
|
||||
throw new Error('Aún no se ha entregado el equipo al usuario.');
|
||||
diferencia = parseInt((ahora - moment(res.horaFin)) / 60000);
|
||||
idPrestamo = res.idPrestamo;
|
||||
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(() =>
|
||||
Usuario.update({ multa: true }, { where: { idUsuario } })
|
||||
);
|
||||
return Equipo.update(
|
||||
{ idStatus: 3 },
|
||||
{ where: { idEquipo: res.idEquipo } }
|
||||
);
|
||||
})
|
||||
.then(() =>
|
||||
Prestamo.update(
|
||||
{ horaEntrega: ahora.format(), activo: false, regresoInmediato: true },
|
||||
{ where: { idPrestamo } }
|
||||
)
|
||||
)
|
||||
.then(() => {
|
||||
io.getIO().emit('actualizar', { idUsuario });
|
||||
return {
|
||||
message: 'Se ha regresado correctamente el equipo de cómputo.',
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = regresoInmediatoNumeroInventario;
|
||||
@@ -0,0 +1,141 @@
|
||||
const moment = require('moment');
|
||||
const { convertArrayToCSV } = require('convert-array-to-csv');
|
||||
const { Op } = require('sequelize');
|
||||
const helperPath = '../../helper';
|
||||
const helper = require(`${helperPath}/helper`);
|
||||
const validar = require(`${helperPath}/validar`);
|
||||
const dbPath = '../../db/tablas';
|
||||
const Carrera = require(`${dbPath}/Carrera`);
|
||||
const Carrito = require(`${dbPath}/Carrito`);
|
||||
const Equipo = require(`${dbPath}/Equipo`);
|
||||
const Modulo = require(`${dbPath}/Modulo`);
|
||||
const Operador = require(`${dbPath}/Operador`);
|
||||
const Prestamo = require(`${dbPath}/Prestamo`);
|
||||
const Programa = require(`${dbPath}/Programa`);
|
||||
const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
||||
const TipoUsuario = require(`${dbPath}/TipoUsuario`);
|
||||
const Usuario = require(`${dbPath}/Usuario`);
|
||||
|
||||
const reporte = async (body) => {
|
||||
const inicio = validar.validarFecha(body.inicio, 'fecha de inicio', false);
|
||||
const fin = validar.validarFecha(body.fin, 'fecha fin', false);
|
||||
const idCarrera = body.idCarrera
|
||||
? validar.validarNumeroEntero(body.idCarrera, 'id carrera', true)
|
||||
: '';
|
||||
const idTipoUsuario = body.idTipoUsuario
|
||||
? validar.validarNumeroEntero(body.idTipoUsuario, 'id tipo usuario', true)
|
||||
: '';
|
||||
const idTipoCarrito = body.idTipoCarrito
|
||||
? validar.validarNumeroEntero(body.idTipoCarrito, 'id tipo carrito', true)
|
||||
: '';
|
||||
const path = `server/uploads/reporte.csv`;
|
||||
const data = [];
|
||||
|
||||
return Prestamo.findAll({
|
||||
where: {
|
||||
[Op.and]: [
|
||||
{ createdAt: { [Op.gte]: inicio.format('YYYY-MM-DD') } },
|
||||
{ createdAt: { [Op.lte]: fin.format('YYYY-MM-DD') } },
|
||||
],
|
||||
},
|
||||
include: [
|
||||
{
|
||||
model: Equipo,
|
||||
include: [
|
||||
{
|
||||
model: Carrito,
|
||||
include: [{ model: TipoCarrito }, { model: Modulo }],
|
||||
},
|
||||
{ model: Programa },
|
||||
],
|
||||
},
|
||||
{
|
||||
model: Usuario,
|
||||
include: [{ model: Carrera }, { model: TipoUsuario }],
|
||||
},
|
||||
{
|
||||
model: Operador,
|
||||
as: 'OperadorEntrega',
|
||||
},
|
||||
{
|
||||
model: Operador,
|
||||
as: 'OperadorRegreso',
|
||||
},
|
||||
],
|
||||
})
|
||||
.then(async (res) => {
|
||||
for (let i = 0; i < res.length; i++) {
|
||||
let agregar = false;
|
||||
|
||||
if (idTipoCarrito) {
|
||||
if (idTipoCarrito === res[i].Equipo.Carrito.idTipoCarrito) {
|
||||
if (idTipoUsuario) {
|
||||
if (idTipoUsuario === res[i].Usuario.idTipoUsuario) {
|
||||
if (idCarrera) {
|
||||
if (idCarrera === res[i].Usuario.idCarrera) agregar = true;
|
||||
} else agregar = true;
|
||||
}
|
||||
} else if (idCarrera) {
|
||||
if (idCarrera === res[i].Usuario.idCarrera) agregar = true;
|
||||
} else agregar = true;
|
||||
}
|
||||
} else if (idTipoUsuario) {
|
||||
if (idTipoUsuario === res[i].Usuario.idTipoUsuario) {
|
||||
if (idCarrera) {
|
||||
if (idCarrera === res[i].Usuario.idCarrera) agregar = true;
|
||||
} else agregar = true;
|
||||
}
|
||||
} else if (idCarrera) {
|
||||
if (idCarrera === res[i].Usuario.idCarrera) agregar = true;
|
||||
} else agregar = true;
|
||||
if (agregar)
|
||||
data.push({
|
||||
idPrestamo: res[i].idPrestamo,
|
||||
activo: res[i].activo,
|
||||
fecha: moment(res[i].createdAt).format('YYYY-MM-DD'),
|
||||
hora: moment(res[i].createdAt).format('HH:mm'),
|
||||
horaMaxRecoger: moment(res[i].horaMaxRecoger).format('HH:mm'),
|
||||
horaInicio: res[i].horaInicio
|
||||
? moment(res[i].horaInicio).format('HH:mm')
|
||||
: '',
|
||||
horaFin: res[i].horaFin
|
||||
? moment(res[i].horaFin).format('HH:mm')
|
||||
: '',
|
||||
fechaEntrega: res[i].horaEntrega
|
||||
? moment(res[i].horaEntrega).format('YYYY-MM-DD')
|
||||
: '',
|
||||
horaEntrega: res[i].horaEntrega
|
||||
? moment(res[i].horaEntrega).format('HH:mm')
|
||||
: '',
|
||||
modulo: res[i].Equipo.Carrito.Modulo.modulo,
|
||||
carrito: res[i].Equipo.Carrito.carrito,
|
||||
equipo: res[i].Equipo.equipo,
|
||||
tipoCarrito: res[i].Equipo.Carrito.TipoCarrito.tipoCarrito,
|
||||
programa: res[i].Equipo.Programa
|
||||
? res[i].Equipo.Programa.programa
|
||||
: '',
|
||||
numeroInventario: res[i].Equipo.numeroInventario,
|
||||
numeroSerie: res[i].Equipo.numeroSerie,
|
||||
tipoUsuario: res[i].Usuario.TipoUsuario.tipoUsuario,
|
||||
usuario: res[i].Usuario.usuario,
|
||||
nombre: res[i].Usuario.nombre,
|
||||
carrera: res[i].Usuario.Carrera
|
||||
? res[i].Usuario.Carrera.carrera
|
||||
: '',
|
||||
operadorEntrega: res[i].OperadorEntrega
|
||||
? res[i].OperadorEntrega.operador
|
||||
: '',
|
||||
operadorRegreso: res[i].OperadorRegreso
|
||||
? res[i].OperadorRegreso.operador
|
||||
: '',
|
||||
canceladoUsuario: res[i].canceladoUsuario ? 'si' : 'no',
|
||||
canceladoOperador: res[i].canceladoOperador ? 'si' : 'no',
|
||||
});
|
||||
}
|
||||
await helper.eliminarArchivo(path).catch((err) => {});
|
||||
return helper.crearArchivo(path, convertArrayToCSV(data));
|
||||
})
|
||||
.then(() => path);
|
||||
};
|
||||
|
||||
module.exports = reporte;
|
||||
@@ -1,87 +1,88 @@
|
||||
const moment = require('moment');
|
||||
const { validarId } = require('../../helper/validar');
|
||||
const io = require('../../socket');
|
||||
const { validarNumeroEntero } = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Carrito = require(`${dbPath}/Carrito`);
|
||||
const Equipo = require(`${dbPath}/Equipo`);
|
||||
const Modulo = require(`${dbPath}/Modulo`);
|
||||
const Prestamo = require(`${dbPath}/Prestamo`);
|
||||
const Programa = require(`${dbPath}/Programa`);
|
||||
const Status = require(`${dbPath}/Status`);
|
||||
const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
||||
|
||||
const status = async (body) => {
|
||||
const idPrestamo = validarId(body.idPrestamo);
|
||||
const ahora = moment();
|
||||
const idPrestamo = validarNumeroEntero(body.idPrestamo, 'id préstamo', true);
|
||||
let message = '';
|
||||
let atraso = false;
|
||||
let idUsuario = null;
|
||||
|
||||
return Prestamo.findOne({
|
||||
where: { idPrestamo },
|
||||
include: [
|
||||
{
|
||||
model: Equipo,
|
||||
include: [{ model: Equipo }],
|
||||
})
|
||||
.then(async (res) => {
|
||||
if (!res) throw new Error('No existe este préstamo.');
|
||||
idUsuario = res.idUsuario;
|
||||
if (!res.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 =
|
||||
'Ya paso la hora de entrega. El usuario puede ser acreedor a una multa por el retraso.';
|
||||
atraso = true;
|
||||
} else message = 'El equipo ya fue entregado al usuario.';
|
||||
} else if (moment(res.horaMaxRecoger) < ahora) {
|
||||
await Equipo.update(
|
||||
{ idStatus: 4 },
|
||||
{ where: { idEquipo: res.Equipo.idEquipo } }
|
||||
).then(() =>
|
||||
Prestamo.update(
|
||||
{ activo: false, canceladoOperador: true, idOperadorRegreso: 1 },
|
||||
{ where: { idPrestamo } }
|
||||
)
|
||||
);
|
||||
message =
|
||||
'Ya paso el tiempo limite para recoger el dispositivo. Se ha cancelado tu prestamo.';
|
||||
io.getIO().emit('actualizar', { idUsuario });
|
||||
} else message = 'Aún no se entrega el equipo al usuario.';
|
||||
return Prestamo.findOne({
|
||||
where: { idPrestamo },
|
||||
include: [
|
||||
{
|
||||
model: Carrito,
|
||||
include: [{ model: TipoCarrito }, { model: Modulo }],
|
||||
model: Equipo,
|
||||
include: [
|
||||
{
|
||||
model: Carrito,
|
||||
include: [{ model: TipoCarrito }, { model: Modulo }],
|
||||
attributes: ['idCarrito', 'carrito'],
|
||||
},
|
||||
{ model: Status },
|
||||
{ model: Programa },
|
||||
],
|
||||
attributes: [
|
||||
'idEquipo',
|
||||
'numeroSerie',
|
||||
'numeroInventario',
|
||||
'equipo',
|
||||
],
|
||||
},
|
||||
{ model: Programa },
|
||||
],
|
||||
},
|
||||
],
|
||||
}).then(async (res) => {
|
||||
if (!res) throw new Error('No existe este prestamo.');
|
||||
delete res.dataValues.idUsuario;
|
||||
delete res.dataValues.idOperadorEntrega;
|
||||
delete res.dataValues.idOperadorRegreso;
|
||||
delete res.dataValues.idOperadorCancelacion;
|
||||
delete res.dataValues.idEquipo;
|
||||
delete res.dataValues.Equipo.dataValues.idPrograma;
|
||||
delete res.dataValues.Equipo.dataValues.idStatus;
|
||||
delete res.dataValues.Equipo.dataValues.idCarrito;
|
||||
delete res.dataValues.Equipo.dataValues.updatedAt;
|
||||
delete res.dataValues.Equipo.dataValues.Carrito.dataValues.idTipoCarrito;
|
||||
delete res.dataValues.Equipo.dataValues.Carrito.dataValues.idModulo;
|
||||
delete res.dataValues.Equipo.dataValues.Carrito.dataValues.activo;
|
||||
if (!res.activo) {
|
||||
if (!res.horaEntrega)
|
||||
return {
|
||||
message: 'Este prestamo fue cancelado.',
|
||||
prestamo: res,
|
||||
};
|
||||
return {
|
||||
message: 'Este prestamo no es encuentra activo.',
|
||||
prestamo: res,
|
||||
};
|
||||
} else if (res.Equipo.enUso) {
|
||||
if (moment(res.horaFin) < ahora) {
|
||||
return {
|
||||
message:
|
||||
'Ya paso la hora de entrega. El usuario puede ser acreedor a una multa por el retraso.',
|
||||
prestamo: res,
|
||||
atraso: true,
|
||||
};
|
||||
}
|
||||
return {
|
||||
message: 'El equipo ya fue entregado al usuario.',
|
||||
prestamo: res,
|
||||
};
|
||||
} else if (moment(res.horaMaxRecoger) < ahora) {
|
||||
await Equipo.update(
|
||||
{ apartado: false },
|
||||
{ where: { idEquipo: res.Equipo.idEquipo } }
|
||||
);
|
||||
await Prestamo.update({ activo: false }, { where: { idPrestamo } });
|
||||
res.Equipo.apartado = false;
|
||||
res.activo = false;
|
||||
return {
|
||||
message:
|
||||
'Ya paso el tiempo limite para recoger el dispositivo. Se ha cancelado tu prestamo.',
|
||||
prestamo: res,
|
||||
};
|
||||
}
|
||||
return {
|
||||
message: 'Aun no se entrega el equipo al usuario.',
|
||||
prestamo: res,
|
||||
};
|
||||
});
|
||||
attributes: [
|
||||
'idPrestamo',
|
||||
'activo',
|
||||
'horaMaxRecoger',
|
||||
'horaInicio',
|
||||
'horaFin',
|
||||
'horaEntrega',
|
||||
'canceladoUsuario',
|
||||
'regresoInmediato',
|
||||
'createdAt',
|
||||
],
|
||||
});
|
||||
})
|
||||
.then((res) => ({ message, prestamo: res, atraso }));
|
||||
};
|
||||
|
||||
module.exports = status;
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
const { Op } = require('sequelize');
|
||||
const Programa = require('../../db/tablas/Programa');
|
||||
|
||||
const get = async () => Programa.findAll();
|
||||
const get = async () =>
|
||||
Programa.findAll({
|
||||
where: { [Op.or]: [{ idPrograma: 2 }, { idPrograma: 3 }] },
|
||||
});
|
||||
|
||||
module.exports = get;
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
const { Op } = require('sequelize');
|
||||
const TipoUsuario = require('../../db/tablas/TipoUsuario');
|
||||
|
||||
const get = async () =>
|
||||
TipoUsuario.findAll({ where: { idTipoUsuario: { [Op.gt]: 2 } } });
|
||||
|
||||
module.exports = get;
|
||||
@@ -0,0 +1,145 @@
|
||||
const csv = require('csvtojson');
|
||||
const helperPath = '../../helper';
|
||||
const { validarObjetoVacio } = require(`${helperPath}/validar`);
|
||||
const { eliminarArchivo } = require(`${helperPath}/helper`);
|
||||
const dbPath = '../../db/tablas';
|
||||
const Carrera = require(`${dbPath}/Carrera`);
|
||||
const TipoUsuario = require(`${dbPath}/TipoUsuario`);
|
||||
const Usuario = require(`${dbPath}/Usuario`);
|
||||
|
||||
const cargaMasiva = async (file) => {
|
||||
const path = `server/uploads/${file}`;
|
||||
const usuariosNuevos = [];
|
||||
const usuariosUpdate = [];
|
||||
const errores = [];
|
||||
const avisos = [];
|
||||
|
||||
return csv()
|
||||
.fromFile(path)
|
||||
.then(async (usuarios) => {
|
||||
for (let i = 0; i < usuarios.length; i++) {
|
||||
const mensajeErrBase = `Se salto la linea ${i + 2} por:`;
|
||||
|
||||
if (
|
||||
!usuarios[i].cuenta ||
|
||||
!usuarios[i].apellidop ||
|
||||
!usuarios[i].apellidom ||
|
||||
!usuarios[i].nombrew ||
|
||||
!usuarios[i].tipoUsuario
|
||||
) {
|
||||
if (!usuarios[i].cuenta)
|
||||
errores.push(`${mensajeErrBase} falta variable cuenta.`);
|
||||
if (!usuarios[i].apellidop)
|
||||
errores.push(`${mensajeErrBase} falta variable apellidop.`);
|
||||
if (!usuarios[i].apellidom)
|
||||
errores.push(`${mensajeErrBase} falta variable apellidom.`);
|
||||
if (!usuarios[i].nombrew)
|
||||
errores.push(`${mensajeErrBase} falta variable nombrew.`);
|
||||
if (!usuarios[i].tipoUsuario)
|
||||
errores.push(`${mensajeErrBase} falta variable tipoUsuario.`);
|
||||
continue;
|
||||
}
|
||||
|
||||
const idTipoUsuario = await TipoUsuario.findOne({
|
||||
where: { tipoUsuario: usuarios[i].tipoUsuario },
|
||||
}).then((res) => {
|
||||
if (!res) {
|
||||
errores.push(`${mensajeErrBase} tipo de usuario no valido.`);
|
||||
return null;
|
||||
}
|
||||
return res.idTipoUsuario;
|
||||
});
|
||||
let idCarrera = null;
|
||||
|
||||
if (!idTipoUsuario) continue;
|
||||
if (idTipoUsuario != 3) {
|
||||
if (!usuarios[i].nomplan) {
|
||||
errores.push(`${mensajeErrBase} falta variable nomplan.`);
|
||||
continue;
|
||||
}
|
||||
idCarrera = await Carrera.findOne({
|
||||
where: { carrera: usuarios[i].nomplan },
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) {
|
||||
avisos.push(
|
||||
`Se añadio el posgrado/la carrera ${usuarios[i].nomplan} al catálogo.`
|
||||
);
|
||||
return Carrera.create({ carrera: usuarios[i].nomplan });
|
||||
}
|
||||
return res;
|
||||
})
|
||||
.then((res) => res.idCarrera);
|
||||
}
|
||||
if (usuarios[i].cuenta.length === 8)
|
||||
usuarios[i].cuenta = `0${usuarios[i].cuenta}`;
|
||||
await Usuario.findOne({
|
||||
where: { usuario: usuarios[i].cuenta },
|
||||
include: [{ model: Carrera }],
|
||||
}).then(async (res) => {
|
||||
let usuario = res;
|
||||
|
||||
if (!usuario) {
|
||||
const data = {
|
||||
usuario: usuarios[i].cuenta,
|
||||
nombre: `${usuarios[i].apellidop} ${usuarios[i].apellidom} ${usuarios[i].nombrew}`,
|
||||
idTipoUsuario,
|
||||
};
|
||||
|
||||
if (data.idTipoUsuario != 3) data.idCarrera = idCarrera;
|
||||
await Usuario.create(data)
|
||||
.then((res) =>
|
||||
Usuario.findOne({
|
||||
where: { idUsuario: res.idUsuario },
|
||||
include: [{ model: Carrera }, { model: TipoUsuario }],
|
||||
attributes: ['idUsuario', 'usuario', 'nombre'],
|
||||
})
|
||||
)
|
||||
.then((res) => usuariosNuevos.push(res));
|
||||
} else {
|
||||
let update = {};
|
||||
|
||||
if (!usuario.activo) {
|
||||
update.activo = true;
|
||||
usuariosUpdate.push(
|
||||
`La cuenta del usuario: ${usuario.usuario} fue activada.`
|
||||
);
|
||||
}
|
||||
if (
|
||||
usuario.Carrera &&
|
||||
usuario.Carrera.carrera != usuarios[i].nomplan
|
||||
) {
|
||||
update.idCarrera = idCarrera;
|
||||
usuariosUpdate.push(
|
||||
`Se cambio la carrera del usuario: ${usuario.usuario} de ${usuario.Carrera.carrera} por ${usuarios[i].nomplan}.`
|
||||
);
|
||||
}
|
||||
if (usuario.idTipoUsuario != idTipoUsuario) {
|
||||
update.idTipoUsuario = idTipoUsuario;
|
||||
usuariosUpdate.push(
|
||||
`Se cambio el tipo de usuario del usuario: ${usuario.usuario} de ${usuario.TipoUsuario.tipoUsuario} por ${usuarios[i].tipoUsuario}.`
|
||||
);
|
||||
}
|
||||
if (!validarObjetoVacio(update))
|
||||
await Usuario.update(update, {
|
||||
where: { idUsuario: usuario.idUsuario },
|
||||
});
|
||||
else
|
||||
errores.push(
|
||||
`${mensajeErrBase} no se mando nada para actualizar.`
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
return eliminarArchivo(path);
|
||||
})
|
||||
.then(() => ({
|
||||
message: 'Se subió correctamente el archivo csv.',
|
||||
usuariosNuevos,
|
||||
usuariosUpdate,
|
||||
errores,
|
||||
avisos,
|
||||
}));
|
||||
};
|
||||
|
||||
module.exports = cargaMasiva;
|
||||
@@ -1,126 +0,0 @@
|
||||
const csv = require('csvtojson');
|
||||
const helperPath = '../../helper';
|
||||
const { validarObjetoVacio } = require(`${helperPath}/validar`);
|
||||
const { eliminarArchivo } = require(`${helperPath}/helper`);
|
||||
const dbPath = '../../db/tablas';
|
||||
const Carrera = require(`${dbPath}/Carrera`);
|
||||
const TipoUsuario = require(`${dbPath}/TipoUsuario`);
|
||||
const Usuario = require(`${dbPath}/Usuario`);
|
||||
|
||||
const cargaMasiva = async (file) => {
|
||||
const path = `server/uploads/${file}`;
|
||||
const alumnosNuevos = [];
|
||||
const alumnosUpdate = [];
|
||||
const errores = [];
|
||||
const avisos = [];
|
||||
|
||||
await csv()
|
||||
.fromFile(path)
|
||||
.then(async (alumnos) => {
|
||||
for (let i = 0; i < alumnos.length; i++) {
|
||||
if (alumnos[i].cuenta.length === 8)
|
||||
alumnos[i].cuenta = '0' + alumnos[i].cuenta;
|
||||
await Usuario.findOne({
|
||||
where: { usuario: alumnos[i].cuenta },
|
||||
include: [{ model: Carrera }],
|
||||
}).then(async (res) => {
|
||||
let usuario = res;
|
||||
|
||||
if (!usuario) {
|
||||
await Carrera.findOne({
|
||||
where: { carrera: alumnos[i].nomplan },
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) {
|
||||
avisos.push(
|
||||
`Se añadio el posgrado ${alumnos[i].nomplan} al catalogo.`
|
||||
);
|
||||
return Carrera.create({ carrera: alumnos[i].nomplan });
|
||||
}
|
||||
return res;
|
||||
})
|
||||
.then((res) =>
|
||||
Usuario.create({
|
||||
usuario: alumnos[i].cuenta,
|
||||
nombre: `${alumnos[i].apellidop} ${alumnos[i].apellidom} ${alumnos[i].nombrew}`,
|
||||
idCarrera: res.idCarrera,
|
||||
idTipoUsuario: 5,
|
||||
})
|
||||
)
|
||||
.then((res) =>
|
||||
Usuario.findOne({
|
||||
where: { idUsuario: res.idUsuario },
|
||||
include: [{ model: Carrera }, { model: TipoUsuario }],
|
||||
})
|
||||
)
|
||||
.then((res) => {
|
||||
alumnosNuevos.push({
|
||||
idUsuario: res.idUsuario,
|
||||
usuario: res.usuario,
|
||||
nombre: res.nombre,
|
||||
Carrera: {
|
||||
idCarrera: res.Carrera.idCarrera,
|
||||
carrera: res.Carrera.carrera,
|
||||
},
|
||||
TipoUsuario: {
|
||||
idTipoUsuario: res.TipoUsuario.idTipoUsuario,
|
||||
tipoUsuario: res.TipoUsuario.tipoUsuario,
|
||||
},
|
||||
});
|
||||
});
|
||||
} else {
|
||||
let update = {};
|
||||
|
||||
if (!usuario.activo) {
|
||||
update.activo = true;
|
||||
alumnosUpdate.push(`El alumno ${usuario.usuario} fue activado.`);
|
||||
}
|
||||
if (usuario.Carrera.carrera != alumnos[i].nomplan) {
|
||||
await Carrera.findOne({
|
||||
where: { carrera: alumnos[i].nomplan },
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) {
|
||||
avisos.push(
|
||||
`Se añadio el posgrado ${alumnos[i].nomplan} al catalogo.`
|
||||
);
|
||||
return Carrera.create({ carrera: alumnos[i].nomplan });
|
||||
}
|
||||
return res;
|
||||
})
|
||||
.then((res) => {
|
||||
update.idCarrera = res.idCarrera;
|
||||
alumnosUpdate.push(
|
||||
`Se cambio la carrera del alumno ${usuario.usuario} de ${usuario.Carrera.carrera} por ${res.carrera}.`
|
||||
);
|
||||
});
|
||||
}
|
||||
if (usuario.idTipoUsuario === 3)
|
||||
avisos.push(
|
||||
`El alumno con id ${usuario.idUsuario} y numero de cuenta ${usuario.usuario} tambien es profesor.`
|
||||
);
|
||||
if (usuario.idTipoUsuario === 4) {
|
||||
update.idTipoUsuario = 5;
|
||||
alumnosUpdate.push(
|
||||
`Se cambio el tipo de usuario alumno con id ${usuario.idUsuario} y numero de cuenta ${usuario.usuario}.`
|
||||
);
|
||||
}
|
||||
if (!validarObjetoVacio(update))
|
||||
await Usuario.update(update, {
|
||||
where: { idUsuario: usuario.idUsuario },
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
await eliminarArchivo(path);
|
||||
});
|
||||
return {
|
||||
message: 'Se subio correctamente el archivo csv.',
|
||||
alumnosNuevos,
|
||||
alumnosUpdate,
|
||||
errores,
|
||||
avisos,
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = cargaMasiva;
|
||||
@@ -1,21 +1,27 @@
|
||||
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');
|
||||
|
||||
const crear = async (body) => {
|
||||
const idUsuario = validar.validarId(body.idUsuario);
|
||||
const telefono = validar.validarNumero(body.telefono, false, 15);
|
||||
const idUsuario = validar.validarNumeroEntero(
|
||||
body.idUsuario,
|
||||
'id usuario',
|
||||
true
|
||||
);
|
||||
const telefono = validar.validarNumero(body.telefono, 'teléfono', true, 15);
|
||||
const password = encriptar.generarPassword();
|
||||
let correo = '@pcpuma.acatlan.unam.mx';
|
||||
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 + correo;
|
||||
email = `${res.usuario}@pcpuma.acatlan.unam.mx`;
|
||||
correo = correoPcPuma(password);
|
||||
return Usuario.update(
|
||||
{
|
||||
password: encriptar.encriptar(password),
|
||||
@@ -24,11 +30,8 @@ const crear = async (body) => {
|
||||
{ where: { idUsuario } }
|
||||
);
|
||||
})
|
||||
.then((res) => {
|
||||
// return gmail('Contraseña',correo,"")
|
||||
return gmail('Contraseña', 'lemuelhelonmarquezrosas@gmail.com', 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.',
|
||||
}));
|
||||
|
||||
@@ -10,70 +10,59 @@ const escolares = async (body) => {
|
||||
|
||||
return Usuario.findOne({
|
||||
where: { usuario: numeroCuenta },
|
||||
include: [{ model: Carrera }, { model: TipoUsuario }],
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) {
|
||||
let usuario = { Carrera: {} };
|
||||
let esAlumno = false;
|
||||
attributes: ['idUsuario', 'password'],
|
||||
}).then((res) => {
|
||||
if (!res) {
|
||||
let usuario = { Carrera: null };
|
||||
let esAlumno = false;
|
||||
|
||||
return obtenerAlumno(numeroCuenta)
|
||||
.then(async (res) => {
|
||||
if (!res) return obtenerProfesor(numeroCuenta);
|
||||
esAlumno = true;
|
||||
return res;
|
||||
})
|
||||
.then(async (res) => {
|
||||
usuario = res;
|
||||
if (!usuario)
|
||||
throw new Error(
|
||||
'Este número de cuenta o de trabajador no existe.'
|
||||
);
|
||||
if (esAlumno) {
|
||||
if (usuario.inscrito != 'SI')
|
||||
throw new Error('Este alumno no esta inscrito este semestre.');
|
||||
await Carrera.findOne({
|
||||
where: { carrera: usuario.carrera },
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) return Carrera.create({ carrera: usuario.carrera });
|
||||
return res;
|
||||
})
|
||||
.then((res) => {
|
||||
usuario.Carrera = res;
|
||||
usuario.nombre = usuario.nombre.trim();
|
||||
usuario.idTipoUsuario = 4;
|
||||
});
|
||||
} else {
|
||||
usuario.idTipoUsuario = 3;
|
||||
usuario.nombre = `${usuario.ApPaterno.trim()} ${usuario.ApMaterno.trim()} ${usuario.Nombre.trim()}`;
|
||||
}
|
||||
return Usuario.create({
|
||||
usuario: numeroCuenta,
|
||||
nombre: usuario.nombre,
|
||||
idCarrera: usuario.Carrera ? usuario.Carrera.idCarrera : null,
|
||||
idTipoUsuario: usuario.idTipoUsuario,
|
||||
return obtenerAlumno(numeroCuenta)
|
||||
.then(async (res) => {
|
||||
if (!res) return obtenerProfesor(numeroCuenta);
|
||||
esAlumno = true;
|
||||
return res;
|
||||
})
|
||||
.then(async (res) => {
|
||||
usuario = res;
|
||||
if (!usuario)
|
||||
throw new Error('Este número de cuenta o de trabajador no existe.');
|
||||
if (esAlumno) {
|
||||
if (usuario.inscrito != 'SI')
|
||||
throw new Error('Este alumno no esta inscrito este semestre.');
|
||||
usuario.nombre = usuario.nombre.trim();
|
||||
usuario.idTipoUsuario = 4;
|
||||
usuario.Carrera = await Carrera.findOne({
|
||||
where: { carrera: usuario.carrera },
|
||||
}).then((res) => {
|
||||
if (!res) return Carrera.create({ carrera: usuario.carrera });
|
||||
return res;
|
||||
});
|
||||
} else {
|
||||
usuario.idTipoUsuario = 3;
|
||||
usuario.nombre = `${usuario.ApPaterno.trim()} ${usuario.ApMaterno.trim()} ${usuario.Nombre.trim()}`;
|
||||
}
|
||||
return Usuario.create({
|
||||
usuario: numeroCuenta,
|
||||
nombre: usuario.nombre,
|
||||
idCarrera: usuario.Carrera ? usuario.Carrera.idCarrera : null,
|
||||
idTipoUsuario: usuario.idTipoUsuario,
|
||||
});
|
||||
})
|
||||
.then((res) =>
|
||||
Usuario.findOne({
|
||||
where: { usuario: numeroCuenta },
|
||||
include: [{ model: Carrera }, { model: TipoUsuario }],
|
||||
attributes: ['idUsuario', 'usuario', 'nombre'],
|
||||
})
|
||||
.then((res) =>
|
||||
Usuario.findOne({
|
||||
where: { usuario: numeroCuenta },
|
||||
include: [{ model: Carrera }, { model: TipoUsuario }],
|
||||
})
|
||||
);
|
||||
} else if (res.password)
|
||||
throw new Error('Este número de cuenta ya fue registrado.');
|
||||
return res;
|
||||
})
|
||||
.then((res) => {
|
||||
delete res.dataValues.password;
|
||||
delete res.dataValues.telefono;
|
||||
delete res.dataValues.telefono;
|
||||
delete res.dataValues.multa;
|
||||
delete res.dataValues.idTipoUsuario;
|
||||
delete res.dataValues.idCarrera;
|
||||
return res;
|
||||
);
|
||||
} else if (res.password)
|
||||
throw new Error('Este número de cuenta ya fue registrado.');
|
||||
return Usuario.findOne({
|
||||
where: { usuario: numeroCuenta },
|
||||
include: [{ model: Carrera }, { model: TipoUsuario }],
|
||||
attributes: ['idUsuario', 'usuario', 'nombre'],
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = escolares;
|
||||
|
||||
@@ -1,41 +1,44 @@
|
||||
const { Op } = require('sequelize');
|
||||
const { crearTokenUsuario } = require('../../middleware/autentificacion');
|
||||
const helperPath = '../../helper';
|
||||
const encriptar = require(`${helperPath}/encriptar`);
|
||||
const { comparar } = require(`${helperPath}/encriptar`);
|
||||
const validar = require(`${helperPath}/validar`);
|
||||
const dbPath = '../../db/tablas';
|
||||
const Carrera = require(`${dbPath}/Carrera`);
|
||||
const Usuario = require(`${dbPath}/Usuario`);
|
||||
const TipoUsuario = require(`${dbPath}/TipoUsuario`);
|
||||
|
||||
const login = async (body) => {
|
||||
const usuario = validar.validarNumeroCuenta(body.usuario, 'El usuario', 60);
|
||||
const usuario = validar.validarNumeroCuenta(body.usuario);
|
||||
const password = validar.validarAlfanumerico(
|
||||
body.password,
|
||||
'La contraseña',
|
||||
'contraseña',
|
||||
false,
|
||||
20
|
||||
);
|
||||
|
||||
return Usuario.findOne({
|
||||
where: { usuario, password: { [Op.ne]: null } },
|
||||
include: [{ model: TipoUsuario }],
|
||||
}).then((res) => {
|
||||
if (!res) throw new Error('No existe este usuario.');
|
||||
if (!res.activo) throw new Error('Este usuario fue desactivado.');
|
||||
if (encriptar.comparar(password, res.password)) {
|
||||
delete res.dataValues.password;
|
||||
delete res.dataValues.idCarrera;
|
||||
delete res.dataValues.idTipoUsuario;
|
||||
delete res.dataValues.telefono;
|
||||
return {
|
||||
Usuario: res,
|
||||
token: crearTokenUsuario({
|
||||
idUsuario: res.idUsuario,
|
||||
idTipoUsuario: res.TipoUsuario.idTipoUsuario,
|
||||
}),
|
||||
};
|
||||
}
|
||||
throw new Error('Usuario o contraseña no válidos.');
|
||||
});
|
||||
attributes: ['idUsuario', 'password', 'activo'],
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe este usuario.');
|
||||
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({
|
||||
where: { usuario },
|
||||
include: [{ model: TipoUsuario }, { model: Carrera }],
|
||||
attributes: ['idUsuario', 'usuario', 'nombre', 'multa', 'activo'],
|
||||
});
|
||||
})
|
||||
.then((res) => ({
|
||||
Usuario: res,
|
||||
token: crearTokenUsuario({
|
||||
idUsuario: res.idUsuario,
|
||||
idTipoUsuario: res.TipoUsuario.idTipoUsuario,
|
||||
}),
|
||||
}));
|
||||
};
|
||||
|
||||
module.exports = login;
|
||||
|
||||
@@ -2,7 +2,11 @@ const validar = require('../../helper/validar');
|
||||
const Usuario = require(`../../db/tablas/Usuario`);
|
||||
|
||||
const quitarMulta = async (body) => {
|
||||
const idUsuario = validar.validarId(body.idUsuario);
|
||||
const idUsuario = validar.validarNumeroEntero(
|
||||
body.idUsuario,
|
||||
'id usuario',
|
||||
true
|
||||
);
|
||||
|
||||
return Usuario.findOne({ where: { idUsuario } })
|
||||
.then((res) => {
|
||||
@@ -10,8 +14,8 @@ const quitarMulta = async (body) => {
|
||||
if (!res.multa) throw new Error('Este usuario no tiene multa.');
|
||||
return Usuario.update({ multa: false }, { where: { idUsuario } });
|
||||
})
|
||||
.then((res) => ({
|
||||
message: 'Se le quito la multa a este usuario.',
|
||||
.then(() => ({
|
||||
message: 'Se le quitó la multa a este usuario.',
|
||||
}));
|
||||
};
|
||||
|
||||
|
||||
@@ -11,12 +11,16 @@ const usuario = async (body) => {
|
||||
return Usuario.findOne({
|
||||
where: { usuario, password: { [Op.ne]: null } },
|
||||
include: [{ model: TipoUsuario }, { model: Carrera }],
|
||||
attributes: [
|
||||
'idUsuario',
|
||||
'usuario',
|
||||
'nombre',
|
||||
'telefono',
|
||||
'multa',
|
||||
'activo',
|
||||
],
|
||||
}).then((res) => {
|
||||
if (!res) throw new Error('No existe este usuario.');
|
||||
delete res.dataValues.password;
|
||||
delete res.dataValues.idTipoUsuario;
|
||||
if (!res.idCarrera) delete res.dataValues.Carrera;
|
||||
delete res.dataValues.idCarrera;
|
||||
return res;
|
||||
});
|
||||
};
|
||||
|
||||
@@ -6,22 +6,26 @@ const TipoUsuario = require(`${dbPath}/TipoUsuario`);
|
||||
const Usuario = require(`${dbPath}/Usuario`);
|
||||
|
||||
const usuarios = async (body) => {
|
||||
const pagina = validar.validarNumero(body.pagina, true);
|
||||
// filtros
|
||||
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)
|
||||
: '';
|
||||
|
||||
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', 'multa', 'activo'],
|
||||
limit: 25,
|
||||
offset: 25 * (pagina - 1),
|
||||
}).then((res) => {
|
||||
for (let i = 0; i < res.rows.length; i++) {
|
||||
delete res.rows[i].dataValues.password;
|
||||
delete res.rows[i].dataValues.idTipoUsuario;
|
||||
delete res.rows[i].dataValues.idCarrera;
|
||||
if (!res.rows[i].Carrera) delete res.rows[i].dataValues.Carrera;
|
||||
}
|
||||
return { count: res.count, usuarios: res.rows };
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
+11
-19
@@ -1,27 +1,19 @@
|
||||
const Carrera = require('./tablas/Carrera');
|
||||
const Usuario = require('./tablas/Usuario');
|
||||
const { encriptar } = require('../helper/encriptar');
|
||||
|
||||
const dataUsuarios = async () => {
|
||||
let usuario = ['316313528', '111111111', '222222222'];
|
||||
let nombre = [
|
||||
'Lemuel Helon Marquez Rosas',
|
||||
'Nombre Falso 1',
|
||||
'Nombre Falso 2',
|
||||
];
|
||||
|
||||
for (let i = 0; i < usuario.length; i++) {
|
||||
await Usuario.create({
|
||||
usuario: usuario[i],
|
||||
nombre: nombre[i],
|
||||
password: encriptar('holi'),
|
||||
telefono: '55-####-####',
|
||||
idTipoUsuario: 4,
|
||||
idCarrera: 1,
|
||||
});
|
||||
}
|
||||
await Carrera.create({ carrera: 'Matemáticas Aplicadas y Computación' }).then(
|
||||
() =>
|
||||
Usuario.create({
|
||||
usuario: '316313528',
|
||||
nombre: 'Marquez Rosas Lemuel Helon',
|
||||
idTipoUsuario: 4,
|
||||
idCarrera: 1,
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
const exec = async() => {
|
||||
const exec = async () => {
|
||||
await dataUsuarios();
|
||||
console.log(
|
||||
'\nSe ha instalado exitosamente la información falsa en la base de datos.\n'
|
||||
|
||||
+48
-18
@@ -6,6 +6,7 @@ const Carrito = require('./tablas/Carrito');
|
||||
const Equipo = require('./tablas/Equipo');
|
||||
const Infraccion = require('./tablas/Infraccion');
|
||||
const Modulo = require('./tablas/Modulo');
|
||||
const Motivo = require('./tablas/Motivo');
|
||||
const Multa = require('./tablas/Multa');
|
||||
const Operador = require('./tablas/Operador');
|
||||
const Prestamo = require('./tablas/Prestamo');
|
||||
@@ -27,6 +28,9 @@ const drop = async () => {
|
||||
await Prestamo.drop();
|
||||
console.log('La tabla Prestamo se desinstalo correctamente.'.magenta);
|
||||
|
||||
await Motivo.drop();
|
||||
console.log('La tabla Motivo se desinstalo correctamente.'.magenta);
|
||||
|
||||
await Equipo.drop();
|
||||
console.log('La tabla Equipo se desinstalo correctamente.'.magenta);
|
||||
|
||||
@@ -91,6 +95,9 @@ const sync = async () => {
|
||||
await Equipo.sync();
|
||||
console.log('La tabla Equipo se instalo correctamente.'.magenta);
|
||||
|
||||
await Motivo.sync();
|
||||
console.log('La tabla Motivo se instalo correctamente.'.magenta);
|
||||
|
||||
await Prestamo.sync();
|
||||
console.log('La tabla Prestamo se instalo correctamente.'.magenta);
|
||||
|
||||
@@ -114,7 +121,7 @@ const dataTipoUsuario = async () => {
|
||||
};
|
||||
|
||||
const dataModulo = async () => {
|
||||
const data = ['Módulo 1', 'Módulo 2'];
|
||||
const data = ['Módulo 1' /*, 'Módulo 2'*/];
|
||||
|
||||
console.log('\nPaso 4) Insertando data modulo.'.bold.blue);
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
@@ -127,9 +134,9 @@ const dataModulo = async () => {
|
||||
|
||||
const dataTipoCarrito = async () => {
|
||||
const data = [
|
||||
{ tipo: 'Chromebook', letra: 'E' },
|
||||
{ tipo: 'Laptop', letra: 'L' },
|
||||
{ tipo: 'iPad', letra: 'T' },
|
||||
{ tipo: 'CHROMEBOOK', letra: 'E' },
|
||||
{ tipo: 'LAP TOP', letra: 'L' },
|
||||
{ tipo: 'IPAD', letra: 'T' },
|
||||
];
|
||||
|
||||
console.log('\nPaso 5) Insertando data tipo carrito.'.bold.blue);
|
||||
@@ -138,12 +145,22 @@ const dataTipoCarrito = async () => {
|
||||
tipoCarrito: data[i].tipo,
|
||||
letra: data[i].letra,
|
||||
});
|
||||
console.log(`Se agrego el tipo carrito ${data[i]}.`.magenta);
|
||||
console.log(`Se agrego el tipo carrito ${data[i].tipo}.`.magenta);
|
||||
}
|
||||
};
|
||||
|
||||
const dataStatus = async () => {
|
||||
const data = ['Activo', 'Cargando', 'Reparación', 'Mantenimiento'];
|
||||
const data = [
|
||||
'Apartado',
|
||||
'En uso',
|
||||
'Entrega inmediata',
|
||||
'Activo',
|
||||
'Cargando',
|
||||
'Reparación',
|
||||
'Mantenimiento',
|
||||
'Desactivado',
|
||||
'Revisar',
|
||||
];
|
||||
|
||||
console.log('\nPaso 6) Insertando data status.'.bold.blue);
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
@@ -155,7 +172,7 @@ const dataStatus = async () => {
|
||||
};
|
||||
|
||||
const dataPrograma = async () => {
|
||||
const data = ['Autodesk', 'Adobe', 'Programación'];
|
||||
const data = ['Autocad, Maya, 3Dmax', 'Programación', 'Autocad', '3Dmax'];
|
||||
|
||||
console.log('\nPaso 7) Insertando data programa.'.bold.blue);
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
@@ -166,8 +183,17 @@ const dataPrograma = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
const dataSystem = async () => {
|
||||
console.log('\nPaso 8) Insertando system.'.bold.blue);
|
||||
await Operador.create({
|
||||
idTipoUsuario: 1,
|
||||
operador: 'Sistema',
|
||||
password: encriptar.encriptar(process.env.SYSTEM_PASSWORD),
|
||||
});
|
||||
};
|
||||
|
||||
const dataAdmin = async () => {
|
||||
console.log('\nPaso 8) Insertando admin.'.bold.blue);
|
||||
console.log('\nPaso 9) Insertando admin.'.bold.blue);
|
||||
await Operador.create({
|
||||
idTipoUsuario: 1,
|
||||
operador: 'Araceli',
|
||||
@@ -196,7 +222,7 @@ const dataInfraccion = async () => {
|
||||
// { infraccion: '', gravedad: '2' },
|
||||
];
|
||||
|
||||
console.log('\nPaso 9) Insertando data infraccion.'.bold.blue);
|
||||
console.log('\nPaso 10) Insertando data infraccion.'.bold.blue);
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
await Infraccion.create({
|
||||
infraccion: data[i].infraccion,
|
||||
@@ -207,15 +233,19 @@ const dataInfraccion = async () => {
|
||||
};
|
||||
|
||||
const exe = async () => {
|
||||
await drop();
|
||||
await sync();
|
||||
await dataTipoUsuario();
|
||||
await dataModulo();
|
||||
await dataTipoCarrito();
|
||||
await dataStatus();
|
||||
await dataPrograma();
|
||||
await dataAdmin();
|
||||
await dataInfraccion();
|
||||
// await drop();
|
||||
// await sync();
|
||||
// await dataTipoUsuario();
|
||||
// await dataModulo();
|
||||
// await dataTipoCarrito();
|
||||
// await dataStatus();
|
||||
// await dataPrograma();
|
||||
// await dataSystem();
|
||||
// await dataAdmin();
|
||||
// await dataInfraccion();
|
||||
|
||||
await Motivo.sync();
|
||||
console.log('La tabla Motivo se instalo correctamente.'.magenta);
|
||||
|
||||
console.log(
|
||||
'\nSe ha instalado exitosamente la base de datos.\n'.underline.bold.green
|
||||
|
||||
@@ -13,7 +13,7 @@ Carrito.init(
|
||||
unique: true,
|
||||
autoIncrement: true,
|
||||
},
|
||||
sobrenombre: {
|
||||
carrito: {
|
||||
type: DataTypes.STRING(4),
|
||||
allowNull: false,
|
||||
},
|
||||
|
||||
@@ -14,6 +14,10 @@ Equipo.init(
|
||||
unique: true,
|
||||
autoIncrement: true,
|
||||
},
|
||||
equipo: {
|
||||
type: DataTypes.STRING(4),
|
||||
allowNull: false,
|
||||
},
|
||||
numeroSerie: {
|
||||
type: DataTypes.STRING(15),
|
||||
allowNull: false,
|
||||
@@ -22,16 +26,7 @@ Equipo.init(
|
||||
type: DataTypes.STRING(15),
|
||||
allowNull: false,
|
||||
},
|
||||
sobrenombre: {
|
||||
type: DataTypes.STRING(4),
|
||||
allowNull: false,
|
||||
},
|
||||
apartado: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
allowNull: false,
|
||||
defaultValue: false,
|
||||
},
|
||||
enUso: {
|
||||
prestado: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
allowNull: false,
|
||||
defaultValue: false,
|
||||
@@ -60,7 +55,7 @@ Equipo.belongsTo(Status, {
|
||||
name: 'idStatus',
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
defaultValue: 1,
|
||||
defaultValue: 4,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
const { DataTypes, Model } = require('sequelize');
|
||||
const sequelize = require('../../config/sequelize.conf');
|
||||
const Equipo = require('./Equipo');
|
||||
const Status = require('./Status');
|
||||
|
||||
class Motivo extends Model {}
|
||||
Motivo.init(
|
||||
{
|
||||
idMotivo: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
allowNull: false,
|
||||
unique: true,
|
||||
autoIncrement: true,
|
||||
},
|
||||
motivo: {
|
||||
type: DataTypes.STRING(500),
|
||||
allowNull: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
modelName: 'Motivo',
|
||||
tableName: 'motivo',
|
||||
timestamps: true,
|
||||
createdAt: true,
|
||||
updatedAt: false,
|
||||
}
|
||||
);
|
||||
|
||||
Motivo.belongsTo(Equipo, {
|
||||
foreignKey: {
|
||||
name: 'idEquipo',
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
});
|
||||
|
||||
Motivo.belongsTo(Status, {
|
||||
foreignKey: {
|
||||
name: 'idStatus',
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
});
|
||||
|
||||
module.exports = Motivo;
|
||||
@@ -22,6 +22,11 @@ Multa.init(
|
||||
type: DataTypes.DATE,
|
||||
allowNull: false,
|
||||
},
|
||||
// activo: {
|
||||
// type: DataTypes.BOOLEAN,
|
||||
// allowNull: false,
|
||||
// defaultValue: true,
|
||||
// },
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
@@ -55,6 +60,7 @@ Multa.belongsTo(Operador, {
|
||||
name: 'idOperadorMulta',
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
defaultValue: 1,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -43,6 +43,16 @@ Prestamo.init(
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
canceladoOperador: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
regresoInmediato: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
@@ -74,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',
|
||||
|
||||
@@ -12,7 +12,7 @@ Programa.init(
|
||||
autoIncrement: true,
|
||||
},
|
||||
programa: {
|
||||
type: DataTypes.STRING(15),
|
||||
type: DataTypes.STRING(20),
|
||||
allowNull: false,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
const correoPcPuma = (password) => ({
|
||||
subject: `Pc Puma credenciales`,
|
||||
msj: `Estimado usuario, su registro se realizó con éxito.
|
||||
<p>
|
||||
Para acceder al servicio debe hacerlo con los siguientes datos:
|
||||
</p>
|
||||
|
||||
<p>
|
||||
• Usuario: Número de cuenta o número de trabajador</br>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
• Contraseña: ${password}
|
||||
</p>
|
||||
|
||||
<p style=" text-align: justify; text-justify: inter-word;">
|
||||
El presente registro le permite hacer uso del préstamo del equipo de cómputo seleccionado, el cual puede ser utilizado únicamente al interior de la FES Acatlán.
|
||||
Para acceder al servicio es obligatorio y su responsabilidad leer los lineamientos "pcpuma-solicita" en la siguiente liga: <u>https://www.acatlan.unam.mx/pcpuma/Lineamientos.html</u>
|
||||
Hacemos de su conocimiento que la presente información es confidencial y debe ser tratada como tal, es de uso exclusivo para el usuario al que fue asignada y se encuentra protegida por la normatividad de la Universidad Nacional Autónoma de México en la materia, cualquier uso no autorizado o indebido se hará del conocimiento de la autoridad universitaria.
|
||||
Puede consultar nuestro aviso de privacidad en: <u>https://www.acatlan.unam.mx/normatividad</u>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Para mayor información o duda contáctenos por este medio.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Atte.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
PCPUMA Solicita
|
||||
</p>
|
||||
`,
|
||||
});
|
||||
|
||||
module.exports = correoPcPuma;
|
||||
@@ -1,27 +1,17 @@
|
||||
const bcrypt = require('bcrypt');
|
||||
const validar = require('./validar');
|
||||
require('../config/config');
|
||||
|
||||
const comparar = (password, dbPassword) => {
|
||||
let campo = 'password';
|
||||
|
||||
validar.noHay(password, campo);
|
||||
if (typeof password != 'string') validar.noValido(campo);
|
||||
if (!bcrypt.compareSync(password, dbPassword)) return false;
|
||||
return true;
|
||||
};
|
||||
|
||||
const encriptar = (password) => {
|
||||
let campo = 'password';
|
||||
|
||||
validar.noHay(password, campo);
|
||||
if (typeof password != 'string') validar.noValido(campo);
|
||||
return bcrypt.hashSync(password, Number(process.env.SALT_ROUNDS));
|
||||
};
|
||||
const encriptar = (password) =>
|
||||
bcrypt.hashSync(password, Number(process.env.SALT_ROUNDS));
|
||||
|
||||
const generarPassword = () => {
|
||||
let length = 8;
|
||||
let charset =
|
||||
const length = 8;
|
||||
const charset =
|
||||
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
||||
let password = '';
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
const Equipo = require('../db/tablas/Equipo');
|
||||
|
||||
Equipo.update({ prestado: false }, { where: { prestado: true } });
|
||||
@@ -5,9 +5,9 @@ const send = require('gmail-send')({
|
||||
pass: process.env.GMAILPASSWORD,
|
||||
});
|
||||
|
||||
const gmail = (subject, to, text) => {
|
||||
const gmail = (subject, to, html) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
send({ subject, to, text }, (error, result, fullResult) => {
|
||||
send({ subject, to, html }, (error, result, fullResult) => {
|
||||
if (error) reject(error);
|
||||
resolve(result);
|
||||
});
|
||||
|
||||
+2
-15
@@ -1,22 +1,10 @@
|
||||
const fs = require('fs');
|
||||
const moment = require('moment');
|
||||
|
||||
const crearDDMMAAAA = (date) => {
|
||||
const fechaMoment = moment(date);
|
||||
let ddmmaaaa = '';
|
||||
|
||||
if (fechaMoment.isValid())
|
||||
ddmmaaaa = `${fechaMoment.date()}/${
|
||||
fechaMoment.month() + 1
|
||||
}/${fechaMoment.year()}`;
|
||||
return ddmmaaaa;
|
||||
};
|
||||
|
||||
const eliminarArchivo = (path) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
fs.unlink(path, (err) => {
|
||||
if (err) reject(err);
|
||||
resolve({ message: 'Se elimino el archivo correctamente.' });
|
||||
resolve({ message: 'Se eliminó el archivo correctamente.' });
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -25,13 +13,12 @@ const crearArchivo = (path, texto) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
fs.appendFile(path, texto, (err) => {
|
||||
if (err) reject(err);
|
||||
resolve({ message: 'Se creo el archivo correctamente.' });
|
||||
resolve({ message: 'Se creó el archivo correctamente.' });
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
crearDDMMAAAA,
|
||||
eliminarArchivo,
|
||||
crearArchivo,
|
||||
};
|
||||
|
||||
+131
-94
@@ -1,58 +1,26 @@
|
||||
const moment = require('moment');
|
||||
const validator = require('validator');
|
||||
|
||||
const noValido = (campo) => {
|
||||
throw new Error(`${campo} no es valido.`);
|
||||
};
|
||||
|
||||
const noHay = (variable, campo) => {
|
||||
if (!variable) throw new Error(`Falta ${campo}.`);
|
||||
};
|
||||
|
||||
const yaExiste = (campo) => {
|
||||
throw new Error(`${campo} ya se encuentra en uso.`);
|
||||
};
|
||||
|
||||
const validar = (texto, campo, length) => {
|
||||
noHay(texto, campo);
|
||||
if (typeof texto !== 'string' || (length && texto.length > length))
|
||||
noValido(campo);
|
||||
return texto;
|
||||
};
|
||||
|
||||
const validarId = (id) => {
|
||||
let campo = 'El id';
|
||||
|
||||
noHay(id, campo);
|
||||
if (typeof id === 'number') id = id.toString();
|
||||
if (typeof id !== 'string' || !validator.isNumeric(id, { no_symbols: true }))
|
||||
noValido(campo);
|
||||
return Number(id);
|
||||
};
|
||||
|
||||
const validarCorreo = (correo) => {
|
||||
let campo = 'El correo';
|
||||
|
||||
noHay(correo, campo);
|
||||
if (typeof correo !== 'string' || !validator.isEmail(correo)) noValido(campo);
|
||||
return correo;
|
||||
};
|
||||
|
||||
const caracteresEspeciales = (char) => {
|
||||
// Caractéres especiales permitidos en una string
|
||||
const caracterEspecial = (char) => {
|
||||
const charset = [
|
||||
' ',
|
||||
'.',
|
||||
'-',
|
||||
',',
|
||||
'/',
|
||||
'#',
|
||||
'?',
|
||||
'¿',
|
||||
':',
|
||||
';',
|
||||
'?',
|
||||
'¿',
|
||||
'!',
|
||||
'¡',
|
||||
'(',
|
||||
')',
|
||||
'"',
|
||||
"'",
|
||||
'-',
|
||||
'_',
|
||||
'/',
|
||||
'#',
|
||||
'%',
|
||||
'\n',
|
||||
];
|
||||
@@ -61,87 +29,156 @@ const caracteresEspeciales = (char) => {
|
||||
return false;
|
||||
};
|
||||
|
||||
const validarTexto = (texto, campo, length) => {
|
||||
noHay(texto, campo);
|
||||
if (typeof texto !== 'string' || texto.length > length) noValido(campo);
|
||||
const yaExiste = (campo, m) => {
|
||||
throw new Error(`Ya se encuentra en uso ${m ? 'el' : 'la'} ${campo}.`);
|
||||
};
|
||||
|
||||
const noValido = (campo, m, razon) => {
|
||||
throw new Error(
|
||||
`${m ? 'El' : 'La'} ${campo} no es valid${m ? 'o' : 'a'}, ${razon}.`
|
||||
);
|
||||
};
|
||||
|
||||
/*
|
||||
Valida que la variable contenga un valor, de lo contrario saca un error.
|
||||
*/
|
||||
const noHay = (variable, campo, m) => {
|
||||
if (!variable) throw new Error(`No se mando ${m ? 'el' : 'la'} ${campo}.`);
|
||||
};
|
||||
|
||||
/*
|
||||
Valida que la variable sea una string y, si se necesita, que mida igual
|
||||
o menor que una longitud determinada.
|
||||
*/
|
||||
const validacionBasicaStr = (texto, campo, m, length) => {
|
||||
noHay(texto, campo, m);
|
||||
if (typeof texto !== 'string') noValido(campo, m, 'no se mando una string');
|
||||
if (length && texto.length > length)
|
||||
noValido(campo, m, 'tiene más carecteres de lo permitido');
|
||||
return texto;
|
||||
};
|
||||
|
||||
/*
|
||||
Valida que la variable sea un numero entero, ya sea que recibe una string o
|
||||
un number. Usualmente se usa para validar ids.
|
||||
*/
|
||||
const validarNumeroEntero = (numero, campo, m = true) => {
|
||||
noHay(numero, campo, m);
|
||||
if (typeof numero === 'number') numero = numero.toString();
|
||||
if (typeof numero !== 'string')
|
||||
noValido(campo, m, 'no se mando una string o un number');
|
||||
if (!validator.isNumeric(numero, { no_symbols: true }))
|
||||
noValido(campo, m, 'no es un número entero valido');
|
||||
return Number(numero);
|
||||
};
|
||||
|
||||
/*
|
||||
Valida que la stirng mandada sea un correo valido.
|
||||
*/
|
||||
const validarCorreo = (correo, campo = 'correo', m = true, length) => {
|
||||
validacionBasicaStr(correo, campo, m, length);
|
||||
if (!validator.isEmail(correo)) noValido(campo, m, 'no es un correo válido');
|
||||
return correo;
|
||||
};
|
||||
|
||||
/*
|
||||
Valida que la stirng mandada sean caracteres del abcdario.
|
||||
Usualmente se usa para validar nombres, apellidos, etc.
|
||||
*/
|
||||
const validarTexto = (texto, campo, m, length) => {
|
||||
validacionBasicaStr(texto, campo, m, length);
|
||||
for (let i = 0; i < texto.length; i++)
|
||||
if (
|
||||
!validator.isAlpha(texto[i], 'es-ES') &&
|
||||
texto[i] != ' ' &&
|
||||
texto[i] != '.'
|
||||
)
|
||||
noValido(campo, m, 'contiene caracteres no validos');
|
||||
return texto;
|
||||
};
|
||||
|
||||
/*
|
||||
Lo mismo que el de arriba pero este permite números y
|
||||
caracteres especiales.
|
||||
*/
|
||||
const validarAlfanumerico = (texto, campo, m, length) => {
|
||||
validacionBasicaStr(texto, campo, m, length);
|
||||
for (let i = 0; i < texto.length; i++) {
|
||||
if (caracteresEspeciales(texto[i])) continue;
|
||||
if (!validator.isAlpha(texto[i], 'es-ES')) noValido(campo);
|
||||
if (caracterEspecial(texto[i])) continue;
|
||||
if (!validator.isAlphanumeric(texto[i], 'es-ES'))
|
||||
noValido(campo, m, 'contiene caracteres no validos');
|
||||
}
|
||||
return texto;
|
||||
};
|
||||
|
||||
const validarAlfanumerico = (texto, campo, length) => {
|
||||
noHay(texto, campo);
|
||||
if (typeof texto !== 'string' || texto.length > length) noValido(campo);
|
||||
for (let i = 0; i < texto.length; i++) {
|
||||
if (caracteresEspeciales(texto[i])) continue;
|
||||
if (!validator.isAlphanumeric(texto[i], 'es-ES')) noValido(campo);
|
||||
}
|
||||
return texto;
|
||||
};
|
||||
|
||||
const validarNumeroCuenta = (numeroCuenta) => {
|
||||
let campo = 'El numero de cuenta';
|
||||
|
||||
noHay(numeroCuenta, campo);
|
||||
if (
|
||||
typeof numeroCuenta !== 'string' ||
|
||||
!validator.isNumeric(numeroCuenta, { no_symbols: true }) ||
|
||||
numeroCuenta.length > 9
|
||||
)
|
||||
noValido(campo);
|
||||
/*
|
||||
Valida que la string sea un número menor a 9 dígitos.
|
||||
*/
|
||||
const validarNumeroCuenta = (
|
||||
numeroCuenta,
|
||||
campo = 'numero de cuenta',
|
||||
m = true
|
||||
) => {
|
||||
validacionBasicaStr(numeroCuenta, campo, m, 9);
|
||||
if (!validator.isNumeric(numeroCuenta, { no_symbols: true }))
|
||||
noValido(campo, m, 'tiene caracteres que nos son números');
|
||||
return numeroCuenta;
|
||||
};
|
||||
|
||||
const validarFecha = (fecha) => {
|
||||
let campo = 'La fecha';
|
||||
/*
|
||||
Valida que la variable sea una fecha moment valida.
|
||||
*/
|
||||
const validarFecha = (fecha, campo, m) => {
|
||||
let fechaMoment = moment(fecha);
|
||||
|
||||
noHay(fecha, campo);
|
||||
if (!fechaMoment.isValid()) noValido(campo);
|
||||
noHay(fecha, campo, m);
|
||||
if (!fechaMoment.isValid()) noValido(campo, m, 'no es una fecha válida');
|
||||
return fechaMoment;
|
||||
};
|
||||
|
||||
const validarNumero = (numero, makeNumber = false, length) => {
|
||||
let campo = 'El numero';
|
||||
|
||||
noHay(numero, campo);
|
||||
if (
|
||||
typeof numero !== 'string' ||
|
||||
!validator.isNumeric(numero, { no_symbols: true }) ||
|
||||
(length && numero.length > length)
|
||||
)
|
||||
noValido(campo);
|
||||
/*
|
||||
Valida que una string contenga solo números
|
||||
*/
|
||||
const validarNumero = (
|
||||
numero,
|
||||
campo,
|
||||
m,
|
||||
length,
|
||||
no_symbols = true,
|
||||
makeNumber = false
|
||||
) => {
|
||||
validacionBasicaStr(numero, campo, m, length);
|
||||
if (!validator.isNumeric(numero, { no_symbols }))
|
||||
noValido(campo, m, 'tiene caracteres que no son números');
|
||||
if (makeNumber) return Number(numero);
|
||||
return numero;
|
||||
};
|
||||
|
||||
const validarAccesibilidad = (usuariosValidos = [], idTipoUsuario) => {
|
||||
for (let i = 0; i < usuariosValidos.length; i++)
|
||||
if (idTipoUsuario === usuariosValidos[i]) return;
|
||||
throw new Error('Este usuario no tiene permitido usar esta linea de la API.');
|
||||
};
|
||||
// const validarAccesibilidad = (usuariosValidos = [], idTipoUsuario) => {
|
||||
// for (let i = 0; i < usuariosValidos.length; i++)
|
||||
// if (idTipoUsuario === usuariosValidos[i]) return;
|
||||
// throw new Error('Este usuario no tiene permitido usar esta linea de la API.');
|
||||
// };
|
||||
|
||||
/*
|
||||
Te dice si un objeto esta vacio o no.
|
||||
*/
|
||||
const validarObjetoVacio = (obj) => {
|
||||
for (let key in obj) {
|
||||
if (obj.hasOwnProperty(key)) return false;
|
||||
}
|
||||
for (let key in obj) if (obj.hasOwnProperty(key)) return false;
|
||||
return true;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
validar,
|
||||
noValido,
|
||||
yaExiste,
|
||||
noValido,
|
||||
noHay,
|
||||
validacionBasicaStr,
|
||||
validarNumeroEntero,
|
||||
validarCorreo,
|
||||
validarId,
|
||||
validarTexto,
|
||||
validarAlfanumerico,
|
||||
validarNumeroCuenta,
|
||||
validarFecha,
|
||||
validarNumero,
|
||||
validarAccesibilidad,
|
||||
validarObjetoVacio,
|
||||
};
|
||||
|
||||
@@ -13,7 +13,7 @@ const verificaToken = (req, res, next) => {
|
||||
let message = '';
|
||||
|
||||
if (err.message === 'invalid signature')
|
||||
message = 'El token no es valido. Inicia sesión de nuevo.';
|
||||
message = 'Se termino el tiempo de tu sesión. Inicia sesión de nuevo.';
|
||||
if (err.message === 'jwt expired')
|
||||
message = 'El token expiro. Inicia sesión de nuevo.';
|
||||
if (err.message === 'jwt malformed')
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
const express = require('express');
|
||||
const app = express();
|
||||
const { verificaToken } = require('../middleware/autentificacion');
|
||||
const route = '/carrera';
|
||||
const get = require('../controller/Carrera/get');
|
||||
|
||||
app.get(`${route}`, verificaToken, (req, res) => {
|
||||
return get()
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = app;
|
||||
@@ -9,7 +9,7 @@ const equiposCarrito = require(`${controllerPath}/equiposCarrito`);
|
||||
const update = require(`${controllerPath}/update`);
|
||||
|
||||
// PUT
|
||||
app.put(`${route}/update`, (req, res) => {
|
||||
app.put(`${route}/update`, verificaToken, (req, res) => {
|
||||
return update(req.body)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
@@ -20,7 +20,7 @@ app.put(`${route}/update`, (req, res) => {
|
||||
});
|
||||
|
||||
//GET
|
||||
app.get(`${route}/`, (req, res) => {
|
||||
app.get(`${route}/`, verificaToken, (req, res) => {
|
||||
return carrito(req.query)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
@@ -30,7 +30,7 @@ app.get(`${route}/`, (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
app.get(`${route}/carritos`, (req, res) => {
|
||||
app.get(`${route}/carritos`, verificaToken, (req, res) => {
|
||||
return carritos(req.query)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
@@ -40,7 +40,7 @@ app.get(`${route}/carritos`, (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
app.get(`${route}/equipos_carrito`, (req, res) => {
|
||||
app.get(`${route}/equipos_carrito`, verificaToken, (req, res) => {
|
||||
return equiposCarrito(req.query)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
|
||||
@@ -13,7 +13,7 @@ const update = require(`${controllerPath}/update`);
|
||||
// POST
|
||||
app.post(
|
||||
`${route}/carga_masiva`,
|
||||
// verificaToken,
|
||||
verificaToken,
|
||||
upload.single('csv'),
|
||||
(req, res) => {
|
||||
if (req.file) {
|
||||
@@ -32,7 +32,7 @@ app.post(
|
||||
);
|
||||
|
||||
// PUT
|
||||
app.put(`${route}/update`, (req, res) => {
|
||||
app.put(`${route}/update`, verificaToken, (req, res) => {
|
||||
return update(req.body)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
@@ -43,7 +43,7 @@ app.put(`${route}/update`, (req, res) => {
|
||||
});
|
||||
|
||||
//GET
|
||||
app.get(`${route}/`, (req, res) => {
|
||||
app.get(`${route}/`, verificaToken, (req, res) => {
|
||||
return equipo(req.query)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
@@ -53,7 +53,7 @@ app.get(`${route}/`, (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
app.get(`${route}/equipos`, (req, res) => {
|
||||
app.get(`${route}/equipos`, verificaToken, (req, res) => {
|
||||
return equipos(req.query)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
|
||||
@@ -4,18 +4,14 @@ const { verificaToken } = require('../middleware/autentificacion');
|
||||
const route = '/infraccion';
|
||||
const get = require('../controller/Infraccion/get');
|
||||
|
||||
app.get(
|
||||
`${route}`,
|
||||
//verificaToken,
|
||||
(req, res) => {
|
||||
return get()
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
}
|
||||
);
|
||||
app.get(`${route}`, verificaToken, (req, res) => {
|
||||
return get()
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = app;
|
||||
|
||||
+9
-14
@@ -1,21 +1,16 @@
|
||||
const express = require('express');
|
||||
const app = express();
|
||||
const { verificaToken } = require('../middleware/autentificacion');
|
||||
const route = '/modulo';
|
||||
const get = require('../controller/Modulo/get');
|
||||
|
||||
app.get(
|
||||
`${route}`,
|
||||
// verificaToken,
|
||||
(req, res) => {
|
||||
return get()
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
}
|
||||
);
|
||||
app.get(`${route}`, (req, res) => {
|
||||
return get()
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = app;
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
const express = require('express');
|
||||
const app = express();
|
||||
const { verificaToken } = require('../middleware/autentificacion');
|
||||
const route = '/motivo';
|
||||
const historialMotivosEquipo = require('../controller/Motivo/historialMotivosEquipo');
|
||||
|
||||
app.get(`${route}/historial_motivos_equipo`, verificaToken, (req, res) => {
|
||||
return historialMotivosEquipo(req.query)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = app;
|
||||
+47
-52
@@ -5,62 +5,57 @@ const route = '/multa';
|
||||
const historialMultasEquipo = require('../controller/Multa/historialMultasEquipo');
|
||||
const historialMultasUsuario = require('../controller/Multa/historialMultasUsuario');
|
||||
const multar = require('../controller/Multa/multar');
|
||||
const multarIdPrestamo = require('../controller/Multa/multarIdPrestamo');
|
||||
const multarNumeroInventario = require('../controller/Multa/multarNumeroInventario');
|
||||
|
||||
app.post(
|
||||
`${route}/multar`,
|
||||
//verificaToken,
|
||||
(req, res) => {
|
||||
return multar(req.body)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
}
|
||||
);
|
||||
app.post(`${route}/multar`, verificaToken, (req, res) => {
|
||||
return multar(req.body)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
app.post(
|
||||
`${route}/multar_numero_inventario`,
|
||||
//verificaToken,
|
||||
(req, res) => {
|
||||
return multarNumeroInventario(req.body)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
}
|
||||
);
|
||||
app.post(`${route}/multar_id_prestamo`, verificaToken, (req, res) => {
|
||||
return multarIdPrestamo(req.body)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
app.get(
|
||||
`${route}/historial_multas_usuario`,
|
||||
//verificaToken,
|
||||
(req, res) => {
|
||||
return historialMultasUsuario(req.query)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
}
|
||||
);
|
||||
app.post(`${route}/multar_numero_inventario`, verificaToken, (req, res) => {
|
||||
return multarNumeroInventario(req.body)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
app.get(
|
||||
`${route}/historial_multas_equipo`,
|
||||
//verificaToken,
|
||||
(req, res) => {
|
||||
return historialMultasEquipo(req.query)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
}
|
||||
);
|
||||
app.get(`${route}/historial_multas_usuario`, verificaToken, (req, res) => {
|
||||
return historialMultasUsuario(req.query)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
app.get(`${route}/historial_multas_equipo`, verificaToken, (req, res) => {
|
||||
return historialMultasEquipo(req.query)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = app;
|
||||
|
||||
@@ -19,7 +19,7 @@ app.post(`${route}/login`, (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
app.post(`${route}/crear`, (req, res) => {
|
||||
app.post(`${route}/crear`, verificaToken, (req, res) => {
|
||||
return crear(req.body)
|
||||
.then((data) => {
|
||||
res.status(201).json(data);
|
||||
@@ -30,7 +30,7 @@ app.post(`${route}/crear`, (req, res) => {
|
||||
});
|
||||
|
||||
// PUT
|
||||
app.put(`${route}/update`, (req, res) => {
|
||||
app.put(`${route}/update`, verificaToken, (req, res) => {
|
||||
return update(req.body)
|
||||
.then((data) => {
|
||||
res.status(201).json(data);
|
||||
@@ -41,7 +41,7 @@ app.put(`${route}/update`, (req, res) => {
|
||||
});
|
||||
|
||||
// GET
|
||||
app.get(`${route}/operadores`, (req, res) => {
|
||||
app.get(`${route}/operadores`, verificaToken, (req, res) => {
|
||||
return operadores(req.query)
|
||||
.then((data) => {
|
||||
res.status(201).json(data);
|
||||
|
||||
+170
-159
@@ -6,6 +6,7 @@ const controllerPath = '../controller/Prestamo';
|
||||
const activos = require(`${controllerPath}/activos`);
|
||||
const cancelarOperador = require(`${controllerPath}/cancelarOperador`);
|
||||
const cancelarUsuario = require(`${controllerPath}/cancelarUsuario`);
|
||||
const diezMinutos = require(`${controllerPath}/diezMinutos`);
|
||||
const historial = require(`${controllerPath}/historial`);
|
||||
const historialEquipo = require(`${controllerPath}/historialEquipo`);
|
||||
const historialUsuario = require(`${controllerPath}/historialUsuario`);
|
||||
@@ -13,29 +14,71 @@ const pedir = require(`${controllerPath}/pedir`);
|
||||
const entregar = require(`${controllerPath}/entregar`);
|
||||
const regresar = require(`${controllerPath}/regresar`);
|
||||
const regresarNumeroInventario = require(`${controllerPath}/regresarNumeroInventario`);
|
||||
const regresoInmediato = require(`${controllerPath}/regresoInmediato`);
|
||||
const regresoInmediatoNumeroInventario = require(`${controllerPath}/regresoInmediatoNumeroInventario`);
|
||||
const prestamo = require(`${controllerPath}/prestamo`);
|
||||
const prestamoNumeroInventario = require(`${controllerPath}/prestamoNumeroInventario`);
|
||||
const prestamoUsuario = require(`${controllerPath}/prestamoUsuario`);
|
||||
const reporte = require(`${controllerPath}/reporte`);
|
||||
const status = require(`${controllerPath}/status`);
|
||||
|
||||
app.post(
|
||||
`${route}/pedir`,
|
||||
// verificaToken,
|
||||
(req, res) => {
|
||||
return pedir(req.body)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
}
|
||||
);
|
||||
// POST
|
||||
app.post(`${route}/pedir`, verificaToken, (req, res) => {
|
||||
return pedir(req.body)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
// PUT
|
||||
app.put(`${route}/entregar`, verificaToken, (req, res) => {
|
||||
return entregar(req.body)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
app.put(`${route}/regresar`, verificaToken, (req, res) => {
|
||||
return regresar(req.body)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
app.put(`${route}/regresar_numero_inventario`, verificaToken, (req, res) => {
|
||||
return regresarNumeroInventario(req.body)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
app.put(`${route}/regreso_inmediato`, verificaToken, (req, res) => {
|
||||
return regresoInmediato(req.body)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
app.put(
|
||||
`${route}/entregar`,
|
||||
// verificaToken,
|
||||
`${route}/regreso_inmediato_numero_inventario`,
|
||||
verificaToken,
|
||||
(req, res) => {
|
||||
return entregar(req.body)
|
||||
return regresoInmediatoNumeroInventario(req.body)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
@@ -45,158 +88,126 @@ app.put(
|
||||
}
|
||||
);
|
||||
|
||||
app.put(
|
||||
`${route}/regresar`,
|
||||
// verificaToken,
|
||||
(req, res) => {
|
||||
return regresar(req.body)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
}
|
||||
);
|
||||
app.put(`${route}/cancelar_usuario`, verificaToken, (req, res) => {
|
||||
req.body.idUsuario = req.decoded.data.idUsuario;
|
||||
return cancelarUsuario(req.body)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
app.put(
|
||||
`${route}/regresar_numero_inventario`,
|
||||
// verificaToken,
|
||||
(req, res) => {
|
||||
return regresarNumeroInventario(req.body)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
}
|
||||
);
|
||||
app.put(`${route}/cancelar_operador`, verificaToken, (req, res) => {
|
||||
return cancelarOperador(req.body)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
app.put(
|
||||
`${route}/cancelar_usuario`,
|
||||
// verificaToken,
|
||||
(req, res) => {
|
||||
return cancelarUsuario(req.body)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
}
|
||||
);
|
||||
// GET
|
||||
app.get(`${route}/activos`, verificaToken, (req, res) => {
|
||||
return activos(req.query)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
app.put(
|
||||
`${route}/cancelar_operador`,
|
||||
// verificaToken,
|
||||
(req, res) => {
|
||||
return cancelarOperador(req.body)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
}
|
||||
);
|
||||
app.get(`${route}/diez_minutos`, verificaToken, (req, res) => {
|
||||
return diezMinutos(req.query)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
app.get(
|
||||
`${route}/activos`,
|
||||
// verificaToken,
|
||||
(req, res) => {
|
||||
return activos(req.query)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
}
|
||||
);
|
||||
app.get(`${route}/historial`, verificaToken, (req, res) => {
|
||||
return historial(req.query)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
app.get(
|
||||
`${route}/historial`,
|
||||
// verificaToken,
|
||||
(req, res) => {
|
||||
return historial(req.query)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
}
|
||||
);
|
||||
app.get(`${route}/historial_equipo`, verificaToken, (req, res) => {
|
||||
return historialEquipo(req.query)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
app.get(
|
||||
`${route}/historial_equipo`,
|
||||
// verificaToken,
|
||||
(req, res) => {
|
||||
return historialEquipo(req.query)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
}
|
||||
);
|
||||
app.get(`${route}/historial_usuario`, verificaToken, (req, res) => {
|
||||
return historialUsuario(req.query)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
app.get(
|
||||
`${route}/historial_usuario`,
|
||||
// verificaToken,
|
||||
(req, res) => {
|
||||
return historialUsuario(req.query)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
}
|
||||
);
|
||||
app.get(`${route}`, verificaToken, (req, res) => {
|
||||
return prestamo(req.query)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
app.get(
|
||||
`${route}`,
|
||||
// verificaToken,
|
||||
(req, res) => {
|
||||
return prestamo(req.query)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
}
|
||||
);
|
||||
app.get(`${route}/prestamo_numero_inventario`, verificaToken, (req, res) => {
|
||||
return prestamoNumeroInventario(req.query)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
app.get(
|
||||
`${route}/prestamo_usuario`,
|
||||
// verificaToken,
|
||||
(req, res) => {
|
||||
return prestamoUsuario(req.query)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
}
|
||||
);
|
||||
app.get(`${route}/prestamo_usuario`, verificaToken, (req, res) => {
|
||||
return prestamoUsuario(req.query)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
app.get(
|
||||
`${route}/status`,
|
||||
// verificaToken,
|
||||
(req, res) => {
|
||||
return status(req.query)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
}
|
||||
);
|
||||
app.get(`${route}/reporte`, verificaToken, (req, res) => {
|
||||
return reporte(req.query)
|
||||
.then((data) => {
|
||||
res.download(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
app.get(`${route}/status`, verificaToken, (req, res) => {
|
||||
return status(req.query)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = app;
|
||||
|
||||
@@ -4,18 +4,14 @@ const { verificaToken } = require('../middleware/autentificacion');
|
||||
const route = '/programa';
|
||||
const get = require('../controller/Programa/get');
|
||||
|
||||
app.get(
|
||||
`${route}`,
|
||||
//verificaToken,
|
||||
(req, res) => {
|
||||
return get()
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
}
|
||||
);
|
||||
app.get(`${route}`, verificaToken, (req, res) => {
|
||||
return get()
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = app;
|
||||
|
||||
+9
-13
@@ -4,18 +4,14 @@ const { verificaToken } = require('../middleware/autentificacion');
|
||||
const route = '/status';
|
||||
const get = require('../controller/Status/get');
|
||||
|
||||
app.get(
|
||||
`${route}`,
|
||||
//verificaToken,
|
||||
(req, res) => {
|
||||
return get()
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
}
|
||||
);
|
||||
app.get(`${route}`, verificaToken, (req, res) => {
|
||||
return get()
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = app;
|
||||
|
||||
@@ -4,18 +4,14 @@ const { verificaToken } = require('../middleware/autentificacion');
|
||||
const route = '/tipo_carrito';
|
||||
const get = require('../controller/TipoCarrito/get');
|
||||
|
||||
app.get(
|
||||
`${route}`,
|
||||
//verificaToken,
|
||||
(req, res) => {
|
||||
return get()
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
}
|
||||
);
|
||||
app.get(`${route}`, verificaToken, (req, res) => {
|
||||
return get()
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = app;
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
const express = require('express');
|
||||
const app = express();
|
||||
const { verificaToken } = require('../middleware/autentificacion');
|
||||
const route = '/tipo_usuario';
|
||||
const get = require('../controller/TipoUsuario/get');
|
||||
|
||||
app.get(`${route}`, verificaToken, (req, res) => {
|
||||
return get()
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = app;
|
||||
@@ -5,7 +5,7 @@ const upload = multer({ dest: 'server/uploads' });
|
||||
const { verificaToken } = require('../middleware/autentificacion');
|
||||
const route = '/usuario';
|
||||
const controllerPath = '../controller/Usuario';
|
||||
const cargaMasivaPosgrados = require(`${controllerPath}/cargaMasivaPosgrados`);
|
||||
const cargaMasiva = require(`${controllerPath}/cargaMasiva`);
|
||||
const crear = require(`${controllerPath}/crear`);
|
||||
const escolares = require(`${controllerPath}/escolares`);
|
||||
const login = require(`${controllerPath}/login`);
|
||||
@@ -15,11 +15,11 @@ const usuarios = require(`${controllerPath}/usuarios`);
|
||||
|
||||
app.post(
|
||||
`${route}/carga_masiva_posgrado`,
|
||||
// verificaToken,
|
||||
verificaToken,
|
||||
upload.single('csv'),
|
||||
(req, res) => {
|
||||
if (req.file) {
|
||||
return cargaMasivaPosgrados(req.file.filename)
|
||||
return cargaMasiva(req.file.filename)
|
||||
.then((data) => {
|
||||
res.status(201).json(data);
|
||||
})
|
||||
@@ -53,7 +53,7 @@ app.post(`${route}/login`, (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
app.put(`${route}/quitar_multa`, (req, res) => {
|
||||
app.put(`${route}/quitar_multa`, verificaToken, (req, res) => {
|
||||
return quitarMulta(req.body)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
@@ -73,7 +73,7 @@ app.get(`${route}/escolares`, (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
app.get(`${route}`, (req, res) => {
|
||||
app.get(`${route}`, verificaToken, (req, res) => {
|
||||
return usuario(req.query)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
@@ -83,7 +83,7 @@ app.get(`${route}`, (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
app.get(`${route}/usuarios`, (req, res) => {
|
||||
app.get(`${route}/usuarios`, verificaToken, (req, res) => {
|
||||
return usuarios(req.query)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
const express = require('express');
|
||||
const app = express();
|
||||
|
||||
app.use(require('./Carrera'));
|
||||
app.use(require('./Carrito'));
|
||||
app.use(require('./Equipo'));
|
||||
app.use(require('./Infraccion'));
|
||||
app.use(require('./Modulo'));
|
||||
app.use(require('./Motivo'));
|
||||
app.use(require('./Multa'));
|
||||
app.use(require('./Operador'));
|
||||
app.use(require('./Prestamo'));
|
||||
app.use(require('./Programa'));
|
||||
app.use(require('./Status'));
|
||||
app.use(require('./TipoCarrito'));
|
||||
app.use(require('./TipoUsuario'));
|
||||
app.use(require('./Usuario'));
|
||||
|
||||
module.exports = app;
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
const { Server } = require('socket.io');
|
||||
let io;
|
||||
|
||||
module.exports = {
|
||||
init(httpServer) {
|
||||
io = new Server(httpServer, {
|
||||
cors: {
|
||||
origin: [
|
||||
// 'http://localhost:3046',
|
||||
// 'http://localhost:3056',
|
||||
// 'http://132.248.80.196:3045',
|
||||
// 'http://132.248.80.196:3055',
|
||||
'https://pcpuma.acatlan.unam.mx',
|
||||
'https://pcpuma.acatlan.unam.mx:8080',
|
||||
],
|
||||
},
|
||||
});
|
||||
return io;
|
||||
},
|
||||
getIO() {
|
||||
if (!io) throw new Error('Socket.io no se ha inicializado.');
|
||||
return io;
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user