excel primer semestre aparentemente listo
This commit is contained in:
+3
-1
@@ -2,4 +2,6 @@ node_modules/
|
||||
|
||||
.env
|
||||
|
||||
server/db/alumnos_segundo.csv
|
||||
server/db/alumnos_segundo.csv
|
||||
|
||||
server/uploads/*
|
||||
|
||||
Generated
+868
-36
File diff suppressed because it is too large
Load Diff
@@ -18,8 +18,10 @@
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"bcrypt": "^5.0.1",
|
||||
"body-parser": "^1.19.0",
|
||||
"colors": "^1.4.0",
|
||||
"convert-array-to-csv": "^2.0.0",
|
||||
"cors": "^2.8.5",
|
||||
"csvtojson": "^2.0.10",
|
||||
"dotenv": "^8.2.0",
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
const { convertArrayToCSV } = require('convert-array-to-csv');
|
||||
const moment = require('moment');
|
||||
const helperPath = '../../helper';
|
||||
const helper = require(`${helperPath}/helper`);
|
||||
const encriptar = require(`${helperPath}/encriptar`);
|
||||
const dbPath = '../../db/tablas';
|
||||
const Carrera = require(`${dbPath}/Carrera`);
|
||||
const Grupo = require(`${dbPath}/Grupo`);
|
||||
const Horario = require(`${dbPath}/Horario`);
|
||||
const PrimerSemestre = require(`${dbPath}/PrimerSemestre`);
|
||||
|
||||
const get = async (body) => {
|
||||
const path = `server/uploads/primer_semestre.csv`;
|
||||
const data = [];
|
||||
|
||||
if (!body.password) throw new Error('No hay contraseña.');
|
||||
if (
|
||||
!encriptar.comparar(
|
||||
body.password,
|
||||
'$2b$10$/yZZE6Ee8GEUgCmzCd/mWehpb94g74cmk6fDb52G4W0tQ9Py9M.Ia'
|
||||
)
|
||||
)
|
||||
throw new Error('Contraseña no valida.');
|
||||
return PrimerSemestre.findAll({
|
||||
include: [{ model: Grupo, include: [{ model: Carrera }] }],
|
||||
})
|
||||
.then(async (res) => {
|
||||
for (let i = 0; i < res.length; i++) {
|
||||
const horario = await Horario.findOne({
|
||||
where: { idHorario: res[i].idHorario },
|
||||
}).then((res) => moment(res.horario));
|
||||
|
||||
data.push({
|
||||
numeroCuenta: res[i].numeroCuenta,
|
||||
nombre: res[i].nombre,
|
||||
carrera: res[i].Grupo.Carrera.carrera,
|
||||
grupo: res[i].Grupo.grupo,
|
||||
horario: `${
|
||||
horario.date() < 10 ? '0' + horario.date() : horario.date()
|
||||
}/${
|
||||
horario.month() + 1 < 10
|
||||
? '0' + (horario.month() + 1)
|
||||
: horario.month() + 1
|
||||
}/${horario.year()} ${
|
||||
horario.hour() < 10 ? '0' + horario.hour() : horario.hour()
|
||||
}:${
|
||||
horario.minute() < 10 ? '0' + horario.minute() : horario.minute()
|
||||
}`,
|
||||
});
|
||||
}
|
||||
await helper.eliminarArchivo(path).catch((err) => {});
|
||||
return helper.crearArchivo(path, convertArrayToCSV(data));
|
||||
})
|
||||
.then((res) => path);
|
||||
};
|
||||
|
||||
module.exports = get;
|
||||
|
||||
get({ password: 'hola' });
|
||||
@@ -0,0 +1,34 @@
|
||||
const bcrypt = require('bcrypt');
|
||||
const validar = require('./validar');
|
||||
require('../config/config');
|
||||
|
||||
const comparar = (password, dbPassword) => {
|
||||
let campo = 'password';
|
||||
|
||||
validar.noHay(password, campo);
|
||||
if (typeof password != 'string') validar.noValido(campo);
|
||||
return bcrypt.compareSync(password, dbPassword);
|
||||
};
|
||||
|
||||
const encriptar = (password) => {
|
||||
let campo = 'password';
|
||||
|
||||
validar.noHay(password, campo);
|
||||
if (typeof password != 'string') validar.noValido(campo);
|
||||
return bcrypt.hashSync(password, Number(process.env.SALT_ROUNDS));
|
||||
};
|
||||
|
||||
const generarPassword = () => {
|
||||
let length = 8;
|
||||
let charset =
|
||||
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
||||
let password = '';
|
||||
|
||||
for (let i = 0, n = charset.length; i < length; ++i)
|
||||
password += charset.charAt(Math.floor(Math.random() * n));
|
||||
return password;
|
||||
};
|
||||
|
||||
module.exports = { comparar, encriptar, generarPassword };
|
||||
|
||||
// console.log(encriptar('hola'))
|
||||
@@ -15,4 +15,15 @@ app.post(`${route}/registrar`, (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
// GET
|
||||
app.get(`${route}`, verificaToken, (req, res) => {
|
||||
return get(req.query)
|
||||
.then((data) => {
|
||||
res.download(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = app;
|
||||
|
||||
Reference in New Issue
Block a user