Compare commits
113 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8624198286 | |||
| 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
|
.env
|
||||||
|
|
||||||
|
server/uploads/*
|
||||||
Generated
+1152
-963
File diff suppressed because it is too large
Load Diff
+2
-1
@@ -12,7 +12,7 @@
|
|||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": ""
|
"url": "https://repositorio.acatlan.unam.mx/CIDWA/pcpuma_acatlan_api.git"
|
||||||
},
|
},
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
@@ -31,6 +31,7 @@
|
|||||||
"moment": "^2.29.1",
|
"moment": "^2.29.1",
|
||||||
"multer": "^1.4.2",
|
"multer": "^1.4.2",
|
||||||
"sequelize": "^6.6.2",
|
"sequelize": "^6.6.2",
|
||||||
|
"socket.io": "^4.4.1",
|
||||||
"validator": "^13.6.0"
|
"validator": "^13.6.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
+5
-4
@@ -4,6 +4,9 @@ const bodyParser = require('body-parser');
|
|||||||
const cors = require('cors');
|
const cors = require('cors');
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
const app = express();
|
const app = express();
|
||||||
|
const { createServer } = require('http');
|
||||||
|
const httpServer = createServer(app);
|
||||||
|
const io = require('./socket').init(httpServer);
|
||||||
|
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
|
|
||||||
@@ -19,8 +22,6 @@ app.get('/', (req, res) => res.send('API Pcpuma'));
|
|||||||
|
|
||||||
app.use(require('./routes/index'));
|
app.use(require('./routes/index'));
|
||||||
|
|
||||||
app.listen(Number(process.env.PORT), () =>
|
httpServer.listen(Number(process.env.PORT), () =>
|
||||||
console.log(
|
console.log(`API Pcpuma corriendo en el puerto: ${process.env.PORT}`.rainbow)
|
||||||
`API Pcpuma corriendo en el puerto: ${process.env.PORT}`.rainbow
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
require('./config');
|
|
||||||
const mariadb = require('mariadb');
|
const mariadb = require('mariadb');
|
||||||
|
require('./config');
|
||||||
|
|
||||||
const pool = mariadb.createPool({
|
const pool = mariadb.createPool({
|
||||||
host: process.env.ESCOLARES_HOST,
|
host: process.env.ESCOLARES_HOST,
|
||||||
@@ -29,7 +29,7 @@ const obtenerAlumno = async (numeroCuenta) => {
|
|||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
conn.end();
|
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
|
return conn
|
||||||
.query(`SELECT * FROM Profesor WHERE NumTrabajador = ${numeroCuenta}`)
|
.query(
|
||||||
|
`SELECT * FROM ${process.env.TABLA_PROFESORES} WHERE NumTrabajador = ${numeroCuenta}`
|
||||||
|
)
|
||||||
.then((rows) => {
|
.then((rows) => {
|
||||||
conn.end();
|
conn.end();
|
||||||
if (rows.length === 0) return null;
|
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 dbPath = '../../db/tablas';
|
||||||
const Carrito = require(`${dbPath}/Carrito`);
|
const Carrito = require(`${dbPath}/Carrito`);
|
||||||
const Modulo = require(`${dbPath}/Modulo`);
|
const Modulo = require(`${dbPath}/Modulo`);
|
||||||
const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
||||||
|
|
||||||
const carrito = async (body) => {
|
const carrito = async (body) => {
|
||||||
const idCarrito = validarId(body.idCarrito);
|
const idCarrito = validarNumeroEntero(body.idCarrito, 'id carrito', true);
|
||||||
|
|
||||||
return Carrito.findOne({
|
return Carrito.findOne({
|
||||||
where: { idCarrito },
|
where: { idCarrito },
|
||||||
include: [{ model: TipoCarrito }, { model: Modulo }],
|
include: [{ model: TipoCarrito }, { model: Modulo }],
|
||||||
|
attributes: ['idCarrito', 'carrito', 'activo'],
|
||||||
}).then((res) => {
|
}).then((res) => {
|
||||||
if (!res) throw new Error('No existe este carrito.');
|
if (!res) throw new Error('No existe este carrito.');
|
||||||
delete res.dataValues.idTipoCarrito;
|
|
||||||
delete res.dataValues.idModulo;
|
|
||||||
return res;
|
return res;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,16 +3,10 @@ const Carrito = require(`${dbPath}/Carrito`);
|
|||||||
const Modulo = require(`${dbPath}/Modulo`);
|
const Modulo = require(`${dbPath}/Modulo`);
|
||||||
const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
||||||
|
|
||||||
const carritos = async () => {
|
const carritos = async () =>
|
||||||
return Carrito.findAll({
|
Carrito.findAll({
|
||||||
include: [{ model: TipoCarrito }, { model: Modulo }],
|
include: [{ model: TipoCarrito }, { model: Modulo }],
|
||||||
}).then((res) => {
|
attributes: ['idCarrito', 'carrito', 'activo'],
|
||||||
for (let i = 0; i < res.length; i++) {
|
|
||||||
delete res[i].dataValues.idTipoCarrito;
|
|
||||||
delete res[i].dataValues.idModulo;
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
});
|
});
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = carritos;
|
module.exports = carritos;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const { validarId } = require('../../helper/validar');
|
const { validarNumeroEntero } = require('../../helper/validar');
|
||||||
const dbPath = '../../db/tablas';
|
const dbPath = '../../db/tablas';
|
||||||
const Carrito = require(`${dbPath}/Carrito`);
|
const Carrito = require(`${dbPath}/Carrito`);
|
||||||
const Equipo = require(`${dbPath}/Equipo`);
|
const Equipo = require(`${dbPath}/Equipo`);
|
||||||
@@ -6,24 +6,16 @@ const Programa = require(`${dbPath}/Programa`);
|
|||||||
const Status = require(`${dbPath}/Status`);
|
const Status = require(`${dbPath}/Status`);
|
||||||
|
|
||||||
const equiposCarrito = async (body) => {
|
const equiposCarrito = async (body) => {
|
||||||
const idCarrito = validarId(body.idCarrito);
|
const idCarrito = validarNumeroEntero(body.idCarrito, 'id carrito', true);
|
||||||
|
|
||||||
return Carrito.findOne({ where: { idCarrito } })
|
return Carrito.findOne({ where: { idCarrito } }).then((res) => {
|
||||||
.then((res) => {
|
if (!res) throw new Error('No existe este carrito.');
|
||||||
if (!res) throw new Error('No existe este carrito.');
|
return Equipo.findAll({
|
||||||
return Equipo.findAll({
|
where: { idCarrito },
|
||||||
where: { idCarrito },
|
include: [{ model: Status }, { model: Programa }],
|
||||||
include: [{ model: Status }, { model: Programa }],
|
attributes: ['idEquipo', 'numeroSerie', 'numeroInventario', 'equipo'],
|
||||||
});
|
|
||||||
})
|
|
||||||
.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;
|
|
||||||
});
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = equiposCarrito;
|
module.exports = equiposCarrito;
|
||||||
|
|||||||
@@ -1,20 +1,36 @@
|
|||||||
const { validarId } = require('../../helper/validar');
|
const validar = require('../../helper/validar');
|
||||||
const dbPath = '../../db/tablas';
|
const dbPath = '../../db/tablas';
|
||||||
const Carrito = require(`${dbPath}/Carrito`);
|
const Carrito = require(`${dbPath}/Carrito`);
|
||||||
|
const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
||||||
|
|
||||||
const update = async (body) => {
|
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 = {};
|
let update = {};
|
||||||
|
|
||||||
if (body.activo === 'desactivar') update.activo = false;
|
return TipoCarrito.findOne({ where: { idTipoCarrito } })
|
||||||
else if (body.activo === 'activar') update.activo = true;
|
.then((res) => {
|
||||||
else throw new Error('No se envio nada para actualizar.');
|
if (idTipoCarrito) {
|
||||||
return Carrito.findOne({ where: { idCarrito } })
|
if (!res) throw new Error('No existe este tipo carrito.');
|
||||||
|
update.idTipoCarrito = idTipoCarrito;
|
||||||
|
}
|
||||||
|
return Carrito.findOne({ where: { idCarrito } });
|
||||||
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (!res) throw new Error('No existe este carrito.');
|
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 } });
|
return Carrito.update(update, { where: { idCarrito } });
|
||||||
})
|
})
|
||||||
.then((res) => ({ message: 'Se actualizó correctamente el carrito.' }));
|
.then(() => ({ message: 'Se actualizó correctamente el carrito.' }));
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = update;
|
module.exports = update;
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ const cargaMasiva = async (file) => {
|
|||||||
: {};
|
: {};
|
||||||
let existeCarrito = await Carrito.findOne({
|
let existeCarrito = await Carrito.findOne({
|
||||||
where: {
|
where: {
|
||||||
sobrenombre: equipos[i].carritoSobrenombre,
|
idCarrito: equipos[i].carrito,
|
||||||
idModulo: existeModulo.idModulo,
|
idModulo: existeModulo.idModulo,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -63,12 +63,12 @@ const cargaMasiva = async (file) => {
|
|||||||
}
|
}
|
||||||
if (!existeCarrito) {
|
if (!existeCarrito) {
|
||||||
existeCarrito = await Carrito.create({
|
existeCarrito = await Carrito.create({
|
||||||
sobrenombre: equipos[i].carritoSobrenombre,
|
carrito: equipos[i].carritoSobrenombre,
|
||||||
idTipoCarrito: existeTipoCarrito.idTipoCarrito,
|
idTipoCarrito: existeTipoCarrito.idTipoCarrito,
|
||||||
idModulo: existeModulo.idModulo,
|
idModulo: existeModulo.idModulo,
|
||||||
});
|
});
|
||||||
avisos.push(
|
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({
|
existeEquipo = await Equipo.findAll({
|
||||||
@@ -78,7 +78,7 @@ const cargaMasiva = async (file) => {
|
|||||||
Equipo.create({
|
Equipo.create({
|
||||||
numeroSerie: equipos[i].numeroSerie,
|
numeroSerie: equipos[i].numeroSerie,
|
||||||
numeroInventario: equipos[i].numeroInventario,
|
numeroInventario: equipos[i].numeroInventario,
|
||||||
sobrenombre: `${existeTipoCarrito.letra}${
|
equipo: `${existeTipoCarrito.letra}${
|
||||||
res.length < 9 ? '0' + (res.length + 1) : res.length + 1
|
res.length < 9 ? '0' + (res.length + 1) : res.length + 1
|
||||||
}`,
|
}`,
|
||||||
idCarrito: existeCarrito.idCarrito,
|
idCarrito: existeCarrito.idCarrito,
|
||||||
@@ -95,21 +95,23 @@ const cargaMasiva = async (file) => {
|
|||||||
{
|
{
|
||||||
model: Carrito,
|
model: Carrito,
|
||||||
include: [{ model: TipoCarrito }, { model: Modulo }],
|
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);
|
equiposNuevos.push(existeEquipo);
|
||||||
}
|
}
|
||||||
await eliminarArchivo(path);
|
await eliminarArchivo(path);
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
message: 'Se subio correctamente el archivo csv.',
|
message: 'Se subió correctamente el archivo csv.',
|
||||||
equiposNuevos,
|
equiposNuevos,
|
||||||
errores,
|
errores,
|
||||||
avisos,
|
avisos,
|
||||||
|
|||||||
@@ -10,25 +10,25 @@ const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
|||||||
const equipo = async (body) => {
|
const equipo = async (body) => {
|
||||||
const numeroInventario = validarAlfanumerico(
|
const numeroInventario = validarAlfanumerico(
|
||||||
body.numeroInventario,
|
body.numeroInventario,
|
||||||
'El numero de inventario',
|
'numero de inventario',
|
||||||
|
true,
|
||||||
20
|
20
|
||||||
);
|
);
|
||||||
|
|
||||||
return Equipo.findOne({
|
return Equipo.findOne({
|
||||||
where: { numeroInventario },
|
where: { numeroInventario },
|
||||||
include: [
|
include: [
|
||||||
{ model: Carrito, include: [{ model: TipoCarrito }, { model: Modulo }] },
|
{
|
||||||
|
model: Carrito,
|
||||||
|
include: [{ model: TipoCarrito }, { model: Modulo }],
|
||||||
|
attributes: ['idCarrito', 'carrito', 'activo'],
|
||||||
|
},
|
||||||
{ model: Status },
|
{ model: Status },
|
||||||
{ model: Programa },
|
{ model: Programa },
|
||||||
],
|
],
|
||||||
|
attributes: ['idEquipo', 'numeroSerie', 'numeroInventario', 'equipo'],
|
||||||
}).then((res) => {
|
}).then((res) => {
|
||||||
if (!res) throw new Error('No existe este equipo.');
|
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;
|
return res;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,28 +2,22 @@ const dbPath = '../../db/tablas';
|
|||||||
const Carrito = require(`${dbPath}/Carrito`);
|
const Carrito = require(`${dbPath}/Carrito`);
|
||||||
const Equipo = require(`${dbPath}/Equipo`);
|
const Equipo = require(`${dbPath}/Equipo`);
|
||||||
const Modulo = require(`${dbPath}/Modulo`);
|
const Modulo = require(`${dbPath}/Modulo`);
|
||||||
|
const Status = require(`${dbPath}/Status`);
|
||||||
const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
||||||
|
|
||||||
const equipos = async () => {
|
const equipos = async () =>
|
||||||
return Carrito.findAll({
|
Carrito.findAll({
|
||||||
include: [{ model: TipoCarrito }, { model: Modulo }],
|
include: [{ model: TipoCarrito }, { model: Modulo }],
|
||||||
|
attributes: ['idCarrito', 'carrito', 'activo'],
|
||||||
}).then(async (res) => {
|
}).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({
|
res[i].dataValues.Equipos = await Equipo.findAll({
|
||||||
where: { idCarrito: res[i].idCarrito },
|
where: { idCarrito: res[i].idCarrito },
|
||||||
}).then((res) => {
|
include: [{ model: Status }],
|
||||||
for (let j = 0; j < res.length; j++) {
|
attributes: ['idEquipo', 'numeroSerie', 'numeroInventario', 'equipo'],
|
||||||
delete res[j].dataValues.idCarrito;
|
order: [['equipo', 'ASC']],
|
||||||
delete res[j].dataValues.idStatus;
|
|
||||||
delete res[j].dataValues.idPrograma;
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
});
|
});
|
||||||
delete res[i].dataValues.idTipoCarrito;
|
|
||||||
delete res[i].dataValues.idModulo;
|
|
||||||
}
|
|
||||||
return res;
|
return res;
|
||||||
});
|
});
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = equipos;
|
module.exports = equipos;
|
||||||
|
|||||||
@@ -2,41 +2,63 @@ const validar = require('../../helper/validar');
|
|||||||
const dbPath = '../../db/tablas';
|
const dbPath = '../../db/tablas';
|
||||||
const Carrito = require(`${dbPath}/Carrito`);
|
const Carrito = require(`${dbPath}/Carrito`);
|
||||||
const Equipo = require(`${dbPath}/Equipo`);
|
const Equipo = require(`${dbPath}/Equipo`);
|
||||||
|
const Motivo = require(`${dbPath}/Motivo`);
|
||||||
const Programa = require(`${dbPath}/Programa`);
|
const Programa = require(`${dbPath}/Programa`);
|
||||||
const Status = require(`${dbPath}/Status`);
|
const Status = require(`${dbPath}/Status`);
|
||||||
|
|
||||||
const update = async (body) => {
|
const update = async (body) => {
|
||||||
const idEquipo = validar.validarId(body.idEquipo);
|
const idEquipo = validar.validarNumeroEntero(
|
||||||
const idStatus = body.idStatus ? validar.validarId(body.idStatus) : null;
|
body.idEquipo,
|
||||||
const idCarrito = body.idCarrito ? validar.validarId(body.idCarrito) : null;
|
'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
|
const idPrograma = body.idPrograma
|
||||||
? validar.validarId(body.idPrograma)
|
? validar.validarNumeroEntero(body.idPrograma, 'id programa', true)
|
||||||
: null;
|
: '';
|
||||||
|
const motivo = body.motivo
|
||||||
|
? validar.validarAlfanumerico(body.motivo, 'motivo', true, 500)
|
||||||
|
: '';
|
||||||
let update = {};
|
let update = {};
|
||||||
|
|
||||||
if (idStatus)
|
return Status.findOne({ where: { 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 } })
|
|
||||||
.then((res) => {
|
.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 (!res) throw new Error('No existe este equipo.');
|
||||||
|
if (idStatus) await Motivo.create({ motivo, idEquipo, idStatus });
|
||||||
return Equipo.update(update, { where: { idEquipo } });
|
return Equipo.update(update, { where: { idEquipo } });
|
||||||
})
|
})
|
||||||
.then((res) => ({ message: 'Se actualizó correctamente el equipo.' }));
|
.then(() => ({ message: 'Se actualizó correctamente el equipo.' }));
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = update;
|
module.exports = update;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
const Infraccion = require('../../db/tablas/Infraccion');
|
|
||||||
const { Op } = require('sequelize');
|
const { Op } = require('sequelize');
|
||||||
|
const Infraccion = require('../../db/tablas/Infraccion');
|
||||||
|
|
||||||
const get = async () =>
|
const get = async () =>
|
||||||
Infraccion.findAll({ where: { idInfraccion: { [Op.ne]: 1 } } });
|
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 dbPath = '../../db/tablas';
|
||||||
const Multa = require(`${dbPath}/Multa`);
|
const Multa = require(`${dbPath}/Multa`);
|
||||||
const Operador = require(`${dbPath}/Operador`);
|
const Operador = require(`${dbPath}/Operador`);
|
||||||
const Prestamo = require(`${dbPath}/Prestamo`);
|
const Prestamo = require(`${dbPath}/Prestamo`);
|
||||||
|
|
||||||
const historialMultasEquipo = async (body) => {
|
const historialMultasEquipo = async (body) => {
|
||||||
const idEquipo = validar.validarId(body.idEquipo);
|
const pagina = validarNumeroEntero(body.pagina, 'página', false);
|
||||||
const pagina = validar.validarNumero(body.pagina, true);
|
const idEquipo = validarNumeroEntero(body.idEquipo, 'id equipo', true);
|
||||||
|
|
||||||
return Multa.findAndCountAll({
|
return Multa.findAndCountAll({
|
||||||
include: [
|
include: [
|
||||||
{
|
{
|
||||||
model: Prestamo,
|
model: Prestamo,
|
||||||
where: { idEquipo },
|
where: { idEquipo },
|
||||||
|
attributes: ['idPrestamo'],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
model: Operador,
|
||||||
|
as: 'OperadorMulta',
|
||||||
|
attributes: ['idOperador', 'operador'],
|
||||||
},
|
},
|
||||||
{ model: Operador, as: 'OperadorMulta' },
|
|
||||||
],
|
],
|
||||||
|
attributes: ['idMulta', 'descripcion', 'fechaFin', 'createdAt'],
|
||||||
limit: 25,
|
limit: 25,
|
||||||
offset: 25 * (pagina - 1),
|
offset: 25 * (pagina - 1),
|
||||||
order: [['createdAt', 'DESC']],
|
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 dbPath = '../../db/tablas';
|
||||||
const Carrito = require(`${dbPath}/Carrito`);
|
const Carrito = require(`${dbPath}/Carrito`);
|
||||||
const Equipo = require(`${dbPath}/Equipo`);
|
const Equipo = require(`${dbPath}/Equipo`);
|
||||||
@@ -10,57 +10,27 @@ const Prestamo = require(`${dbPath}/Prestamo`);
|
|||||||
const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
||||||
|
|
||||||
const historialMultasUsuario = async (body) => {
|
const historialMultasUsuario = async (body) => {
|
||||||
const idUsuario = validar.validarId(body.idUsuario);
|
const pagina = validarNumeroEntero(body.pagina, 'página', false);
|
||||||
const pagina = validar.validarNumero(body.pagina, true);
|
const idUsuario = validarNumeroEntero(body.idUsuario, 'id usuario', true);
|
||||||
|
|
||||||
return Multa.findAndCountAll({
|
return Multa.findAndCountAll({
|
||||||
include: [
|
include: [
|
||||||
{
|
{
|
||||||
model: Prestamo,
|
model: Prestamo,
|
||||||
where: { idUsuario },
|
where: { idUsuario },
|
||||||
include: [
|
attributes: ['idPrestamo'],
|
||||||
{
|
},
|
||||||
model: Equipo,
|
{
|
||||||
include: [
|
model: Operador,
|
||||||
{
|
as: 'OperadorMulta',
|
||||||
model: Carrito,
|
attributes: ['idOperador', 'operador'],
|
||||||
include: [{ model: Modulo }, { model: TipoCarrito }],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
{ model: Infraccion },
|
{ model: Infraccion },
|
||||||
{ model: Operador, as: 'OperadorMulta' },
|
|
||||||
],
|
],
|
||||||
|
attributes: ['idMulta', 'descripcion', 'fechaFin', 'createdAt'],
|
||||||
limit: 25,
|
limit: 25,
|
||||||
offset: 25 * (pagina - 1),
|
offset: 25 * (pagina - 1),
|
||||||
order: [['createdAt', 'DESC']],
|
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 moment = require('moment');
|
||||||
|
const { Op } = require('sequelize');
|
||||||
const validar = require('../../helper/validar');
|
const validar = require('../../helper/validar');
|
||||||
const dbPath = '../../db/tablas';
|
const dbPath = '../../db/tablas';
|
||||||
const Infraccion = require(`${dbPath}/Infraccion`);
|
const Infraccion = require(`${dbPath}/Infraccion`);
|
||||||
@@ -8,16 +9,32 @@ const Prestamo = require(`${dbPath}/Prestamo`);
|
|||||||
const Usuario = require(`${dbPath}/Usuario`);
|
const Usuario = require(`${dbPath}/Usuario`);
|
||||||
|
|
||||||
const multar = async (body) => {
|
const multar = async (body) => {
|
||||||
const idOperadorMulta = validar.validarId(body.idOperadorMulta);
|
const ahora = moment();
|
||||||
const idInfraccion = validar.validarId(body.idInfraccion);
|
const idOperadorMulta = validar.validarNumeroEntero(
|
||||||
const idPrestamo = validar.validarId(body.idPrestamo);
|
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(
|
const descripcion = validar.validarAlfanumerico(
|
||||||
body.descripcion,
|
body.descripcion,
|
||||||
'La descripción',
|
'descripción',
|
||||||
|
false,
|
||||||
500
|
500
|
||||||
);
|
);
|
||||||
let prestamo = {};
|
|
||||||
let fechaFin = moment();
|
let fechaFin = moment();
|
||||||
|
let prestamo = {};
|
||||||
|
let gravedad = '';
|
||||||
|
|
||||||
return Operador.findOne({ where: { idOperador: idOperadorMulta } })
|
return Operador.findOne({ where: { idOperador: idOperadorMulta } })
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (!res) throw new Error('No existe este operador.');
|
if (!res) throw new Error('No existe este operador.');
|
||||||
@@ -25,36 +42,76 @@ const multar = async (body) => {
|
|||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (!res) throw new Error('No existe esta infracción.');
|
if (!res) throw new Error('No existe esta infracción.');
|
||||||
if (res.gravedad == '1') fechaFin.add(7, 'd');
|
gravedad = res.gravedad;
|
||||||
else fechaFin.add(100, 'y');
|
|
||||||
return Prestamo.findOne({
|
return Prestamo.findOne({
|
||||||
where: { idPrestamo },
|
where: { idPrestamo },
|
||||||
include: [{ model: Usuario }],
|
include: [{ model: Usuario }],
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.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;
|
prestamo = res;
|
||||||
return Multa.findOne({ where: { idPrestamo } });
|
return Prestamo.findOne({
|
||||||
|
where: { idUsuario: prestamo.idUsuario, activo: true },
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (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(
|
return Usuario.update(
|
||||||
{ multa: true },
|
{ multa: true },
|
||||||
{ where: { idUsuario: prestamo.Usuario.idUsuario } }
|
{ where: { idUsuario: prestamo.idUsuario } }
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.then((res) =>
|
.then(() =>
|
||||||
Multa.create({
|
Multa.create({
|
||||||
descripcion,
|
idPrestamo,
|
||||||
fechaFin: fechaFin.format(),
|
|
||||||
idOperadorMulta,
|
idOperadorMulta,
|
||||||
idInfraccion,
|
idInfraccion,
|
||||||
idPrestamo,
|
descripcion,
|
||||||
|
fechaFin: fechaFin.format('YYYY-MM-DD'),
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
.then((res) => ({
|
.then(() => ({
|
||||||
message: `Se levantó correctamente el reporte de multa.`,
|
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 moment = require('moment');
|
||||||
|
const { Op } = require('sequelize');
|
||||||
const validar = require('../../helper/validar');
|
const validar = require('../../helper/validar');
|
||||||
const dbPath = '../../db/tablas';
|
const dbPath = '../../db/tablas';
|
||||||
const Infraccion = require(`${dbPath}/Infraccion`);
|
const Infraccion = require(`${dbPath}/Infraccion`);
|
||||||
const Equipo = require(`${dbPath}/Equipo`);
|
const Equipo = require(`${dbPath}/Equipo`);
|
||||||
const Multa = require(`${dbPath}/Multa`);
|
const Multa = require(`${dbPath}/Multa`);
|
||||||
|
const Operador = require(`${dbPath}/Operador`);
|
||||||
const Prestamo = require(`${dbPath}/Prestamo`);
|
const Prestamo = require(`${dbPath}/Prestamo`);
|
||||||
const Usuario = require(`${dbPath}/Usuario`);
|
const Usuario = require(`${dbPath}/Usuario`);
|
||||||
|
|
||||||
const multarNumeroInventario = async (body) => {
|
const multarNumeroInventario = async (body) => {
|
||||||
const idOperadorMulta = validar.validarId(body.idOperadorMulta);
|
const idOperadorMulta = validar.validarNumeroEntero(
|
||||||
const idInfraccion = validar.validarId(body.idInfraccion);
|
body.idOperadorMulta,
|
||||||
|
'id operador multa',
|
||||||
|
true
|
||||||
|
);
|
||||||
|
const idInfraccion = validar.validarNumeroEntero(
|
||||||
|
body.idInfraccion,
|
||||||
|
'id infracción',
|
||||||
|
true
|
||||||
|
);
|
||||||
const numeroInventario = validar.validarAlfanumerico(
|
const numeroInventario = validar.validarAlfanumerico(
|
||||||
body.numeroInventario,
|
body.numeroInventario,
|
||||||
'El numero de inventario',
|
'número de inventario',
|
||||||
20
|
20
|
||||||
);
|
);
|
||||||
const descripcion = validar.validarAlfanumerico(
|
const descripcion = validar.validarAlfanumerico(
|
||||||
body.descripcion,
|
body.descripcion,
|
||||||
'La descripción',
|
'descripción',
|
||||||
|
false,
|
||||||
500
|
500
|
||||||
);
|
);
|
||||||
let prestamo = {};
|
|
||||||
let fechaFin = moment();
|
let fechaFin = moment();
|
||||||
|
let idPrestamo = null;
|
||||||
|
|
||||||
return Operador.findOne({ where: { idOperador: idOperadorMulta } })
|
return Operador.findOne({ where: { idOperador: idOperadorMulta } })
|
||||||
.then((res) => {
|
.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 } });
|
return Infraccion.findOne({ where: { idInfraccion } });
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (!res) throw new Error('No existe esta infracción.');
|
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');
|
else fechaFin.add(100, 'y');
|
||||||
return Prestamo.findOne({
|
return Prestamo.findOne({
|
||||||
where: { activo: true },
|
where: { activo: true },
|
||||||
include: [
|
include: [{ model: Equipo, where: { numeroInventario } }],
|
||||||
{ model: Equipo, where: { numeroInventario } },
|
|
||||||
{ model: Usuario },
|
|
||||||
],
|
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (!res)
|
if (!res)
|
||||||
throw new Error('No existe un prestamo activo con este equipo.');
|
throw new Error('No existe un prestamo activo con este equipo.');
|
||||||
prestamo = res;
|
idPrestamo = res.idPrestamo;
|
||||||
return Multa.findOne({ where: { idPrestamo: prestamo.idPrestamo } });
|
|
||||||
})
|
|
||||||
.then((res) => {
|
|
||||||
if (res)
|
|
||||||
throw new Error('A este prestamo ya se le ha asignado una multa.');
|
|
||||||
return Usuario.update(
|
return Usuario.update(
|
||||||
{ multa: true },
|
{ multa: true },
|
||||||
{ where: { idUsuario: prestamo.Usuario.idUsuario } }
|
{ where: { idUsuario: res.idUsuario } }
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.then((res) =>
|
.then(() =>
|
||||||
Multa.create({
|
Multa.create({
|
||||||
descripcion,
|
idPrestamo,
|
||||||
idOperadorMulta,
|
idOperadorMulta,
|
||||||
idInfraccion,
|
idInfraccion,
|
||||||
idPrestamo: prestamo.idPrestamo,
|
descripcion,
|
||||||
fechaFin: fechaFin.format(),
|
fechaFin: fechaFin.format('YYYY-MM-DD'),
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
.then((res) => ({
|
.then(() => ({
|
||||||
message: `Se levantó correctamente el reporte de multa.`,
|
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 Operador = require('../../db/tablas/Operador');
|
||||||
|
|
||||||
const crear = async (body) => {
|
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(
|
const password = validar.validarAlfanumerico(
|
||||||
body.password,
|
body.password,
|
||||||
'La contraseña',
|
'contraseña',
|
||||||
|
false,
|
||||||
20
|
20
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -20,7 +21,7 @@ const crear = async (body) => {
|
|||||||
idTipoUsuario: 2,
|
idTipoUsuario: 2,
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.then((res) => ({ message: 'Se creo un nuevo operador correctamente.' }));
|
.then(() => ({ message: 'Se creó un nuevo operador correctamente.' }));
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = crear;
|
module.exports = crear;
|
||||||
|
|||||||
@@ -7,33 +7,33 @@ const Operador = require(`${dbPath}/Operador`);
|
|||||||
const TipoUsuario = require(`${dbPath}/TipoUsuario`);
|
const TipoUsuario = require(`${dbPath}/TipoUsuario`);
|
||||||
|
|
||||||
const login = async (body) => {
|
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(
|
const password = validar.validarAlfanumerico(
|
||||||
body.password,
|
body.password,
|
||||||
'La contraseña',
|
'contraseña',
|
||||||
|
false,
|
||||||
20
|
20
|
||||||
);
|
);
|
||||||
|
|
||||||
return Operador.findOne({
|
return Operador.findOne({ where: { operador } })
|
||||||
where: { operador },
|
.then((res) => {
|
||||||
include: [{ model: TipoUsuario }],
|
if (!res) throw new Error('No existe este operador.');
|
||||||
}).then((res) => {
|
if (!res.activo) throw new Error('Este operador no esta activo.');
|
||||||
if (!res) throw new Error('No existe este operador.');
|
if (!comparar(password, res.password))
|
||||||
if (!res.activo) throw new Error('Este operador no esta activo.');
|
throw new Error('La contraseña es incorrecta.');
|
||||||
if (comparar(password, res.password)) {
|
return Operador.findOne({
|
||||||
delete res.dataValues.password;
|
where: { operador },
|
||||||
delete res.dataValues.activo;
|
include: [{ model: TipoUsuario }],
|
||||||
delete res.dataValues.idTipoUsuario;
|
attributes: ['idOperador', 'operador', 'activo'],
|
||||||
return {
|
});
|
||||||
Operador: res,
|
})
|
||||||
token: crearTokenOperador({
|
.then((res) => ({
|
||||||
idOperador: res.idOperador,
|
Operador: res,
|
||||||
idTipoUsuario: res.TipoUsuario.idTipoUsuario,
|
token: crearTokenOperador({
|
||||||
}),
|
idOperador: res.idOperador,
|
||||||
};
|
idTipoUsuario: res.TipoUsuario.idTipoUsuario,
|
||||||
}
|
}),
|
||||||
throw new Error('La contraseña es incorrecta.');
|
}));
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = login;
|
module.exports = login;
|
||||||
|
|||||||
@@ -1,23 +1,21 @@
|
|||||||
|
const { Op } = require('sequelize');
|
||||||
const validar = require('../../helper/validar');
|
const validar = require('../../helper/validar');
|
||||||
const dbPath = '../../db/tablas';
|
const dbPath = '../../db/tablas';
|
||||||
const Operador = require(`${dbPath}/Operador`);
|
const Operador = require(`${dbPath}/Operador`);
|
||||||
const TipoUsuario = require(`${dbPath}/TipoUsuario`);
|
const TipoUsuario = require(`${dbPath}/TipoUsuario`);
|
||||||
|
|
||||||
const operadores = async (body) => {
|
const operadores = async (body) => {
|
||||||
const pagina = validar.validarNumero(body.pagina, true);
|
const pagina = validar.validarNumeroEntero(body.pagina, 'página', false);
|
||||||
// filtros
|
const operador = body.operador
|
||||||
|
? validar.validarTexto(body.operador, 'operador', true, 20)
|
||||||
|
: '';
|
||||||
|
|
||||||
return Operador.findAndCountAll({
|
return Operador.findAndCountAll({
|
||||||
where: { idTipoUsuario: 2 },
|
where: { idTipoUsuario: 2, operador: { [Op.like]: `%${operador}%` } },
|
||||||
include: [{ model: TipoUsuario }],
|
include: [{ model: TipoUsuario }],
|
||||||
|
attributes: ['idOperador', 'operador', 'activo'],
|
||||||
limit: 25,
|
limit: 25,
|
||||||
offset: 25 * (pagina - 1),
|
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 Operador = require(`../../db/tablas/Operador`);
|
||||||
|
|
||||||
const update = async (body) => {
|
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 = {};
|
let update = {};
|
||||||
|
|
||||||
if (body.activo === 'desactivar') update.activo = false;
|
return Operador.findOne({ where: { idOperador } })
|
||||||
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 } })
|
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (!res) throw new Error('No existe este operador.');
|
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 } });
|
return Operador.update(update, { where: { idOperador } });
|
||||||
})
|
})
|
||||||
.then((res) => ({ message: 'Se actualizó correctamente al operador.' }));
|
.then(() => ({ message: 'Se actualizó correctamente al operador.' }));
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = update;
|
module.exports = update;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const { Op } = require('sequelize');
|
const { Op, where } = require('sequelize');
|
||||||
const validar = require('../../helper/validar');
|
const validar = require('../../helper/validar');
|
||||||
const dbPath = '../../db/tablas';
|
const dbPath = '../../db/tablas';
|
||||||
const Carrera = require(`${dbPath}/Carrera`);
|
const Carrera = require(`${dbPath}/Carrera`);
|
||||||
@@ -6,80 +6,97 @@ const Carrito = require(`${dbPath}/Carrito`);
|
|||||||
const Equipo = require(`${dbPath}/Equipo`);
|
const Equipo = require(`${dbPath}/Equipo`);
|
||||||
const Modulo = require(`${dbPath}/Modulo`);
|
const Modulo = require(`${dbPath}/Modulo`);
|
||||||
const Prestamo = require(`${dbPath}/Prestamo`);
|
const Prestamo = require(`${dbPath}/Prestamo`);
|
||||||
|
const Status = require(`${dbPath}/Status`);
|
||||||
const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
||||||
const TipoUsuario = require(`${dbPath}/TipoUsuario`);
|
const TipoUsuario = require(`${dbPath}/TipoUsuario`);
|
||||||
const Usuario = require(`${dbPath}/Usuario`);
|
const Usuario = require(`${dbPath}/Usuario`);
|
||||||
|
|
||||||
const activos = async (body) => {
|
const activos = async (body) => {
|
||||||
const idModulo = validar.validarId(body.idModulo);
|
const pagina = validar.validarNumeroEntero(body.pagina, 'página', false);
|
||||||
const pagina = validar.validarNumero(body.pagina, true);
|
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 usuario = body.usuario ? validar.validarNumeroCuenta(body.usuario) : '';
|
||||||
const idPrestamo = body.idPrestamo ? validar.validarId(body.idPrestamo) : '';
|
|
||||||
const numeroInventario = body.numeroInventario
|
const numeroInventario = body.numeroInventario
|
||||||
? validar.validarAlfanumerico(
|
? validar.validarAlfanumerico(
|
||||||
body.numeroInventario,
|
body.numeroInventario,
|
||||||
'El numero de inventario',
|
'numero de inventario',
|
||||||
|
true,
|
||||||
20
|
20
|
||||||
)
|
)
|
||||||
: '';
|
: '';
|
||||||
const idTipoCarrito = body.idTipoCarrito
|
const carrito = body.carrito
|
||||||
? validar.validarId(body.idTipoCarrito)
|
? validar.validarAlfanumerico(body.carrito, 'carrito', true)
|
||||||
: null;
|
: '';
|
||||||
|
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 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 });
|
if (idTipoCarrito) whereCarrito.push({ idTipoCarrito });
|
||||||
return Modulo.findOne({ where: { idModulo } })
|
if (idPrestamo) wherePrestamo.idPrestamo = { [Op.like]: `%${idPrestamo}%` };
|
||||||
.then((res) => {
|
return Modulo.findOne({ where: { idModulo } }).then((res) => {
|
||||||
if (!res) throw new Error('No existe este modulo.');
|
if (!res) throw new Error('No existe este módulo.');
|
||||||
return Prestamo.findAndCountAll({
|
return Prestamo.findAndCountAll({
|
||||||
where: { activo: true, idPrestamo: { [Op.like]: `%${idPrestamo}%` } },
|
where: wherePrestamo,
|
||||||
include: [
|
include: [
|
||||||
{
|
{
|
||||||
model: Equipo,
|
model: Equipo,
|
||||||
where: { numeroInventario: { [Op.like]: `%${numeroInventario}%` } },
|
where: whereEquipo,
|
||||||
include: [
|
include: [
|
||||||
{
|
{
|
||||||
model: Carrito,
|
model: Carrito,
|
||||||
where: { [Op.and]: whereCarrito },
|
where: { [Op.and]: whereCarrito },
|
||||||
include: [{ model: TipoCarrito }, { model: Modulo }],
|
include: [{ model: TipoCarrito }, { model: Modulo }],
|
||||||
},
|
attributes: ['idCarrito', 'carrito'],
|
||||||
],
|
},
|
||||||
},
|
{ model: Status },
|
||||||
{
|
],
|
||||||
model: Usuario,
|
attributes: ['idEquipo', 'numeroSerie', 'numeroInventario', 'equipo'],
|
||||||
where: { usuario: { [Op.like]: `%${usuario}%` } },
|
},
|
||||||
include: [{ model: TipoUsuario }, { model: Carrera }],
|
{
|
||||||
},
|
model: Usuario,
|
||||||
],
|
where: { usuario: { [Op.like]: `%${usuario}%` } },
|
||||||
limit: 25,
|
include: [{ model: TipoUsuario }, { model: Carrera }],
|
||||||
offset: 25 * (pagina - 1),
|
attributes: ['idUsuario', 'usuario', 'nombre'],
|
||||||
order: [['createdAt', 'DESC']],
|
},
|
||||||
});
|
],
|
||||||
})
|
attributes: [
|
||||||
.then((res) => {
|
'idPrestamo',
|
||||||
for (let i = 0; i < res.rows.length; i++) {
|
'activo',
|
||||||
delete res.rows[i].dataValues.idUsuario;
|
'horaMaxRecoger',
|
||||||
delete res.rows[i].dataValues.idOperadorEntrega;
|
'horaInicio',
|
||||||
delete res.rows[i].dataValues.idOperadorRegreso;
|
'horaFin',
|
||||||
delete res.rows[i].dataValues.idOperadorCancelacion;
|
'horaEntrega',
|
||||||
delete res.rows[i].dataValues.idEquipo;
|
'regresoInmediato',
|
||||||
delete res.rows[i].dataValues.Equipo.dataValues.idPrograma;
|
'createdAt',
|
||||||
delete res.rows[i].dataValues.Equipo.dataValues.idStatus;
|
],
|
||||||
delete res.rows[i].dataValues.Equipo.dataValues.idCarrito;
|
limit: 25,
|
||||||
delete res.rows[i].dataValues.Equipo.dataValues.Carrito.dataValues
|
offset: 25 * (pagina - 1),
|
||||||
.idTipoCarrito;
|
order: [['idPrestamo', 'ASC']],
|
||||||
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 };
|
|
||||||
});
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = activos;
|
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 dbPath = '../../db/tablas';
|
||||||
const Equipo = require(`${dbPath}/Equipo`);
|
const Equipo = require(`${dbPath}/Equipo`);
|
||||||
|
const Motivo = require(`${dbPath}/Motivo`);
|
||||||
const Operador = require(`${dbPath}/Operador`);
|
const Operador = require(`${dbPath}/Operador`);
|
||||||
const Prestamo = require(`${dbPath}/Prestamo`);
|
const Prestamo = require(`${dbPath}/Prestamo`);
|
||||||
|
|
||||||
const cancelarOperador = async (body) => {
|
const cancelarOperador = async (body) => {
|
||||||
const idPrestamo = validarId(body.idPrestamo);
|
const idPrestamo = validar.validarNumeroEntero(
|
||||||
const idOperadorCancelacion = validarId(body.idOperadorCancelacion);
|
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) => {
|
.then((res) => {
|
||||||
if (!res) throw new Error('No existe esta este operador.');
|
if (!res) throw new Error('No existe este operador.');
|
||||||
return Prestamo.findOne({
|
return Prestamo.findOne({ where: { idPrestamo } });
|
||||||
where: { idPrestamo },
|
|
||||||
include: [{ model: Equipo }],
|
|
||||||
});
|
|
||||||
})
|
})
|
||||||
|
.then(async (res) => {
|
||||||
.then((res) => {
|
if (!res) throw new Error('Este préstamo no existe.');
|
||||||
if (!res) throw new Error('Este prestamo no existe.');
|
idUsuario = res.idUsuario;
|
||||||
if (!res.activo)
|
if (!res.activo)
|
||||||
throw new Error(
|
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)
|
|
||||||
throw new Error(
|
|
||||||
'El equipo ya fue entregado al usuario, ya no se puede cancelar.'
|
|
||||||
);
|
);
|
||||||
|
await Motivo.create({ motivo, idEquipo: res.idEquipo, idStatus: 9 });
|
||||||
return Equipo.update(
|
return Equipo.update(
|
||||||
{ apartado: false },
|
{ idStatus: 9 },
|
||||||
{ where: { idEquipo: res.Equipo.idEquipo } }
|
{ where: { idEquipo: res.idEquipo } }
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.then((res) =>
|
.then(() =>
|
||||||
Prestamo.update(
|
Prestamo.update(
|
||||||
{ activo: false, idOperadorCancelacion },
|
{
|
||||||
|
activo: false,
|
||||||
|
idOperadorRegreso: idOperador,
|
||||||
|
canceladoOperador: true,
|
||||||
|
},
|
||||||
{ where: { idPrestamo } }
|
{ 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;
|
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 dbPath = '../../db/tablas';
|
||||||
const Prestamo = require(`${dbPath}/Prestamo`);
|
|
||||||
const Equipo = require(`${dbPath}/Equipo`);
|
const Equipo = require(`${dbPath}/Equipo`);
|
||||||
|
const Prestamo = require(`${dbPath}/Prestamo`);
|
||||||
|
const Usuario = require(`${dbPath}/Usuario`);
|
||||||
|
|
||||||
const cancelarUsuario = async (body) => {
|
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({
|
return Usuario.findOne({ where: { idUsuario } })
|
||||||
where: { idPrestamo },
|
|
||||||
include: [{ model: Equipo }],
|
|
||||||
})
|
|
||||||
.then((res) => {
|
.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)
|
if (!res.activo)
|
||||||
throw new Error(
|
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(
|
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(
|
return Equipo.update(
|
||||||
{ apartado: false },
|
{ idStatus: 4 },
|
||||||
{ where: { idEquipo: res.Equipo.idEquipo } }
|
{ where: { idEquipo: res.idEquipo } }
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.then((res) =>
|
.then(() =>
|
||||||
Prestamo.update(
|
Prestamo.update(
|
||||||
{ activo: false, canceladoUsuario: true },
|
{ activo: false, canceladoUsuario: true },
|
||||||
{ where: { idPrestamo } }
|
{ 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;
|
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 moment = require('moment');
|
||||||
const { validarId } = require('../../helper/validar');
|
const io = require('../../socket');
|
||||||
|
const { validarNumeroEntero } = require('../../helper/validar');
|
||||||
const dbPath = '../../db/tablas';
|
const dbPath = '../../db/tablas';
|
||||||
const Carrito = require(`${dbPath}/Carrito`);
|
const Carrito = require(`${dbPath}/Carrito`);
|
||||||
const Equipo = require(`${dbPath}/Equipo`);
|
const Equipo = require(`${dbPath}/Equipo`);
|
||||||
@@ -10,9 +11,18 @@ const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
|||||||
|
|
||||||
const entregar = async (body) => {
|
const entregar = async (body) => {
|
||||||
const ahora = moment();
|
const ahora = moment();
|
||||||
const idPrestamo = validarId(body.idPrestamo);
|
const idPrestamo = validarNumeroEntero(body.idPrestamo, 'id préstamo', true);
|
||||||
const idOperadorEntrega = validarId(body.idOperadorEntrega);
|
const idOperadorEntrega = validarNumeroEntero(
|
||||||
let idEquipo;
|
body.idOperadorEntrega,
|
||||||
|
'id operador entrega',
|
||||||
|
true
|
||||||
|
);
|
||||||
|
let update = {
|
||||||
|
idOperadorEntrega,
|
||||||
|
horaInicio: ahora.format(),
|
||||||
|
};
|
||||||
|
let idEquipo = null;
|
||||||
|
let idUsuario = null;
|
||||||
|
|
||||||
return Operador.findOne({ where: { idOperador: idOperadorEntrega } })
|
return Operador.findOne({ where: { idOperador: idOperadorEntrega } })
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
@@ -23,47 +33,47 @@ const entregar = async (body) => {
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
.then(async (res) => {
|
.then(async (res) => {
|
||||||
if (!res) throw new Error('No existe este prestamo.');
|
if (!res) throw new Error('No existe este préstamo.');
|
||||||
idEquipo = res.Equipo.idEquipo;
|
idEquipo = res.idEquipo;
|
||||||
if (!res.activo) throw new Error('Este prestamo ya no esta activo.');
|
idUsuario = res.idUsuario;
|
||||||
else if (res.Equipo.enUso)
|
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.');
|
throw new Error('Ya se entrego el equipo al usuario.');
|
||||||
else if (moment(res.horaMaxRecoger) < ahora) {
|
if (moment(res.horaMaxRecoger) < ahora)
|
||||||
await Equipo.update({ apartado: false }, { where: { idEquipo } });
|
await Equipo.update({ idStatus: 4 }, { where: { idEquipo } })
|
||||||
await Prestamo.update({ activo: false }, { where: { idPrestamo } });
|
.then(() =>
|
||||||
throw new Error(
|
Prestamo.update({ activo: false }, { where: { idPrestamo } })
|
||||||
'Ya paso el tiempo limite para recoger el dispositivo.'
|
)
|
||||||
);
|
.then(() => {
|
||||||
}
|
io.getIO().emit('actualizar', { idUsuario });
|
||||||
return Equipo.update({ enUso: true }, { where: { idEquipo } });
|
throw new Error(
|
||||||
})
|
'Ya pasó el tiempo límite para recoger el equipo de cómputo.'
|
||||||
.then((res) => {
|
);
|
||||||
Prestamo.update(
|
});
|
||||||
{
|
if (ahora > moment(`${ahora.format('YYYY-MM-DD')} 17:45`))
|
||||||
idOperadorEntrega,
|
update.horaFin = moment(`${ahora.format('YYYY-MM-DD')} 19:45`);
|
||||||
horaInicio: ahora.format(),
|
else update.horaFin = ahora.add(2, 'h').format();
|
||||||
horaFin: ahora.add(2, 'h').format(),
|
return Equipo.update(
|
||||||
},
|
{ idStatus: 2, prestado: true },
|
||||||
{ where: { idPrestamo } }
|
{ where: { idEquipo } }
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then(() => Prestamo.update(update, { where: { idPrestamo } }))
|
||||||
return Equipo.findOne({
|
.then(() =>
|
||||||
|
Equipo.findOne({
|
||||||
where: { idEquipo },
|
where: { idEquipo },
|
||||||
include: [
|
include: [
|
||||||
{
|
{
|
||||||
model: Carrito,
|
model: Carrito,
|
||||||
include: [{ model: TipoCarrito }, { model: Modulo }],
|
include: [{ model: TipoCarrito }, { model: Modulo }],
|
||||||
|
attributes: ['idCarrito', 'carrito'],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
attributes: ['idEquipo', 'numeroSerie', 'numeroInventario', 'equipo'],
|
||||||
})
|
})
|
||||||
|
)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
delete res.dataValues.idCarrito;
|
io.getIO().emit('actualizar', { idUsuario });
|
||||||
delete res.dataValues.idStatus;
|
|
||||||
delete res.dataValues.idPrograma;
|
|
||||||
delete res.dataValues.Carrito.dataValues.idTipoCarrito;
|
|
||||||
delete res.dataValues.Carrito.dataValues.idModulo;
|
|
||||||
return res;
|
return res;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -12,20 +12,25 @@ const TipoUsuario = require(`${dbPath}/TipoUsuario`);
|
|||||||
const Usuario = require(`${dbPath}/Usuario`);
|
const Usuario = require(`${dbPath}/Usuario`);
|
||||||
|
|
||||||
const historial = async (body) => {
|
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 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
|
const numeroInventario = body.numeroInventario
|
||||||
? validar.validarAlfanumerico(
|
? validar.validarAlfanumerico(
|
||||||
body.numeroInventario,
|
body.numeroInventario,
|
||||||
'El numero de inventario',
|
'numero de inventario',
|
||||||
|
true,
|
||||||
20
|
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
|
const idTipoCarrito = body.idTipoCarrito
|
||||||
? validar.validarId(body.idTipoCarrito)
|
? validar.validarNumeroEntero(body.idTipoCarrito, 'id tipo carrito', true)
|
||||||
: null;
|
: '';
|
||||||
let whereCarrito = [];
|
let whereCarrito = [];
|
||||||
|
|
||||||
if (idTipoCarrito) whereCarrito.push({ idTipoCarrito });
|
if (idTipoCarrito) whereCarrito.push({ idTipoCarrito });
|
||||||
@@ -47,53 +52,49 @@ const historial = async (body) => {
|
|||||||
model: Carrito,
|
model: Carrito,
|
||||||
where: { [Op.and]: whereCarrito },
|
where: { [Op.and]: whereCarrito },
|
||||||
include: [{ model: TipoCarrito }, { model: Modulo }],
|
include: [{ model: TipoCarrito }, { model: Modulo }],
|
||||||
|
attributes: ['idCarrito', 'carrito'],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
attributes: [
|
||||||
|
'idEquipo',
|
||||||
|
'numeroSerie',
|
||||||
|
'numeroInventario',
|
||||||
|
'equipo',
|
||||||
|
'updatedAt',
|
||||||
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
model: Usuario,
|
model: Usuario,
|
||||||
where: { usuario: { [Op.like]: `%${usuario}%` } },
|
where: { usuario: { [Op.like]: `%${usuario}%` } },
|
||||||
include: [{ model: TipoUsuario }, { model: Carrera }],
|
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,
|
limit: 25,
|
||||||
offset: 25 * (pagina - 1),
|
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 Usuario = require(`${dbPath}/Usuario`);
|
||||||
|
|
||||||
const historialEquipo = async (body) => {
|
const historialEquipo = async (body) => {
|
||||||
const idEquipo = validar.validarId(body.idEquipo);
|
const pagina = validar.validarNumeroEntero(body.pagina, 'página', false);
|
||||||
const pagina = validar.validarNumero(body.pagina, true);
|
const idEquipo = validar.validarNumeroEntero(
|
||||||
|
body.idEquipo,
|
||||||
|
'id equipo',
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
return Prestamo.findAndCountAll({
|
return Prestamo.findAndCountAll({
|
||||||
include: [
|
include: [
|
||||||
{ model: Equipo, where: { idEquipo } },
|
{
|
||||||
{ model: Usuario, include: [{ model: TipoUsuario }, { model: Carrera }] },
|
model: Equipo,
|
||||||
{ model: Operador, as: 'OperadorRegreso' },
|
where: { idEquipo },
|
||||||
{ model: Operador, as: 'OperadorEntrega' },
|
attributes: ['idEquipo', 'numeroSerie', 'numeroInventario', 'equipo'],
|
||||||
{ model: Operador, as: 'OperadorCancelacion' },
|
},
|
||||||
|
{
|
||||||
|
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,
|
limit: 25,
|
||||||
offset: 25 * (pagina - 1),
|
offset: 25 * (pagina - 1),
|
||||||
order: [['createdAt', 'DESC']],
|
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 Usuario = require(`${dbPath}/Usuario`);
|
||||||
|
|
||||||
const historialUsuario = async (body) => {
|
const historialUsuario = async (body) => {
|
||||||
const idUsuario = validar.validarId(body.idUsuario);
|
const pagina = validar.validarNumeroEntero(body.pagina, 'página', false);
|
||||||
const pagina = validar.validarNumero(body.pagina, true);
|
const idUsuario = validar.validarNumeroEntero(
|
||||||
|
body.idUsuario,
|
||||||
|
'id usuario',
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
return Prestamo.findAndCountAll({
|
return Prestamo.findAndCountAll({
|
||||||
include: [
|
include: [
|
||||||
@@ -21,53 +25,43 @@ const historialUsuario = async (body) => {
|
|||||||
{
|
{
|
||||||
model: Carrito,
|
model: Carrito,
|
||||||
include: [{ model: TipoCarrito }, { model: Modulo }],
|
include: [{ model: TipoCarrito }, { model: Modulo }],
|
||||||
|
attributes: ['idCarrito', 'carrito'],
|
||||||
},
|
},
|
||||||
{ model: Programa },
|
{ 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,
|
limit: 25,
|
||||||
offset: 25 * (pagina - 1),
|
offset: 25 * (pagina - 1),
|
||||||
order: [['createdAt', 'DESC']],
|
order: [['createdAt', 'DESC']],
|
||||||
}).then((res) => {
|
attributes: [
|
||||||
for (let i = 0; i < res.rows.length; i++) {
|
'idPrestamo',
|
||||||
delete res.rows[i].dataValues.idOperadorEntrega;
|
'activo',
|
||||||
delete res.rows[i].dataValues.idOperadorRegreso;
|
'horaMaxRecoger',
|
||||||
delete res.rows[i].dataValues.idOperadorCancelacion;
|
'horaInicio',
|
||||||
delete res.rows[i].dataValues.idUsuario;
|
'horaFin',
|
||||||
delete res.rows[i].dataValues.idEquipo;
|
'horaEntrega',
|
||||||
delete res.rows[i].dataValues.Usuario;
|
'canceladoUsuario',
|
||||||
delete res.rows[i].dataValues.Equipo.dataValues.idCarrito;
|
'canceladoOperador',
|
||||||
delete res.rows[i].dataValues.Equipo.dataValues.idStatus;
|
'regresoInmediato',
|
||||||
delete res.rows[i].dataValues.Equipo.dataValues.idPrograma;
|
'createdAt',
|
||||||
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 };
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,43 +1,55 @@
|
|||||||
const moment = require('moment');
|
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 dbPath = '../../db/tablas';
|
||||||
const Carrito = require(`${dbPath}/Carrito`);
|
const Carrito = require(`${dbPath}/Carrito`);
|
||||||
const Equipo = require(`${dbPath}/Equipo`);
|
const Equipo = require(`${dbPath}/Equipo`);
|
||||||
const Modulo = require(`${dbPath}/Modulo`);
|
const Modulo = require(`${dbPath}/Modulo`);
|
||||||
const Prestamo = require(`${dbPath}/Prestamo`);
|
const Prestamo = require(`${dbPath}/Prestamo`);
|
||||||
const Programa = require(`${dbPath}/Programa`);
|
const Programa = require(`${dbPath}/Programa`);
|
||||||
const Status = require(`${dbPath}/Status`);
|
|
||||||
const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
||||||
const Usuario = require(`${dbPath}/Usuario`);
|
const Usuario = require(`${dbPath}/Usuario`);
|
||||||
|
|
||||||
const pedir = async (body) => {
|
const pedir = async (body) => {
|
||||||
const ahora = moment();
|
const ahora = moment();
|
||||||
const horaMax = moment().format('20:00:00');
|
const horaMax = moment(`${ahora.format('YYYY-MM-DD')} 18:45`);
|
||||||
const horaMin = moment().format('09:00:00');
|
const horaMin = moment(`${ahora.format('YYYY-MM-DD')} 09:00`);
|
||||||
const idUsuario = validarId(body.idUsuario);
|
const idUsuario = validarNumeroEntero(body.idUsuario, 'id usuario', true);
|
||||||
const idTipoCarrito = validarId(body.idTipoCarrito);
|
const idTipoCarrito = validarNumeroEntero(
|
||||||
const idPrograma = body.idPrograma ? validarId(body.idPrograma) : null;
|
body.idTipoCarrito,
|
||||||
const idModulo = idPrograma ? 1 : validarId(body.idModulo);
|
'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;
|
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 } })
|
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) => {
|
.then((res) => {
|
||||||
if (!res) throw new Error('No existe este tipo de equipo.');
|
if (!res) throw new Error('No existe este tipo de equipo.');
|
||||||
return Modulo.findOne({ where: { idModulo } });
|
return Modulo.findOne({ where: { idModulo } });
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.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 } });
|
return Programa.findOne({ where: { idPrograma } });
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (!res && idPrograma) throw new Error('No existe este programa.');
|
if (!res && idPrograma) throw new Error('No existe este programa.');
|
||||||
|
if (idPrograma) whereEquipo.idPrograma = idPrograma;
|
||||||
return Usuario.findOne({ where: { idUsuario } });
|
return Usuario.findOne({ where: { idUsuario } });
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
@@ -45,31 +57,84 @@ const pedir = async (body) => {
|
|||||||
if (!res.activo) throw new Error('Este usuario no esta activo.');
|
if (!res.activo) throw new Error('Este usuario no esta activo.');
|
||||||
if (res.multa)
|
if (res.multa)
|
||||||
throw new Error(
|
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) => {
|
.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(
|
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: {
|
return Equipo.count({
|
||||||
apartado: false,
|
where: whereEquipo,
|
||||||
idStatus: 1,
|
|
||||||
idPrograma,
|
|
||||||
},
|
|
||||||
include: [
|
include: [
|
||||||
{
|
{
|
||||||
model: Carrito,
|
model: Carrito,
|
||||||
where: { idTipoCarrito, idModulo, activo: true },
|
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) => {
|
.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.'
|
'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;
|
idEquipo = res.idEquipo;
|
||||||
return Equipo.update({ apartado: true }, { where: { idEquipo } });
|
return Equipo.update({ idStatus: 1 }, { where: { idEquipo } });
|
||||||
})
|
})
|
||||||
.then((res) =>
|
.then(() =>
|
||||||
Prestamo.create({
|
Prestamo.create({
|
||||||
horaMaxRecoger: ahora.add(10, 'm'),
|
horaMaxRecoger: ahora.add(10, 'm'),
|
||||||
idUsuario,
|
idUsuario,
|
||||||
idEquipo,
|
idEquipo,
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
.then((res) => {
|
.then(() => {
|
||||||
return Prestamo.findOne({
|
io.getIO().emit('actualizar', { idUsuario });
|
||||||
where: { idPrestamo: res.idPrestamo },
|
return {
|
||||||
include: [
|
message:
|
||||||
{
|
'Haz solicitado un equipo de cómputo correctamente. Presentate al módulo señalado y muestra tu QR.',
|
||||||
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;
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const { validarId } = require('../../helper/validar');
|
const { validarNumeroEntero } = require('../../helper/validar');
|
||||||
const dbPath = '../../db/tablas';
|
const dbPath = '../../db/tablas';
|
||||||
const Carrera = require(`${dbPath}/Carrera`);
|
const Carrera = require(`${dbPath}/Carrera`);
|
||||||
const Carrito = require(`${dbPath}/Carrito`);
|
const Carrito = require(`${dbPath}/Carrito`);
|
||||||
@@ -7,12 +7,13 @@ const Modulo = require(`${dbPath}/Modulo`);
|
|||||||
const Operador = require(`${dbPath}/Operador`);
|
const Operador = require(`${dbPath}/Operador`);
|
||||||
const Prestamo = require(`${dbPath}/Prestamo`);
|
const Prestamo = require(`${dbPath}/Prestamo`);
|
||||||
const Programa = require(`${dbPath}/Programa`);
|
const Programa = require(`${dbPath}/Programa`);
|
||||||
|
const Status = require(`${dbPath}/Status`);
|
||||||
const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
||||||
const TipoUsuario = require(`${dbPath}/TipoUsuario`);
|
const TipoUsuario = require(`${dbPath}/TipoUsuario`);
|
||||||
const Usuario = require(`${dbPath}/Usuario`);
|
const Usuario = require(`${dbPath}/Usuario`);
|
||||||
|
|
||||||
const prestamo = async (body) => {
|
const prestamo = async (body) => {
|
||||||
const idPrestamo = validarId(body.idPrestamo);
|
const idPrestamo = validarNumeroEntero(body.idPrestamo, 'id préstamo', true);
|
||||||
|
|
||||||
return Prestamo.findOne({
|
return Prestamo.findOne({
|
||||||
where: { idPrestamo },
|
where: { idPrestamo },
|
||||||
@@ -23,43 +24,43 @@ const prestamo = async (body) => {
|
|||||||
{
|
{
|
||||||
model: Carrito,
|
model: Carrito,
|
||||||
include: [{ model: TipoCarrito }, { model: Modulo }],
|
include: [{ model: TipoCarrito }, { model: Modulo }],
|
||||||
|
attributes: ['idCarrito', 'carrito'],
|
||||||
},
|
},
|
||||||
{ model: Programa },
|
{ model: Programa },
|
||||||
|
{ model: Status },
|
||||||
],
|
],
|
||||||
|
attributes: ['idEquipo', 'numeroSerie', 'numeroInventario', 'equipo'],
|
||||||
},
|
},
|
||||||
{ model: Usuario, include: [{ model: TipoUsuario }, { model: Carrera }] },
|
{
|
||||||
{ model: Operador, as: 'OperadorRegreso' },
|
model: Usuario,
|
||||||
{ model: Operador, as: 'OperadorEntrega' },
|
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) => {
|
}).then((res) => {
|
||||||
if (!res) throw new Error('No existe este prestamo.');
|
if (!res) throw new Error('No existe este préstamo.');
|
||||||
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;
|
|
||||||
}
|
|
||||||
return res;
|
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 dbPath = '../../db/tablas';
|
||||||
const Carrito = require(`${dbPath}/Carrito`);
|
const Carrito = require(`${dbPath}/Carrito`);
|
||||||
const Equipo = require(`${dbPath}/Equipo`);
|
const Equipo = require(`${dbPath}/Equipo`);
|
||||||
const Modulo = require(`${dbPath}/Modulo`);
|
const Modulo = require(`${dbPath}/Modulo`);
|
||||||
const Prestamo = require(`${dbPath}/Prestamo`);
|
const Prestamo = require(`${dbPath}/Prestamo`);
|
||||||
const Programa = require(`${dbPath}/Programa`);
|
const Programa = require(`${dbPath}/Programa`);
|
||||||
|
const Status = require(`${dbPath}/Status`);
|
||||||
const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
||||||
const Usuario = require(`${dbPath}/Usuario`);
|
const Usuario = require(`${dbPath}/Usuario`);
|
||||||
|
|
||||||
const prestamo = async (body) => {
|
const prestamoUsuario = async (body) => {
|
||||||
const idUsuario = validarId(body.idUsuario);
|
const idUsuario = validarNumeroEntero(body.idUsuario, 'id usuario', true);
|
||||||
|
|
||||||
return Usuario.findOne({ where: { idUsuario } })
|
return Usuario.findOne({ where: { idUsuario } }).then((res) => {
|
||||||
.then((res) => {
|
if (!res) throw new Error('No existe este usuario.');
|
||||||
if (!res) throw new Error('No existe este usuario.');
|
return Prestamo.findOne({
|
||||||
|
where: { idUsuario, activo: true },
|
||||||
return Prestamo.findOne({
|
include: [
|
||||||
where: { idUsuario, activo: true },
|
{
|
||||||
include: [
|
model: Equipo,
|
||||||
{
|
include: [
|
||||||
model: Equipo,
|
{
|
||||||
include: [
|
model: Carrito,
|
||||||
{
|
include: [{ model: TipoCarrito }, { model: Modulo }],
|
||||||
model: Carrito,
|
attributes: ['idCarrito', 'carrito'],
|
||||||
include: [{ model: TipoCarrito }, { model: Modulo }],
|
},
|
||||||
},
|
{ model: Status },
|
||||||
{ model: Programa },
|
{ model: Programa },
|
||||||
],
|
],
|
||||||
},
|
attributes: ['idEquipo', 'numeroSerie', 'numeroInventario', 'equipo'],
|
||||||
],
|
},
|
||||||
});
|
],
|
||||||
})
|
attributes: [
|
||||||
.then((res) => {
|
'idPrestamo',
|
||||||
if (!res) return null;
|
'activo',
|
||||||
delete res.dataValues.idUsuario;
|
'horaMaxRecoger',
|
||||||
delete res.dataValues.idOperadorEntrega;
|
'horaInicio',
|
||||||
delete res.dataValues.idOperadorRegreso;
|
'horaFin',
|
||||||
delete res.dataValues.idOperadorCancelacion;
|
'horaEntrega',
|
||||||
delete res.dataValues.idEquipo;
|
'canceladoUsuario',
|
||||||
delete res.dataValues.Equipo.dataValues.idPrograma;
|
'canceladoOperador',
|
||||||
delete res.dataValues.Equipo.dataValues.idStatus;
|
'regresoInmediato',
|
||||||
delete res.dataValues.Equipo.dataValues.idCarrito;
|
'createdAt',
|
||||||
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;
|
|
||||||
});
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = prestamo;
|
module.exports = prestamoUsuario;
|
||||||
|
|||||||
@@ -1,16 +1,25 @@
|
|||||||
const moment = require('moment');
|
const moment = require('moment');
|
||||||
const multar = require('../Multa/multar');
|
const io = require('../../socket');
|
||||||
const { validarId } = require('../../helper/validar');
|
const { validarNumeroEntero } = require('../../helper/validar');
|
||||||
const prestamo = require('./prestamoUsuario');
|
|
||||||
const dbPath = '../../db/tablas';
|
const dbPath = '../../db/tablas';
|
||||||
const Equipo = require(`${dbPath}/Equipo`);
|
const Equipo = require(`${dbPath}/Equipo`);
|
||||||
|
const Multa = require(`${dbPath}/Multa`);
|
||||||
const Operador = require(`${dbPath}/Operador`);
|
const Operador = require(`${dbPath}/Operador`);
|
||||||
const Prestamo = require(`${dbPath}/Prestamo`);
|
const Prestamo = require(`${dbPath}/Prestamo`);
|
||||||
|
const Usuario = require(`${dbPath}/Usuario`);
|
||||||
|
|
||||||
const regresar = async (body) => {
|
const regresar = async (body) => {
|
||||||
const idPrestamo = validarId(body.idPrestamo);
|
|
||||||
const idOperadorRegreso = validarId(body.idOperadorRegreso);
|
|
||||||
const ahora = moment();
|
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 } })
|
return Operador.findOne({ where: { idOperador: idOperadorRegreso } })
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
@@ -22,33 +31,38 @@ const regresar = async (body) => {
|
|||||||
})
|
})
|
||||||
.then(async (res) => {
|
.then(async (res) => {
|
||||||
if (!res) throw new Error('No existe este préstamo.');
|
if (!res) throw new Error('No existe este préstamo.');
|
||||||
if (!res.activo) throw new Error('Este préstamo ya no esta activo.');
|
idUsuario = res.idUsuario;
|
||||||
if (!res.Equipo.enUso)
|
if (!res.activo && res.idOperadorRegreso)
|
||||||
throw new Error('Aun no se ha entregado el equipo al usuario.');
|
throw new Error('Este préstamo ya no esta activo.');
|
||||||
|
if (res.Equipo.idStatus === 1)
|
||||||
if (res.horaFin < ahora) {
|
throw new Error('Aún no se ha entregado el equipo al usuario.');
|
||||||
await multar({
|
if (!res.regresoInmediato) {
|
||||||
idOperadorMulta: idOperadorRegreso,
|
update.horaEntrega = ahora.format();
|
||||||
idPrestamo: res.idPrestamo,
|
update.activo = false;
|
||||||
idInfraccion: 1,
|
diferencia = parseInt((ahora - moment(res.horaFin)) / 60000);
|
||||||
descripcion: 'Demora',
|
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(
|
return Equipo.update(
|
||||||
{ enUso: false, apartado: false },
|
{ idStatus: 4 },
|
||||||
{ where: { idEquipo: res.Equipo.idEquipo } }
|
{ where: { idEquipo: res.idEquipo } }
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.then(async (res) => {
|
.then(() => Prestamo.update(update, { where: { idPrestamo } }))
|
||||||
await Prestamo.update(
|
.then(() => {
|
||||||
{ idOperadorRegreso, horaEntrega: ahora.format(), activo: false },
|
io.getIO().emit('actualizar', { idUsuario });
|
||||||
{ where: { idPrestamo } }
|
return {
|
||||||
);
|
message: 'Se ha regresado correctamente el equipo de cómputo.',
|
||||||
})
|
};
|
||||||
.then((res) => ({
|
});
|
||||||
message: 'Se ha regresado correctamente el equipo de cómputo.',
|
|
||||||
}));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = regresar;
|
module.exports = regresar;
|
||||||
|
|||||||
@@ -1,58 +1,87 @@
|
|||||||
const moment = require('moment');
|
const moment = require('moment');
|
||||||
const multar = require('../Multa/multar');
|
const { Op } = require('sequelize');
|
||||||
|
const io = require('../../socket');
|
||||||
const validar = require('../../helper/validar');
|
const validar = require('../../helper/validar');
|
||||||
const dbPath = '../../db/tablas';
|
const dbPath = '../../db/tablas';
|
||||||
const Equipo = require(`${dbPath}/Equipo`);
|
const Equipo = require(`${dbPath}/Equipo`);
|
||||||
|
const Multa = require(`${dbPath}/Multa`);
|
||||||
const Operador = require(`${dbPath}/Operador`);
|
const Operador = require(`${dbPath}/Operador`);
|
||||||
const Prestamo = require(`${dbPath}/Prestamo`);
|
const Prestamo = require(`${dbPath}/Prestamo`);
|
||||||
|
const Usuario = require(`${dbPath}/Usuario`);
|
||||||
|
|
||||||
const regresarNumeroInventario = async (body) => {
|
const regresarNumeroInventario = async (body) => {
|
||||||
|
const ahora = moment();
|
||||||
|
const ahoraAux = moment();
|
||||||
const numeroInventario = validar.validarAlfanumerico(
|
const numeroInventario = validar.validarAlfanumerico(
|
||||||
body.numeroInventario,
|
body.numeroInventario,
|
||||||
'El numero de inventario',
|
'numero de inventario',
|
||||||
|
true,
|
||||||
20
|
20
|
||||||
);
|
);
|
||||||
const idOperadorRegreso = validar.validarId(body.idOperadorRegreso);
|
const idOperadorRegreso = validar.validarNumeroEntero(
|
||||||
const ahora = moment();
|
body.idOperadorRegreso,
|
||||||
let idPrestamo;
|
'id operador regreso',
|
||||||
|
true
|
||||||
|
);
|
||||||
|
const update = { idOperadorRegreso };
|
||||||
|
let diferencia = null;
|
||||||
|
let idPrestamo = null;
|
||||||
|
let idUsuario = null;
|
||||||
|
|
||||||
return Operador.findOne({ where: { idOperador: idOperadorRegreso } })
|
return Operador.findOne({ where: { idOperador: idOperadorRegreso } })
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (!res) throw new Error('No existe este operador.');
|
if (!res) throw new Error('No existe este operador.');
|
||||||
return Prestamo.findOne({
|
return Prestamo.findOne({
|
||||||
where: { activo: true },
|
where: {
|
||||||
|
[Op.or]: [
|
||||||
|
{ activo: true },
|
||||||
|
{
|
||||||
|
[Op.and]: [
|
||||||
|
{ regresoInmediato: true },
|
||||||
|
{ idOperadorRegreso: null },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
include: [{ model: Equipo, where: { numeroInventario } }],
|
include: [{ model: Equipo, where: { numeroInventario } }],
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.then(async (res) => {
|
.then(async (res) => {
|
||||||
if (!res)
|
if (!res)
|
||||||
throw new Error('No existe un prestamo activo con este equipo.');
|
throw new Error(
|
||||||
if (!res.Equipo.enUso)
|
'No existe un préstamo activo con este equipo de cómputo.'
|
||||||
throw new Error('Aun no se ha entregado el equipo al usuario.');
|
);
|
||||||
|
if (res.Equipo.idStatus === 1)
|
||||||
|
throw new Error('Aún no se ha entregado el equipo al usuario.');
|
||||||
idPrestamo = res.idPrestamo;
|
idPrestamo = res.idPrestamo;
|
||||||
|
idUsuario = res.idUsuario;
|
||||||
if (res.horaFin < ahora) {
|
if (!res.regresoInmediato) {
|
||||||
await multar({
|
update.horaEntrega = ahora.format();
|
||||||
idOperadorMulta: idOperadorRegreso,
|
update.activo = false;
|
||||||
idPrestamo: res.idPrestamo,
|
diferencia = parseInt((ahora - moment(res.horaFin)) / 60000);
|
||||||
idInfraccion: 1,
|
if (diferencia >= 15)
|
||||||
descripcion: 'Demora',
|
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(
|
return Equipo.update(
|
||||||
{ enUso: false, apartado: false },
|
{ idStatus: 4 },
|
||||||
{ where: { idEquipo: res.Equipo.idEquipo } }
|
{ where: { idEquipo: res.idEquipo } }
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then(() => Prestamo.update(update, { where: { idPrestamo } }))
|
||||||
Prestamo.update(
|
.then(() => {
|
||||||
{ idOperadorRegreso, horaEntrega: ahora.format(), activo: false },
|
io.getIO().emit('actualizar', { idUsuario });
|
||||||
{ where: { idPrestamo } }
|
return {
|
||||||
);
|
message: 'Se ha regresado correctamente el equipo de cómputo.',
|
||||||
})
|
};
|
||||||
.then((res) => ({
|
});
|
||||||
message: 'Se ha regresado correctamente el equio de computo.',
|
|
||||||
}));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = regresarNumeroInventario;
|
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 moment = require('moment');
|
||||||
const { validarId } = require('../../helper/validar');
|
const io = require('../../socket');
|
||||||
|
const { validarNumeroEntero } = require('../../helper/validar');
|
||||||
const dbPath = '../../db/tablas';
|
const dbPath = '../../db/tablas';
|
||||||
const Carrito = require(`${dbPath}/Carrito`);
|
const Carrito = require(`${dbPath}/Carrito`);
|
||||||
const Equipo = require(`${dbPath}/Equipo`);
|
const Equipo = require(`${dbPath}/Equipo`);
|
||||||
const Modulo = require(`${dbPath}/Modulo`);
|
const Modulo = require(`${dbPath}/Modulo`);
|
||||||
const Prestamo = require(`${dbPath}/Prestamo`);
|
const Prestamo = require(`${dbPath}/Prestamo`);
|
||||||
const Programa = require(`${dbPath}/Programa`);
|
const Programa = require(`${dbPath}/Programa`);
|
||||||
|
const Status = require(`${dbPath}/Status`);
|
||||||
const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
||||||
|
|
||||||
const status = async (body) => {
|
const status = async (body) => {
|
||||||
const idPrestamo = validarId(body.idPrestamo);
|
|
||||||
const ahora = moment();
|
const ahora = moment();
|
||||||
|
const idPrestamo = validarNumeroEntero(body.idPrestamo, 'id préstamo', true);
|
||||||
|
let message = '';
|
||||||
|
let atraso = false;
|
||||||
|
let idUsuario = null;
|
||||||
|
|
||||||
return Prestamo.findOne({
|
return Prestamo.findOne({
|
||||||
where: { idPrestamo },
|
where: { idPrestamo },
|
||||||
include: [
|
include: [{ model: Equipo }],
|
||||||
{
|
})
|
||||||
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: [
|
include: [
|
||||||
{
|
{
|
||||||
model: Carrito,
|
model: Equipo,
|
||||||
include: [{ model: TipoCarrito }, { model: Modulo }],
|
include: [
|
||||||
|
{
|
||||||
|
model: Carrito,
|
||||||
|
include: [{ model: TipoCarrito }, { model: Modulo }],
|
||||||
|
attributes: ['idCarrito', 'carrito'],
|
||||||
|
},
|
||||||
|
{ model: Status },
|
||||||
|
{ model: Programa },
|
||||||
|
],
|
||||||
|
attributes: [
|
||||||
|
'idEquipo',
|
||||||
|
'numeroSerie',
|
||||||
|
'numeroInventario',
|
||||||
|
'equipo',
|
||||||
|
],
|
||||||
},
|
},
|
||||||
{ model: Programa },
|
|
||||||
],
|
],
|
||||||
},
|
attributes: [
|
||||||
],
|
'idPrestamo',
|
||||||
}).then(async (res) => {
|
'activo',
|
||||||
if (!res) throw new Error('No existe este prestamo.');
|
'horaMaxRecoger',
|
||||||
delete res.dataValues.idUsuario;
|
'horaInicio',
|
||||||
delete res.dataValues.idOperadorEntrega;
|
'horaFin',
|
||||||
delete res.dataValues.idOperadorRegreso;
|
'horaEntrega',
|
||||||
delete res.dataValues.idOperadorCancelacion;
|
'canceladoUsuario',
|
||||||
delete res.dataValues.idEquipo;
|
'regresoInmediato',
|
||||||
delete res.dataValues.Equipo.dataValues.idPrograma;
|
'createdAt',
|
||||||
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;
|
.then((res) => ({ message, prestamo: res, atraso }));
|
||||||
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,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = status;
|
module.exports = status;
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
|
const { Op } = require('sequelize');
|
||||||
const Programa = require('../../db/tablas/Programa');
|
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;
|
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 helperPath = '../../helper';
|
||||||
const gmail = require(`${helperPath}/gmail`);
|
const correoPcPuma = require(`${helperPath}/correo`);
|
||||||
const encriptar = require(`${helperPath}/encriptar`);
|
const encriptar = require(`${helperPath}/encriptar`);
|
||||||
|
const gmail = require(`${helperPath}/gmail`);
|
||||||
const validar = require(`${helperPath}/validar`);
|
const validar = require(`${helperPath}/validar`);
|
||||||
const Usuario = require('../../db/tablas/Usuario');
|
const Usuario = require('../../db/tablas/Usuario');
|
||||||
|
|
||||||
const crear = async (body) => {
|
const crear = async (body) => {
|
||||||
const idUsuario = validar.validarId(body.idUsuario);
|
const idUsuario = validar.validarNumeroEntero(
|
||||||
const telefono = validar.validarNumero(body.telefono, false, 15);
|
body.idUsuario,
|
||||||
|
'id usuario',
|
||||||
|
true
|
||||||
|
);
|
||||||
|
const telefono = validar.validarNumero(body.telefono, 'teléfono', true, 15);
|
||||||
const password = encriptar.generarPassword();
|
const password = encriptar.generarPassword();
|
||||||
let correo = '@pcpuma.acatlan.unam.mx';
|
let correo = {};
|
||||||
|
let email = '';
|
||||||
|
|
||||||
return Usuario.findOne({ where: { idUsuario } })
|
return Usuario.findOne({ where: { idUsuario } })
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (!res) throw new Error('No existe este usuario.');
|
if (!res) throw new Error('No existe este usuario.');
|
||||||
if (res.password) throw new Error('Este usuario ya fue registrado.');
|
if (res.password) throw new Error('Este usuario ya fue registrado.');
|
||||||
if (!res.activo) throw new Error('Este usuario no esta activo.');
|
email = `${res.usuario}@pcpuma.acatlan.unam.mx`;
|
||||||
correo = res.usuario + correo;
|
correo = correoPcPuma(password);
|
||||||
return Usuario.update(
|
return Usuario.update(
|
||||||
{
|
{
|
||||||
password: encriptar.encriptar(password),
|
password: encriptar.encriptar(password),
|
||||||
@@ -24,11 +30,8 @@ const crear = async (body) => {
|
|||||||
{ where: { idUsuario } }
|
{ where: { idUsuario } }
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then(() => gmail(correo.subject, email, correo.msj))
|
||||||
// return gmail('Contraseña',correo,"")
|
.then(() => ({
|
||||||
return gmail('Contraseña', 'lemuelhelonmarquezrosas@gmail.com', password);
|
|
||||||
})
|
|
||||||
.then((res) => ({
|
|
||||||
message:
|
message:
|
||||||
'Se creó correctamente tu cuenta, ingresa a tu correo @pcpuma para consultar tu contraseña para este servicio.',
|
'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({
|
return Usuario.findOne({
|
||||||
where: { usuario: numeroCuenta },
|
where: { usuario: numeroCuenta },
|
||||||
include: [{ model: Carrera }, { model: TipoUsuario }],
|
attributes: ['idUsuario', 'password'],
|
||||||
})
|
}).then((res) => {
|
||||||
.then((res) => {
|
if (!res) {
|
||||||
if (!res) {
|
let usuario = { Carrera: null };
|
||||||
let usuario = { Carrera: {} };
|
let esAlumno = false;
|
||||||
let esAlumno = false;
|
|
||||||
|
|
||||||
return obtenerAlumno(numeroCuenta)
|
return obtenerAlumno(numeroCuenta)
|
||||||
.then(async (res) => {
|
.then(async (res) => {
|
||||||
if (!res) return obtenerProfesor(numeroCuenta);
|
if (!res) return obtenerProfesor(numeroCuenta);
|
||||||
esAlumno = true;
|
esAlumno = true;
|
||||||
return res;
|
return res;
|
||||||
})
|
})
|
||||||
.then(async (res) => {
|
.then(async (res) => {
|
||||||
usuario = res;
|
usuario = res;
|
||||||
if (!usuario)
|
if (!usuario)
|
||||||
throw new Error(
|
throw new Error('Este número de cuenta o de trabajador no existe.');
|
||||||
'Este número de cuenta o de trabajador no existe.'
|
if (esAlumno) {
|
||||||
);
|
if (usuario.inscrito != 'SI')
|
||||||
if (esAlumno) {
|
throw new Error('Este alumno no esta inscrito este semestre.');
|
||||||
if (usuario.inscrito != 'SI')
|
usuario.nombre = usuario.nombre.trim();
|
||||||
throw new Error('Este alumno no esta inscrito este semestre.');
|
usuario.idTipoUsuario = 4;
|
||||||
await Carrera.findOne({
|
usuario.Carrera = await Carrera.findOne({
|
||||||
where: { carrera: usuario.carrera },
|
where: { carrera: usuario.carrera },
|
||||||
})
|
}).then((res) => {
|
||||||
.then((res) => {
|
if (!res) return Carrera.create({ carrera: usuario.carrera });
|
||||||
if (!res) return Carrera.create({ carrera: usuario.carrera });
|
return res;
|
||||||
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,
|
|
||||||
});
|
});
|
||||||
|
} 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({
|
} else if (res.password)
|
||||||
where: { usuario: numeroCuenta },
|
throw new Error('Este número de cuenta ya fue registrado.');
|
||||||
include: [{ model: Carrera }, { model: TipoUsuario }],
|
return Usuario.findOne({
|
||||||
})
|
where: { usuario: numeroCuenta },
|
||||||
);
|
include: [{ model: Carrera }, { model: TipoUsuario }],
|
||||||
} else if (res.password)
|
attributes: ['idUsuario', 'usuario', 'nombre'],
|
||||||
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;
|
|
||||||
});
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = escolares;
|
module.exports = escolares;
|
||||||
|
|||||||
@@ -1,41 +1,44 @@
|
|||||||
const { Op } = require('sequelize');
|
const { Op } = require('sequelize');
|
||||||
const { crearTokenUsuario } = require('../../middleware/autentificacion');
|
const { crearTokenUsuario } = require('../../middleware/autentificacion');
|
||||||
const helperPath = '../../helper';
|
const helperPath = '../../helper';
|
||||||
const encriptar = require(`${helperPath}/encriptar`);
|
const { comparar } = require(`${helperPath}/encriptar`);
|
||||||
const validar = require(`${helperPath}/validar`);
|
const validar = require(`${helperPath}/validar`);
|
||||||
const dbPath = '../../db/tablas';
|
const dbPath = '../../db/tablas';
|
||||||
|
const Carrera = require(`${dbPath}/Carrera`);
|
||||||
const Usuario = require(`${dbPath}/Usuario`);
|
const Usuario = require(`${dbPath}/Usuario`);
|
||||||
const TipoUsuario = require(`${dbPath}/TipoUsuario`);
|
const TipoUsuario = require(`${dbPath}/TipoUsuario`);
|
||||||
|
|
||||||
const login = async (body) => {
|
const login = async (body) => {
|
||||||
const usuario = validar.validarNumeroCuenta(body.usuario, 'El usuario', 60);
|
const usuario = validar.validarNumeroCuenta(body.usuario);
|
||||||
const password = validar.validarAlfanumerico(
|
const password = validar.validarAlfanumerico(
|
||||||
body.password,
|
body.password,
|
||||||
'La contraseña',
|
'contraseña',
|
||||||
|
false,
|
||||||
20
|
20
|
||||||
);
|
);
|
||||||
|
|
||||||
return Usuario.findOne({
|
return Usuario.findOne({
|
||||||
where: { usuario, password: { [Op.ne]: null } },
|
where: { usuario, password: { [Op.ne]: null } },
|
||||||
include: [{ model: TipoUsuario }],
|
attributes: ['idUsuario', 'password', 'activo'],
|
||||||
}).then((res) => {
|
})
|
||||||
if (!res) throw new Error('No existe este usuario.');
|
.then((res) => {
|
||||||
if (!res.activo) throw new Error('Este usuario fue desactivado.');
|
if (!res) throw new Error('No existe este usuario.');
|
||||||
if (encriptar.comparar(password, res.password)) {
|
if (!res.activo) throw new Error('Este cuenta se encuentra desactivada.');
|
||||||
delete res.dataValues.password;
|
if (!comparar(password, res.password))
|
||||||
delete res.dataValues.idCarrera;
|
throw new Error('La contraseña es incorrecta.');
|
||||||
delete res.dataValues.idTipoUsuario;
|
return Usuario.findOne({
|
||||||
delete res.dataValues.telefono;
|
where: { usuario },
|
||||||
return {
|
include: [{ model: TipoUsuario }, { model: Carrera }],
|
||||||
Usuario: res,
|
attributes: ['idUsuario', 'usuario', 'nombre', 'multa', 'activo'],
|
||||||
token: crearTokenUsuario({
|
});
|
||||||
idUsuario: res.idUsuario,
|
})
|
||||||
idTipoUsuario: res.TipoUsuario.idTipoUsuario,
|
.then((res) => ({
|
||||||
}),
|
Usuario: res,
|
||||||
};
|
token: crearTokenUsuario({
|
||||||
}
|
idUsuario: res.idUsuario,
|
||||||
throw new Error('Usuario o contraseña no válidos.');
|
idTipoUsuario: res.TipoUsuario.idTipoUsuario,
|
||||||
});
|
}),
|
||||||
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = login;
|
module.exports = login;
|
||||||
|
|||||||
@@ -2,7 +2,11 @@ const validar = require('../../helper/validar');
|
|||||||
const Usuario = require(`../../db/tablas/Usuario`);
|
const Usuario = require(`../../db/tablas/Usuario`);
|
||||||
|
|
||||||
const quitarMulta = async (body) => {
|
const quitarMulta = async (body) => {
|
||||||
const idUsuario = validar.validarId(body.idUsuario);
|
const idUsuario = validar.validarNumeroEntero(
|
||||||
|
body.idUsuario,
|
||||||
|
'id usuario',
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
return Usuario.findOne({ where: { idUsuario } })
|
return Usuario.findOne({ where: { idUsuario } })
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
@@ -10,8 +14,8 @@ const quitarMulta = async (body) => {
|
|||||||
if (!res.multa) throw new Error('Este usuario no tiene multa.');
|
if (!res.multa) throw new Error('Este usuario no tiene multa.');
|
||||||
return Usuario.update({ multa: false }, { where: { idUsuario } });
|
return Usuario.update({ multa: false }, { where: { idUsuario } });
|
||||||
})
|
})
|
||||||
.then((res) => ({
|
.then(() => ({
|
||||||
message: 'Se le quito la multa a este usuario.',
|
message: 'Se le quitó la multa a este usuario.',
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -11,12 +11,16 @@ const usuario = async (body) => {
|
|||||||
return Usuario.findOne({
|
return Usuario.findOne({
|
||||||
where: { usuario, password: { [Op.ne]: null } },
|
where: { usuario, password: { [Op.ne]: null } },
|
||||||
include: [{ model: TipoUsuario }, { model: Carrera }],
|
include: [{ model: TipoUsuario }, { model: Carrera }],
|
||||||
|
attributes: [
|
||||||
|
'idUsuario',
|
||||||
|
'usuario',
|
||||||
|
'nombre',
|
||||||
|
'telefono',
|
||||||
|
'multa',
|
||||||
|
'activo',
|
||||||
|
],
|
||||||
}).then((res) => {
|
}).then((res) => {
|
||||||
if (!res) throw new Error('No existe este usuario.');
|
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;
|
return res;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,22 +6,26 @@ const TipoUsuario = require(`${dbPath}/TipoUsuario`);
|
|||||||
const Usuario = require(`${dbPath}/Usuario`);
|
const Usuario = require(`${dbPath}/Usuario`);
|
||||||
|
|
||||||
const usuarios = async (body) => {
|
const usuarios = async (body) => {
|
||||||
const pagina = validar.validarNumero(body.pagina, true);
|
const pagina = validar.validarNumeroEntero(body.pagina, 'página', false);
|
||||||
// filtros
|
const usuario = body.usuario ? validar.validarNumeroCuenta(body.usuario) : '';
|
||||||
|
const nombre = body.nombre
|
||||||
|
? validar.validarTexto(body.nombre, 'nombre', true, 70)
|
||||||
|
: '';
|
||||||
|
const idTipoUsuario = body.idTipoUsuario
|
||||||
|
? validar.validarNumeroEntero(body.idTipoUsuario, 'id tipo usuario', true)
|
||||||
|
: '';
|
||||||
|
|
||||||
return Usuario.findAndCountAll({
|
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 }],
|
include: [{ model: TipoUsuario }, { model: Carrera }],
|
||||||
|
attributes: ['idUsuario', 'usuario', 'nombre', 'multa', 'activo'],
|
||||||
limit: 25,
|
limit: 25,
|
||||||
offset: 25 * (pagina - 1),
|
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 Usuario = require('./tablas/Usuario');
|
||||||
const { encriptar } = require('../helper/encriptar');
|
|
||||||
|
|
||||||
const dataUsuarios = async () => {
|
const dataUsuarios = async () => {
|
||||||
let usuario = ['316313528', '111111111', '222222222'];
|
await Carrera.create({ carrera: 'Matemáticas Aplicadas y Computación' }).then(
|
||||||
let nombre = [
|
() =>
|
||||||
'Lemuel Helon Marquez Rosas',
|
Usuario.create({
|
||||||
'Nombre Falso 1',
|
usuario: '316313528',
|
||||||
'Nombre Falso 2',
|
nombre: 'Marquez Rosas Lemuel Helon',
|
||||||
];
|
idTipoUsuario: 4,
|
||||||
|
idCarrera: 1,
|
||||||
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,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const exec = async() => {
|
const exec = async () => {
|
||||||
await dataUsuarios();
|
await dataUsuarios();
|
||||||
console.log(
|
console.log(
|
||||||
'\nSe ha instalado exitosamente la información falsa en la base de datos.\n'
|
'\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 Equipo = require('./tablas/Equipo');
|
||||||
const Infraccion = require('./tablas/Infraccion');
|
const Infraccion = require('./tablas/Infraccion');
|
||||||
const Modulo = require('./tablas/Modulo');
|
const Modulo = require('./tablas/Modulo');
|
||||||
|
const Motivo = require('./tablas/Motivo');
|
||||||
const Multa = require('./tablas/Multa');
|
const Multa = require('./tablas/Multa');
|
||||||
const Operador = require('./tablas/Operador');
|
const Operador = require('./tablas/Operador');
|
||||||
const Prestamo = require('./tablas/Prestamo');
|
const Prestamo = require('./tablas/Prestamo');
|
||||||
@@ -27,6 +28,9 @@ const drop = async () => {
|
|||||||
await Prestamo.drop();
|
await Prestamo.drop();
|
||||||
console.log('La tabla Prestamo se desinstalo correctamente.'.magenta);
|
console.log('La tabla Prestamo se desinstalo correctamente.'.magenta);
|
||||||
|
|
||||||
|
await Motivo.drop();
|
||||||
|
console.log('La tabla Motivo se desinstalo correctamente.'.magenta);
|
||||||
|
|
||||||
await Equipo.drop();
|
await Equipo.drop();
|
||||||
console.log('La tabla Equipo se desinstalo correctamente.'.magenta);
|
console.log('La tabla Equipo se desinstalo correctamente.'.magenta);
|
||||||
|
|
||||||
@@ -91,6 +95,9 @@ const sync = async () => {
|
|||||||
await Equipo.sync();
|
await Equipo.sync();
|
||||||
console.log('La tabla Equipo se instalo correctamente.'.magenta);
|
console.log('La tabla Equipo se instalo correctamente.'.magenta);
|
||||||
|
|
||||||
|
await Motivo.sync();
|
||||||
|
console.log('La tabla Motivo se instalo correctamente.'.magenta);
|
||||||
|
|
||||||
await Prestamo.sync();
|
await Prestamo.sync();
|
||||||
console.log('La tabla Prestamo se instalo correctamente.'.magenta);
|
console.log('La tabla Prestamo se instalo correctamente.'.magenta);
|
||||||
|
|
||||||
@@ -114,7 +121,7 @@ const dataTipoUsuario = async () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const dataModulo = 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);
|
console.log('\nPaso 4) Insertando data modulo.'.bold.blue);
|
||||||
for (let i = 0; i < data.length; i++) {
|
for (let i = 0; i < data.length; i++) {
|
||||||
@@ -127,9 +134,9 @@ const dataModulo = async () => {
|
|||||||
|
|
||||||
const dataTipoCarrito = async () => {
|
const dataTipoCarrito = async () => {
|
||||||
const data = [
|
const data = [
|
||||||
{ tipo: 'Chromebook', letra: 'E' },
|
{ tipo: 'CHROMEBOOK', letra: 'E' },
|
||||||
{ tipo: 'Laptop', letra: 'L' },
|
{ tipo: 'LAP TOP', letra: 'L' },
|
||||||
{ tipo: 'iPad', letra: 'T' },
|
{ tipo: 'IPAD', letra: 'T' },
|
||||||
];
|
];
|
||||||
|
|
||||||
console.log('\nPaso 5) Insertando data tipo carrito.'.bold.blue);
|
console.log('\nPaso 5) Insertando data tipo carrito.'.bold.blue);
|
||||||
@@ -138,12 +145,22 @@ const dataTipoCarrito = async () => {
|
|||||||
tipoCarrito: data[i].tipo,
|
tipoCarrito: data[i].tipo,
|
||||||
letra: data[i].letra,
|
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 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);
|
console.log('\nPaso 6) Insertando data status.'.bold.blue);
|
||||||
for (let i = 0; i < data.length; i++) {
|
for (let i = 0; i < data.length; i++) {
|
||||||
@@ -155,7 +172,7 @@ const dataStatus = async () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const dataPrograma = 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);
|
console.log('\nPaso 7) Insertando data programa.'.bold.blue);
|
||||||
for (let i = 0; i < data.length; i++) {
|
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 () => {
|
const dataAdmin = async () => {
|
||||||
console.log('\nPaso 8) Insertando admin.'.bold.blue);
|
console.log('\nPaso 9) Insertando admin.'.bold.blue);
|
||||||
await Operador.create({
|
await Operador.create({
|
||||||
idTipoUsuario: 1,
|
idTipoUsuario: 1,
|
||||||
operador: 'Araceli',
|
operador: 'Araceli',
|
||||||
@@ -196,7 +222,7 @@ const dataInfraccion = async () => {
|
|||||||
// { infraccion: '', gravedad: '2' },
|
// { 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++) {
|
for (let i = 0; i < data.length; i++) {
|
||||||
await Infraccion.create({
|
await Infraccion.create({
|
||||||
infraccion: data[i].infraccion,
|
infraccion: data[i].infraccion,
|
||||||
@@ -207,15 +233,19 @@ const dataInfraccion = async () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const exe = async () => {
|
const exe = async () => {
|
||||||
await drop();
|
// await drop();
|
||||||
await sync();
|
// await sync();
|
||||||
await dataTipoUsuario();
|
// await dataTipoUsuario();
|
||||||
await dataModulo();
|
// await dataModulo();
|
||||||
await dataTipoCarrito();
|
// await dataTipoCarrito();
|
||||||
await dataStatus();
|
// await dataStatus();
|
||||||
await dataPrograma();
|
// await dataPrograma();
|
||||||
await dataAdmin();
|
// await dataSystem();
|
||||||
await dataInfraccion();
|
// await dataAdmin();
|
||||||
|
// await dataInfraccion();
|
||||||
|
|
||||||
|
await Motivo.sync();
|
||||||
|
console.log('La tabla Motivo se instalo correctamente.'.magenta);
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
'\nSe ha instalado exitosamente la base de datos.\n'.underline.bold.green
|
'\nSe ha instalado exitosamente la base de datos.\n'.underline.bold.green
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ Carrito.init(
|
|||||||
unique: true,
|
unique: true,
|
||||||
autoIncrement: true,
|
autoIncrement: true,
|
||||||
},
|
},
|
||||||
sobrenombre: {
|
carrito: {
|
||||||
type: DataTypes.STRING(4),
|
type: DataTypes.STRING(4),
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -14,6 +14,10 @@ Equipo.init(
|
|||||||
unique: true,
|
unique: true,
|
||||||
autoIncrement: true,
|
autoIncrement: true,
|
||||||
},
|
},
|
||||||
|
equipo: {
|
||||||
|
type: DataTypes.STRING(4),
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
numeroSerie: {
|
numeroSerie: {
|
||||||
type: DataTypes.STRING(15),
|
type: DataTypes.STRING(15),
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
@@ -22,16 +26,7 @@ Equipo.init(
|
|||||||
type: DataTypes.STRING(15),
|
type: DataTypes.STRING(15),
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
},
|
},
|
||||||
sobrenombre: {
|
prestado: {
|
||||||
type: DataTypes.STRING(4),
|
|
||||||
allowNull: false,
|
|
||||||
},
|
|
||||||
apartado: {
|
|
||||||
type: DataTypes.BOOLEAN,
|
|
||||||
allowNull: false,
|
|
||||||
defaultValue: false,
|
|
||||||
},
|
|
||||||
enUso: {
|
|
||||||
type: DataTypes.BOOLEAN,
|
type: DataTypes.BOOLEAN,
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
defaultValue: false,
|
defaultValue: false,
|
||||||
@@ -60,7 +55,7 @@ Equipo.belongsTo(Status, {
|
|||||||
name: 'idStatus',
|
name: 'idStatus',
|
||||||
type: DataTypes.INTEGER,
|
type: DataTypes.INTEGER,
|
||||||
allowNull: false,
|
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,
|
type: DataTypes.DATE,
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
},
|
},
|
||||||
|
// activo: {
|
||||||
|
// type: DataTypes.BOOLEAN,
|
||||||
|
// allowNull: false,
|
||||||
|
// defaultValue: true,
|
||||||
|
// },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
sequelize,
|
sequelize,
|
||||||
@@ -55,6 +60,7 @@ Multa.belongsTo(Operador, {
|
|||||||
name: 'idOperadorMulta',
|
name: 'idOperadorMulta',
|
||||||
type: DataTypes.INTEGER,
|
type: DataTypes.INTEGER,
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
|
defaultValue: 1,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -43,6 +43,16 @@ Prestamo.init(
|
|||||||
allowNull: true,
|
allowNull: true,
|
||||||
defaultValue: null,
|
defaultValue: null,
|
||||||
},
|
},
|
||||||
|
canceladoOperador: {
|
||||||
|
type: DataTypes.BOOLEAN,
|
||||||
|
allowNull: true,
|
||||||
|
defaultValue: null,
|
||||||
|
},
|
||||||
|
regresoInmediato: {
|
||||||
|
type: DataTypes.BOOLEAN,
|
||||||
|
allowNull: true,
|
||||||
|
defaultValue: null,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
sequelize,
|
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, {
|
Prestamo.belongsTo(Usuario, {
|
||||||
foreignKey: {
|
foreignKey: {
|
||||||
name: 'idUsuario',
|
name: 'idUsuario',
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ Programa.init(
|
|||||||
autoIncrement: true,
|
autoIncrement: true,
|
||||||
},
|
},
|
||||||
programa: {
|
programa: {
|
||||||
type: DataTypes.STRING(15),
|
type: DataTypes.STRING(20),
|
||||||
allowNull: false,
|
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 bcrypt = require('bcrypt');
|
||||||
const validar = require('./validar');
|
|
||||||
require('../config/config');
|
require('../config/config');
|
||||||
|
|
||||||
const comparar = (password, dbPassword) => {
|
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;
|
if (!bcrypt.compareSync(password, dbPassword)) return false;
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
const encriptar = (password) => {
|
const encriptar = (password) =>
|
||||||
let campo = 'password';
|
bcrypt.hashSync(password, Number(process.env.SALT_ROUNDS));
|
||||||
|
|
||||||
validar.noHay(password, campo);
|
|
||||||
if (typeof password != 'string') validar.noValido(campo);
|
|
||||||
return bcrypt.hashSync(password, Number(process.env.SALT_ROUNDS));
|
|
||||||
};
|
|
||||||
|
|
||||||
const generarPassword = () => {
|
const generarPassword = () => {
|
||||||
let length = 8;
|
const length = 8;
|
||||||
let charset =
|
const charset =
|
||||||
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
||||||
let password = '';
|
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,
|
pass: process.env.GMAILPASSWORD,
|
||||||
});
|
});
|
||||||
|
|
||||||
const gmail = (subject, to, text) => {
|
const gmail = (subject, to, html) => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
send({ subject, to, text }, (error, result, fullResult) => {
|
send({ subject, to, html }, (error, result, fullResult) => {
|
||||||
if (error) reject(error);
|
if (error) reject(error);
|
||||||
resolve(result);
|
resolve(result);
|
||||||
});
|
});
|
||||||
|
|||||||
+2
-15
@@ -1,22 +1,10 @@
|
|||||||
const fs = require('fs');
|
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) => {
|
const eliminarArchivo = (path) => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
fs.unlink(path, (err) => {
|
fs.unlink(path, (err) => {
|
||||||
if (err) reject(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) => {
|
return new Promise((resolve, reject) => {
|
||||||
fs.appendFile(path, texto, (err) => {
|
fs.appendFile(path, texto, (err) => {
|
||||||
if (err) reject(err);
|
if (err) reject(err);
|
||||||
resolve({ message: 'Se creo el archivo correctamente.' });
|
resolve({ message: 'Se creó el archivo correctamente.' });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
crearDDMMAAAA,
|
|
||||||
eliminarArchivo,
|
eliminarArchivo,
|
||||||
crearArchivo,
|
crearArchivo,
|
||||||
};
|
};
|
||||||
|
|||||||
+131
-94
@@ -1,58 +1,26 @@
|
|||||||
const moment = require('moment');
|
const moment = require('moment');
|
||||||
const validator = require('validator');
|
const validator = require('validator');
|
||||||
|
|
||||||
const noValido = (campo) => {
|
// Caractéres especiales permitidos en una string
|
||||||
throw new Error(`${campo} no es valido.`);
|
const caracterEspecial = (char) => {
|
||||||
};
|
|
||||||
|
|
||||||
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) => {
|
|
||||||
const charset = [
|
const charset = [
|
||||||
' ',
|
' ',
|
||||||
'.',
|
'.',
|
||||||
'-',
|
|
||||||
',',
|
',',
|
||||||
'/',
|
|
||||||
'#',
|
|
||||||
'?',
|
|
||||||
'¿',
|
|
||||||
':',
|
':',
|
||||||
';',
|
';',
|
||||||
|
'?',
|
||||||
|
'¿',
|
||||||
|
'!',
|
||||||
|
'¡',
|
||||||
|
'(',
|
||||||
|
')',
|
||||||
'"',
|
'"',
|
||||||
"'",
|
"'",
|
||||||
|
'-',
|
||||||
'_',
|
'_',
|
||||||
|
'/',
|
||||||
|
'#',
|
||||||
'%',
|
'%',
|
||||||
'\n',
|
'\n',
|
||||||
];
|
];
|
||||||
@@ -61,87 +29,156 @@ const caracteresEspeciales = (char) => {
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
const validarTexto = (texto, campo, length) => {
|
const yaExiste = (campo, m) => {
|
||||||
noHay(texto, campo);
|
throw new Error(`Ya se encuentra en uso ${m ? 'el' : 'la'} ${campo}.`);
|
||||||
if (typeof texto !== 'string' || texto.length > length) noValido(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++) {
|
for (let i = 0; i < texto.length; i++) {
|
||||||
if (caracteresEspeciales(texto[i])) continue;
|
if (caracterEspecial(texto[i])) continue;
|
||||||
if (!validator.isAlpha(texto[i], 'es-ES')) noValido(campo);
|
if (!validator.isAlphanumeric(texto[i], 'es-ES'))
|
||||||
|
noValido(campo, m, 'contiene caracteres no validos');
|
||||||
}
|
}
|
||||||
return texto;
|
return texto;
|
||||||
};
|
};
|
||||||
|
|
||||||
const validarAlfanumerico = (texto, campo, length) => {
|
/*
|
||||||
noHay(texto, campo);
|
Valida que la string sea un número menor a 9 dígitos.
|
||||||
if (typeof texto !== 'string' || texto.length > length) noValido(campo);
|
*/
|
||||||
for (let i = 0; i < texto.length; i++) {
|
const validarNumeroCuenta = (
|
||||||
if (caracteresEspeciales(texto[i])) continue;
|
numeroCuenta,
|
||||||
if (!validator.isAlphanumeric(texto[i], 'es-ES')) noValido(campo);
|
campo = 'numero de cuenta',
|
||||||
}
|
m = true
|
||||||
return texto;
|
) => {
|
||||||
};
|
validacionBasicaStr(numeroCuenta, campo, m, 9);
|
||||||
|
if (!validator.isNumeric(numeroCuenta, { no_symbols: true }))
|
||||||
const validarNumeroCuenta = (numeroCuenta) => {
|
noValido(campo, m, 'tiene caracteres que nos son números');
|
||||||
let campo = 'El numero de cuenta';
|
|
||||||
|
|
||||||
noHay(numeroCuenta, campo);
|
|
||||||
if (
|
|
||||||
typeof numeroCuenta !== 'string' ||
|
|
||||||
!validator.isNumeric(numeroCuenta, { no_symbols: true }) ||
|
|
||||||
numeroCuenta.length > 9
|
|
||||||
)
|
|
||||||
noValido(campo);
|
|
||||||
return numeroCuenta;
|
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);
|
let fechaMoment = moment(fecha);
|
||||||
|
|
||||||
noHay(fecha, campo);
|
noHay(fecha, campo, m);
|
||||||
if (!fechaMoment.isValid()) noValido(campo);
|
if (!fechaMoment.isValid()) noValido(campo, m, 'no es una fecha válida');
|
||||||
return fechaMoment;
|
return fechaMoment;
|
||||||
};
|
};
|
||||||
|
|
||||||
const validarNumero = (numero, makeNumber = false, length) => {
|
/*
|
||||||
let campo = 'El numero';
|
Valida que una string contenga solo números
|
||||||
|
*/
|
||||||
noHay(numero, campo);
|
const validarNumero = (
|
||||||
if (
|
numero,
|
||||||
typeof numero !== 'string' ||
|
campo,
|
||||||
!validator.isNumeric(numero, { no_symbols: true }) ||
|
m,
|
||||||
(length && numero.length > length)
|
length,
|
||||||
)
|
no_symbols = true,
|
||||||
noValido(campo);
|
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);
|
if (makeNumber) return Number(numero);
|
||||||
return numero;
|
return numero;
|
||||||
};
|
};
|
||||||
|
|
||||||
const validarAccesibilidad = (usuariosValidos = [], idTipoUsuario) => {
|
// const validarAccesibilidad = (usuariosValidos = [], idTipoUsuario) => {
|
||||||
for (let i = 0; i < usuariosValidos.length; i++)
|
// for (let i = 0; i < usuariosValidos.length; i++)
|
||||||
if (idTipoUsuario === usuariosValidos[i]) return;
|
// if (idTipoUsuario === usuariosValidos[i]) return;
|
||||||
throw new Error('Este usuario no tiene permitido usar esta linea de la API.');
|
// 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) => {
|
const validarObjetoVacio = (obj) => {
|
||||||
for (let key in obj) {
|
for (let key in obj) if (obj.hasOwnProperty(key)) return false;
|
||||||
if (obj.hasOwnProperty(key)) return false;
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
validar,
|
|
||||||
noValido,
|
|
||||||
yaExiste,
|
yaExiste,
|
||||||
|
noValido,
|
||||||
noHay,
|
noHay,
|
||||||
|
validacionBasicaStr,
|
||||||
|
validarNumeroEntero,
|
||||||
validarCorreo,
|
validarCorreo,
|
||||||
validarId,
|
|
||||||
validarTexto,
|
validarTexto,
|
||||||
validarAlfanumerico,
|
validarAlfanumerico,
|
||||||
validarNumeroCuenta,
|
validarNumeroCuenta,
|
||||||
validarFecha,
|
validarFecha,
|
||||||
validarNumero,
|
validarNumero,
|
||||||
validarAccesibilidad,
|
|
||||||
validarObjetoVacio,
|
validarObjetoVacio,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ const verificaToken = (req, res, next) => {
|
|||||||
let message = '';
|
let message = '';
|
||||||
|
|
||||||
if (err.message === 'invalid signature')
|
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')
|
if (err.message === 'jwt expired')
|
||||||
message = 'El token expiro. Inicia sesión de nuevo.';
|
message = 'El token expiro. Inicia sesión de nuevo.';
|
||||||
if (err.message === 'jwt malformed')
|
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`);
|
const update = require(`${controllerPath}/update`);
|
||||||
|
|
||||||
// PUT
|
// PUT
|
||||||
app.put(`${route}/update`, (req, res) => {
|
app.put(`${route}/update`, verificaToken, (req, res) => {
|
||||||
return update(req.body)
|
return update(req.body)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
res.status(200).json(data);
|
res.status(200).json(data);
|
||||||
@@ -20,7 +20,7 @@ app.put(`${route}/update`, (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
//GET
|
//GET
|
||||||
app.get(`${route}/`, (req, res) => {
|
app.get(`${route}/`, verificaToken, (req, res) => {
|
||||||
return carrito(req.query)
|
return carrito(req.query)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
res.status(200).json(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)
|
return carritos(req.query)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
res.status(200).json(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)
|
return equiposCarrito(req.query)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
res.status(200).json(data);
|
res.status(200).json(data);
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ const update = require(`${controllerPath}/update`);
|
|||||||
// POST
|
// POST
|
||||||
app.post(
|
app.post(
|
||||||
`${route}/carga_masiva`,
|
`${route}/carga_masiva`,
|
||||||
// verificaToken,
|
verificaToken,
|
||||||
upload.single('csv'),
|
upload.single('csv'),
|
||||||
(req, res) => {
|
(req, res) => {
|
||||||
if (req.file) {
|
if (req.file) {
|
||||||
@@ -32,7 +32,7 @@ app.post(
|
|||||||
);
|
);
|
||||||
|
|
||||||
// PUT
|
// PUT
|
||||||
app.put(`${route}/update`, (req, res) => {
|
app.put(`${route}/update`, verificaToken, (req, res) => {
|
||||||
return update(req.body)
|
return update(req.body)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
res.status(200).json(data);
|
res.status(200).json(data);
|
||||||
@@ -43,7 +43,7 @@ app.put(`${route}/update`, (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
//GET
|
//GET
|
||||||
app.get(`${route}/`, (req, res) => {
|
app.get(`${route}/`, verificaToken, (req, res) => {
|
||||||
return equipo(req.query)
|
return equipo(req.query)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
res.status(200).json(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)
|
return equipos(req.query)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
res.status(200).json(data);
|
res.status(200).json(data);
|
||||||
|
|||||||
@@ -4,18 +4,14 @@ const { verificaToken } = require('../middleware/autentificacion');
|
|||||||
const route = '/infraccion';
|
const route = '/infraccion';
|
||||||
const get = require('../controller/Infraccion/get');
|
const get = require('../controller/Infraccion/get');
|
||||||
|
|
||||||
app.get(
|
app.get(`${route}`, verificaToken, (req, res) => {
|
||||||
`${route}`,
|
return get()
|
||||||
//verificaToken,
|
.then((data) => {
|
||||||
(req, res) => {
|
res.status(200).json(data);
|
||||||
return get()
|
})
|
||||||
.then((data) => {
|
.catch((err) => {
|
||||||
res.status(200).json(data);
|
res.status(400).json({ message: err.message });
|
||||||
})
|
});
|
||||||
.catch((err) => {
|
});
|
||||||
res.status(400).json({ message: err.message });
|
|
||||||
});
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
module.exports = app;
|
module.exports = app;
|
||||||
|
|||||||
+9
-14
@@ -1,21 +1,16 @@
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
const app = express();
|
const app = express();
|
||||||
const { verificaToken } = require('../middleware/autentificacion');
|
|
||||||
const route = '/modulo';
|
const route = '/modulo';
|
||||||
const get = require('../controller/Modulo/get');
|
const get = require('../controller/Modulo/get');
|
||||||
|
|
||||||
app.get(
|
app.get(`${route}`, (req, res) => {
|
||||||
`${route}`,
|
return get()
|
||||||
// verificaToken,
|
.then((data) => {
|
||||||
(req, res) => {
|
res.status(200).json(data);
|
||||||
return get()
|
})
|
||||||
.then((data) => {
|
.catch((err) => {
|
||||||
res.status(200).json(data);
|
res.status(400).json({ message: err.message });
|
||||||
})
|
});
|
||||||
.catch((err) => {
|
});
|
||||||
res.status(400).json({ message: err.message });
|
|
||||||
});
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
module.exports = app;
|
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 historialMultasEquipo = require('../controller/Multa/historialMultasEquipo');
|
||||||
const historialMultasUsuario = require('../controller/Multa/historialMultasUsuario');
|
const historialMultasUsuario = require('../controller/Multa/historialMultasUsuario');
|
||||||
const multar = require('../controller/Multa/multar');
|
const multar = require('../controller/Multa/multar');
|
||||||
|
const multarIdPrestamo = require('../controller/Multa/multarIdPrestamo');
|
||||||
const multarNumeroInventario = require('../controller/Multa/multarNumeroInventario');
|
const multarNumeroInventario = require('../controller/Multa/multarNumeroInventario');
|
||||||
|
|
||||||
app.post(
|
app.post(`${route}/multar`, verificaToken, (req, res) => {
|
||||||
`${route}/multar`,
|
return multar(req.body)
|
||||||
//verificaToken,
|
.then((data) => {
|
||||||
(req, res) => {
|
res.status(200).json(data);
|
||||||
return multar(req.body)
|
})
|
||||||
.then((data) => {
|
.catch((err) => {
|
||||||
res.status(200).json(data);
|
res.status(400).json({ message: err.message });
|
||||||
})
|
});
|
||||||
.catch((err) => {
|
});
|
||||||
res.status(400).json({ message: err.message });
|
|
||||||
});
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
app.post(
|
app.post(`${route}/multar_id_prestamo`, verificaToken, (req, res) => {
|
||||||
`${route}/multar_numero_inventario`,
|
return multarIdPrestamo(req.body)
|
||||||
//verificaToken,
|
.then((data) => {
|
||||||
(req, res) => {
|
res.status(200).json(data);
|
||||||
return multarNumeroInventario(req.body)
|
})
|
||||||
.then((data) => {
|
.catch((err) => {
|
||||||
res.status(200).json(data);
|
res.status(400).json({ message: err.message });
|
||||||
})
|
});
|
||||||
.catch((err) => {
|
});
|
||||||
res.status(400).json({ message: err.message });
|
|
||||||
});
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
app.get(
|
app.post(`${route}/multar_numero_inventario`, verificaToken, (req, res) => {
|
||||||
`${route}/historial_multas_usuario`,
|
return multarNumeroInventario(req.body)
|
||||||
//verificaToken,
|
.then((data) => {
|
||||||
(req, res) => {
|
res.status(200).json(data);
|
||||||
return historialMultasUsuario(req.query)
|
})
|
||||||
.then((data) => {
|
.catch((err) => {
|
||||||
res.status(200).json(data);
|
res.status(400).json({ message: err.message });
|
||||||
})
|
});
|
||||||
.catch((err) => {
|
});
|
||||||
res.status(400).json({ message: err.message });
|
|
||||||
});
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
app.get(
|
app.get(`${route}/historial_multas_usuario`, verificaToken, (req, res) => {
|
||||||
`${route}/historial_multas_equipo`,
|
return historialMultasUsuario(req.query)
|
||||||
//verificaToken,
|
.then((data) => {
|
||||||
(req, res) => {
|
res.status(200).json(data);
|
||||||
return historialMultasEquipo(req.query)
|
})
|
||||||
.then((data) => {
|
.catch((err) => {
|
||||||
res.status(200).json(data);
|
res.status(400).json({ message: err.message });
|
||||||
})
|
});
|
||||||
.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;
|
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)
|
return crear(req.body)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
res.status(201).json(data);
|
res.status(201).json(data);
|
||||||
@@ -30,7 +30,7 @@ app.post(`${route}/crear`, (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// PUT
|
// PUT
|
||||||
app.put(`${route}/update`, (req, res) => {
|
app.put(`${route}/update`, verificaToken, (req, res) => {
|
||||||
return update(req.body)
|
return update(req.body)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
res.status(201).json(data);
|
res.status(201).json(data);
|
||||||
@@ -41,7 +41,7 @@ app.put(`${route}/update`, (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// GET
|
// GET
|
||||||
app.get(`${route}/operadores`, (req, res) => {
|
app.get(`${route}/operadores`, verificaToken, (req, res) => {
|
||||||
return operadores(req.query)
|
return operadores(req.query)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
res.status(201).json(data);
|
res.status(201).json(data);
|
||||||
|
|||||||
+170
-159
@@ -6,6 +6,7 @@ const controllerPath = '../controller/Prestamo';
|
|||||||
const activos = require(`${controllerPath}/activos`);
|
const activos = require(`${controllerPath}/activos`);
|
||||||
const cancelarOperador = require(`${controllerPath}/cancelarOperador`);
|
const cancelarOperador = require(`${controllerPath}/cancelarOperador`);
|
||||||
const cancelarUsuario = require(`${controllerPath}/cancelarUsuario`);
|
const cancelarUsuario = require(`${controllerPath}/cancelarUsuario`);
|
||||||
|
const diezMinutos = require(`${controllerPath}/diezMinutos`);
|
||||||
const historial = require(`${controllerPath}/historial`);
|
const historial = require(`${controllerPath}/historial`);
|
||||||
const historialEquipo = require(`${controllerPath}/historialEquipo`);
|
const historialEquipo = require(`${controllerPath}/historialEquipo`);
|
||||||
const historialUsuario = require(`${controllerPath}/historialUsuario`);
|
const historialUsuario = require(`${controllerPath}/historialUsuario`);
|
||||||
@@ -13,29 +14,71 @@ const pedir = require(`${controllerPath}/pedir`);
|
|||||||
const entregar = require(`${controllerPath}/entregar`);
|
const entregar = require(`${controllerPath}/entregar`);
|
||||||
const regresar = require(`${controllerPath}/regresar`);
|
const regresar = require(`${controllerPath}/regresar`);
|
||||||
const regresarNumeroInventario = require(`${controllerPath}/regresarNumeroInventario`);
|
const regresarNumeroInventario = require(`${controllerPath}/regresarNumeroInventario`);
|
||||||
|
const regresoInmediato = require(`${controllerPath}/regresoInmediato`);
|
||||||
|
const regresoInmediatoNumeroInventario = require(`${controllerPath}/regresoInmediatoNumeroInventario`);
|
||||||
const prestamo = require(`${controllerPath}/prestamo`);
|
const prestamo = require(`${controllerPath}/prestamo`);
|
||||||
|
const prestamoNumeroInventario = require(`${controllerPath}/prestamoNumeroInventario`);
|
||||||
const prestamoUsuario = require(`${controllerPath}/prestamoUsuario`);
|
const prestamoUsuario = require(`${controllerPath}/prestamoUsuario`);
|
||||||
|
const reporte = require(`${controllerPath}/reporte`);
|
||||||
const status = require(`${controllerPath}/status`);
|
const status = require(`${controllerPath}/status`);
|
||||||
|
|
||||||
app.post(
|
// POST
|
||||||
`${route}/pedir`,
|
app.post(`${route}/pedir`, verificaToken, (req, res) => {
|
||||||
// verificaToken,
|
return pedir(req.body)
|
||||||
(req, res) => {
|
.then((data) => {
|
||||||
return pedir(req.body)
|
res.status(200).json(data);
|
||||||
.then((data) => {
|
})
|
||||||
res.status(200).json(data);
|
.catch((err) => {
|
||||||
})
|
res.status(400).json({ message: err.message });
|
||||||
.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(
|
app.put(
|
||||||
`${route}/entregar`,
|
`${route}/regreso_inmediato_numero_inventario`,
|
||||||
// verificaToken,
|
verificaToken,
|
||||||
(req, res) => {
|
(req, res) => {
|
||||||
return entregar(req.body)
|
return regresoInmediatoNumeroInventario(req.body)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
res.status(200).json(data);
|
res.status(200).json(data);
|
||||||
})
|
})
|
||||||
@@ -45,158 +88,126 @@ app.put(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
app.put(
|
app.put(`${route}/cancelar_usuario`, verificaToken, (req, res) => {
|
||||||
`${route}/regresar`,
|
req.body.idUsuario = req.decoded.data.idUsuario;
|
||||||
// verificaToken,
|
return cancelarUsuario(req.body)
|
||||||
(req, res) => {
|
.then((data) => {
|
||||||
return regresar(req.body)
|
res.status(200).json(data);
|
||||||
.then((data) => {
|
})
|
||||||
res.status(200).json(data);
|
.catch((err) => {
|
||||||
})
|
res.status(400).json({ message: err.message });
|
||||||
.catch((err) => {
|
});
|
||||||
res.status(400).json({ message: err.message });
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
app.put(
|
app.put(`${route}/cancelar_operador`, verificaToken, (req, res) => {
|
||||||
`${route}/regresar_numero_inventario`,
|
return cancelarOperador(req.body)
|
||||||
// verificaToken,
|
.then((data) => {
|
||||||
(req, res) => {
|
res.status(200).json(data);
|
||||||
return regresarNumeroInventario(req.body)
|
})
|
||||||
.then((data) => {
|
.catch((err) => {
|
||||||
res.status(200).json(data);
|
res.status(400).json({ message: err.message });
|
||||||
})
|
});
|
||||||
.catch((err) => {
|
});
|
||||||
res.status(400).json({ message: err.message });
|
|
||||||
});
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
app.put(
|
// GET
|
||||||
`${route}/cancelar_usuario`,
|
app.get(`${route}/activos`, verificaToken, (req, res) => {
|
||||||
// verificaToken,
|
return activos(req.query)
|
||||||
(req, res) => {
|
.then((data) => {
|
||||||
return cancelarUsuario(req.body)
|
res.status(200).json(data);
|
||||||
.then((data) => {
|
})
|
||||||
res.status(200).json(data);
|
.catch((err) => {
|
||||||
})
|
res.status(400).json({ message: err.message });
|
||||||
.catch((err) => {
|
});
|
||||||
res.status(400).json({ message: err.message });
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
app.put(
|
app.get(`${route}/diez_minutos`, verificaToken, (req, res) => {
|
||||||
`${route}/cancelar_operador`,
|
return diezMinutos(req.query)
|
||||||
// verificaToken,
|
.then((data) => {
|
||||||
(req, res) => {
|
res.status(200).json(data);
|
||||||
return cancelarOperador(req.body)
|
})
|
||||||
.then((data) => {
|
.catch((err) => {
|
||||||
res.status(200).json(data);
|
res.status(400).json({ message: err.message });
|
||||||
})
|
});
|
||||||
.catch((err) => {
|
});
|
||||||
res.status(400).json({ message: err.message });
|
|
||||||
});
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
app.get(
|
app.get(`${route}/historial`, verificaToken, (req, res) => {
|
||||||
`${route}/activos`,
|
return historial(req.query)
|
||||||
// verificaToken,
|
.then((data) => {
|
||||||
(req, res) => {
|
res.status(200).json(data);
|
||||||
return activos(req.query)
|
})
|
||||||
.then((data) => {
|
.catch((err) => {
|
||||||
res.status(200).json(data);
|
res.status(400).json({ message: err.message });
|
||||||
})
|
});
|
||||||
.catch((err) => {
|
});
|
||||||
res.status(400).json({ message: err.message });
|
|
||||||
});
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
app.get(
|
app.get(`${route}/historial_equipo`, verificaToken, (req, res) => {
|
||||||
`${route}/historial`,
|
return historialEquipo(req.query)
|
||||||
// verificaToken,
|
.then((data) => {
|
||||||
(req, res) => {
|
res.status(200).json(data);
|
||||||
return historial(req.query)
|
})
|
||||||
.then((data) => {
|
.catch((err) => {
|
||||||
res.status(200).json(data);
|
res.status(400).json({ message: err.message });
|
||||||
})
|
});
|
||||||
.catch((err) => {
|
});
|
||||||
res.status(400).json({ message: err.message });
|
|
||||||
});
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
app.get(
|
app.get(`${route}/historial_usuario`, verificaToken, (req, res) => {
|
||||||
`${route}/historial_equipo`,
|
return historialUsuario(req.query)
|
||||||
// verificaToken,
|
.then((data) => {
|
||||||
(req, res) => {
|
res.status(200).json(data);
|
||||||
return historialEquipo(req.query)
|
})
|
||||||
.then((data) => {
|
.catch((err) => {
|
||||||
res.status(200).json(data);
|
res.status(400).json({ message: err.message });
|
||||||
})
|
});
|
||||||
.catch((err) => {
|
});
|
||||||
res.status(400).json({ message: err.message });
|
|
||||||
});
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
app.get(
|
app.get(`${route}`, verificaToken, (req, res) => {
|
||||||
`${route}/historial_usuario`,
|
return prestamo(req.query)
|
||||||
// verificaToken,
|
.then((data) => {
|
||||||
(req, res) => {
|
res.status(200).json(data);
|
||||||
return historialUsuario(req.query)
|
})
|
||||||
.then((data) => {
|
.catch((err) => {
|
||||||
res.status(200).json(data);
|
res.status(400).json({ message: err.message });
|
||||||
})
|
});
|
||||||
.catch((err) => {
|
});
|
||||||
res.status(400).json({ message: err.message });
|
|
||||||
});
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
app.get(
|
app.get(`${route}/prestamo_numero_inventario`, verificaToken, (req, res) => {
|
||||||
`${route}`,
|
return prestamoNumeroInventario(req.query)
|
||||||
// verificaToken,
|
.then((data) => {
|
||||||
(req, res) => {
|
res.status(200).json(data);
|
||||||
return prestamo(req.query)
|
})
|
||||||
.then((data) => {
|
.catch((err) => {
|
||||||
res.status(200).json(data);
|
res.status(400).json({ message: err.message });
|
||||||
})
|
});
|
||||||
.catch((err) => {
|
});
|
||||||
res.status(400).json({ message: err.message });
|
|
||||||
});
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
app.get(
|
app.get(`${route}/prestamo_usuario`, verificaToken, (req, res) => {
|
||||||
`${route}/prestamo_usuario`,
|
return prestamoUsuario(req.query)
|
||||||
// verificaToken,
|
.then((data) => {
|
||||||
(req, res) => {
|
res.status(200).json(data);
|
||||||
return prestamoUsuario(req.query)
|
})
|
||||||
.then((data) => {
|
.catch((err) => {
|
||||||
res.status(200).json(data);
|
res.status(400).json({ message: err.message });
|
||||||
})
|
});
|
||||||
.catch((err) => {
|
});
|
||||||
res.status(400).json({ message: err.message });
|
|
||||||
});
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
app.get(
|
app.get(`${route}/reporte`, verificaToken, (req, res) => {
|
||||||
`${route}/status`,
|
return reporte(req.query)
|
||||||
// verificaToken,
|
.then((data) => {
|
||||||
(req, res) => {
|
res.download(data);
|
||||||
return status(req.query)
|
})
|
||||||
.then((data) => {
|
.catch((err) => {
|
||||||
res.status(200).json(data);
|
res.status(400).json({ message: err.message });
|
||||||
})
|
});
|
||||||
.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;
|
module.exports = app;
|
||||||
|
|||||||
@@ -4,18 +4,14 @@ const { verificaToken } = require('../middleware/autentificacion');
|
|||||||
const route = '/programa';
|
const route = '/programa';
|
||||||
const get = require('../controller/Programa/get');
|
const get = require('../controller/Programa/get');
|
||||||
|
|
||||||
app.get(
|
app.get(`${route}`, verificaToken, (req, res) => {
|
||||||
`${route}`,
|
return get()
|
||||||
//verificaToken,
|
.then((data) => {
|
||||||
(req, res) => {
|
res.status(200).json(data);
|
||||||
return get()
|
})
|
||||||
.then((data) => {
|
.catch((err) => {
|
||||||
res.status(200).json(data);
|
res.status(400).json({ message: err.message });
|
||||||
})
|
});
|
||||||
.catch((err) => {
|
});
|
||||||
res.status(400).json({ message: err.message });
|
|
||||||
});
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
module.exports = app;
|
module.exports = app;
|
||||||
|
|||||||
+9
-13
@@ -4,18 +4,14 @@ const { verificaToken } = require('../middleware/autentificacion');
|
|||||||
const route = '/status';
|
const route = '/status';
|
||||||
const get = require('../controller/Status/get');
|
const get = require('../controller/Status/get');
|
||||||
|
|
||||||
app.get(
|
app.get(`${route}`, verificaToken, (req, res) => {
|
||||||
`${route}`,
|
return get()
|
||||||
//verificaToken,
|
.then((data) => {
|
||||||
(req, res) => {
|
res.status(200).json(data);
|
||||||
return get()
|
})
|
||||||
.then((data) => {
|
.catch((err) => {
|
||||||
res.status(200).json(data);
|
res.status(400).json({ message: err.message });
|
||||||
})
|
});
|
||||||
.catch((err) => {
|
});
|
||||||
res.status(400).json({ message: err.message });
|
|
||||||
});
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
module.exports = app;
|
module.exports = app;
|
||||||
|
|||||||
@@ -4,18 +4,14 @@ const { verificaToken } = require('../middleware/autentificacion');
|
|||||||
const route = '/tipo_carrito';
|
const route = '/tipo_carrito';
|
||||||
const get = require('../controller/TipoCarrito/get');
|
const get = require('../controller/TipoCarrito/get');
|
||||||
|
|
||||||
app.get(
|
app.get(`${route}`, verificaToken, (req, res) => {
|
||||||
`${route}`,
|
return get()
|
||||||
//verificaToken,
|
.then((data) => {
|
||||||
(req, res) => {
|
res.status(200).json(data);
|
||||||
return get()
|
})
|
||||||
.then((data) => {
|
.catch((err) => {
|
||||||
res.status(200).json(data);
|
res.status(400).json({ message: err.message });
|
||||||
})
|
});
|
||||||
.catch((err) => {
|
});
|
||||||
res.status(400).json({ message: err.message });
|
|
||||||
});
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
module.exports = app;
|
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 { verificaToken } = require('../middleware/autentificacion');
|
||||||
const route = '/usuario';
|
const route = '/usuario';
|
||||||
const controllerPath = '../controller/Usuario';
|
const controllerPath = '../controller/Usuario';
|
||||||
const cargaMasivaPosgrados = require(`${controllerPath}/cargaMasivaPosgrados`);
|
const cargaMasiva = require(`${controllerPath}/cargaMasiva`);
|
||||||
const crear = require(`${controllerPath}/crear`);
|
const crear = require(`${controllerPath}/crear`);
|
||||||
const escolares = require(`${controllerPath}/escolares`);
|
const escolares = require(`${controllerPath}/escolares`);
|
||||||
const login = require(`${controllerPath}/login`);
|
const login = require(`${controllerPath}/login`);
|
||||||
@@ -15,11 +15,11 @@ const usuarios = require(`${controllerPath}/usuarios`);
|
|||||||
|
|
||||||
app.post(
|
app.post(
|
||||||
`${route}/carga_masiva_posgrado`,
|
`${route}/carga_masiva_posgrado`,
|
||||||
// verificaToken,
|
verificaToken,
|
||||||
upload.single('csv'),
|
upload.single('csv'),
|
||||||
(req, res) => {
|
(req, res) => {
|
||||||
if (req.file) {
|
if (req.file) {
|
||||||
return cargaMasivaPosgrados(req.file.filename)
|
return cargaMasiva(req.file.filename)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
res.status(201).json(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)
|
return quitarMulta(req.body)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
res.status(200).json(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)
|
return usuario(req.query)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
res.status(200).json(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)
|
return usuarios(req.query)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
res.status(200).json(data);
|
res.status(200).json(data);
|
||||||
|
|||||||
@@ -1,16 +1,19 @@
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
|
app.use(require('./Carrera'));
|
||||||
app.use(require('./Carrito'));
|
app.use(require('./Carrito'));
|
||||||
app.use(require('./Equipo'));
|
app.use(require('./Equipo'));
|
||||||
app.use(require('./Infraccion'));
|
app.use(require('./Infraccion'));
|
||||||
app.use(require('./Modulo'));
|
app.use(require('./Modulo'));
|
||||||
|
app.use(require('./Motivo'));
|
||||||
app.use(require('./Multa'));
|
app.use(require('./Multa'));
|
||||||
app.use(require('./Operador'));
|
app.use(require('./Operador'));
|
||||||
app.use(require('./Prestamo'));
|
app.use(require('./Prestamo'));
|
||||||
app.use(require('./Programa'));
|
app.use(require('./Programa'));
|
||||||
app.use(require('./Status'));
|
app.use(require('./Status'));
|
||||||
app.use(require('./TipoCarrito'));
|
app.use(require('./TipoCarrito'));
|
||||||
|
app.use(require('./TipoUsuario'));
|
||||||
app.use(require('./Usuario'));
|
app.use(require('./Usuario'));
|
||||||
|
|
||||||
module.exports = app;
|
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