script pasar db csv a nueva db
This commit is contained in:
@@ -2,3 +2,5 @@
|
||||
node_modules/
|
||||
cred.json
|
||||
server/uploads/*
|
||||
|
||||
*.csv
|
||||
Generated
+33
@@ -242,6 +242,11 @@
|
||||
"integrity": "sha512-1Yj8h9Q+QDF5FzhMs/c9+6UntbD5MkRfRwac8DoEm9ZfUBZ7tZ55YcGVAzEe4bXsdQHEk+s9S5wsOKVdZrw0tQ==",
|
||||
"dev": true
|
||||
},
|
||||
"bluebird": {
|
||||
"version": "3.7.2",
|
||||
"resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz",
|
||||
"integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg=="
|
||||
},
|
||||
"body-parser": {
|
||||
"version": "1.19.0",
|
||||
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.19.0.tgz",
|
||||
@@ -566,6 +571,11 @@
|
||||
"resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz",
|
||||
"integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA=="
|
||||
},
|
||||
"convert-array-to-csv": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/convert-array-to-csv/-/convert-array-to-csv-2.0.0.tgz",
|
||||
"integrity": "sha512-dxUINCt28k6WbXGMoB+AaKjGY0Y6GkKwZmT+kvD4nJgVCOKsnIQ3G6n0v2II1lG4NwXQk6EWZ+pPDub9wcqqMg=="
|
||||
},
|
||||
"cookie": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.0.tgz",
|
||||
@@ -596,6 +606,16 @@
|
||||
"integrity": "sha512-v1plID3y9r/lPhviJ1wrXpLeyUIGAZ2SHNYTEapm7/8A9nLPoyvVp3RK/EPFqn5kEznyWgYZNsRtYYIWbuG8KA==",
|
||||
"dev": true
|
||||
},
|
||||
"csvtojson": {
|
||||
"version": "2.0.10",
|
||||
"resolved": "https://registry.npmjs.org/csvtojson/-/csvtojson-2.0.10.tgz",
|
||||
"integrity": "sha512-lUWFxGKyhraKCW8Qghz6Z0f2l/PqB1W3AO0HKJzGIQ5JRSlR651ekJDiGJbBT4sRNNv5ddnSGVEnsxP9XRCVpQ==",
|
||||
"requires": {
|
||||
"bluebird": "^3.5.1",
|
||||
"lodash": "^4.17.3",
|
||||
"strip-bom": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"debug": {
|
||||
"version": "2.6.9",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
||||
@@ -1277,6 +1297,11 @@
|
||||
"integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo=",
|
||||
"dev": true
|
||||
},
|
||||
"is-utf8": {
|
||||
"version": "0.2.1",
|
||||
"resolved": "https://registry.npmjs.org/is-utf8/-/is-utf8-0.2.1.tgz",
|
||||
"integrity": "sha1-Sw2hRCEE0bM2NA6AeX6GXPOffXI="
|
||||
},
|
||||
"is-yarn-global": {
|
||||
"version": "0.3.0",
|
||||
"resolved": "https://registry.npmjs.org/is-yarn-global/-/is-yarn-global-0.3.0.tgz",
|
||||
@@ -2219,6 +2244,14 @@
|
||||
"ansi-regex": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"strip-bom": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-2.0.0.tgz",
|
||||
"integrity": "sha1-YhmoVhZSBJHzV4i9vxRHqZx+aw4=",
|
||||
"requires": {
|
||||
"is-utf8": "^0.2.0"
|
||||
}
|
||||
},
|
||||
"strip-json-comments": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz",
|
||||
|
||||
@@ -21,7 +21,9 @@
|
||||
"bcrypt": "^5.0.0",
|
||||
"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",
|
||||
"express": "^4.17.1",
|
||||
"gmail-send": "^1.8.10",
|
||||
|
||||
@@ -0,0 +1,201 @@
|
||||
const csv = require('csvtojson');
|
||||
const Carrera = require('./tablas/Carrera');
|
||||
const CuestionarioAlumno = require('./tablas/CuestionarioAlumno');
|
||||
const CuestionarioPrograma = require('./tablas/CuestionarioPrograma');
|
||||
const Programa = require('./tablas/Programa');
|
||||
const Servicio = require('./tablas/Servicio');
|
||||
const Status = require('./tablas/Status');
|
||||
const TipoUsuario = require('./tablas/TipoUsuario');
|
||||
const Usuario = require('./tablas/Usuario');
|
||||
|
||||
const guardar = async () => {
|
||||
let idsProgramas = [];
|
||||
let idsAlumnos = [];
|
||||
let responsables = await csv()
|
||||
.fromFile('responsable.csv')
|
||||
.then((res) => res);
|
||||
let programas = await csv()
|
||||
.fromFile('programa.csv')
|
||||
.then((res) => res);
|
||||
let alumnos = await csv()
|
||||
.fromFile('alumno.csv')
|
||||
.then((res) => res);
|
||||
let registros = await csv()
|
||||
.fromFile('registro.csv')
|
||||
.then((res) => res);
|
||||
|
||||
for (let i = 0; i < responsables.length; i++) {
|
||||
await Usuario.create({
|
||||
idTipoUsuario: 2,
|
||||
usuario: responsables[i].correo,
|
||||
password: responsables[i].password,
|
||||
nombre: responsables[i].nombreResp,
|
||||
activo: true,
|
||||
})
|
||||
.then(async (res) => {
|
||||
console.log(
|
||||
`Fila ${i}\nSe agrego correctamente al responsable ${res.dataValues.usuario}`
|
||||
);
|
||||
for (let j = 0; j < programas.length; j++) {
|
||||
if (responsables[i].idResponsable == programas[j].idResponsable) {
|
||||
await Programa.create({
|
||||
institucion: programas[j].institucion,
|
||||
dependencia: programas[j].dependencia,
|
||||
programa: programas[j].programa,
|
||||
clavePrograma: programas[j].clavePrograma,
|
||||
acatlan: responsables[i].acatlanContigo === 'true' ? true : false,
|
||||
activo: true,
|
||||
idUsuario: res.dataValues.idUsuario,
|
||||
})
|
||||
.then((res) => {
|
||||
console.log(
|
||||
`Se agrego correctamente el programa ${res.dataValues.programa}`
|
||||
);
|
||||
idsProgramas.push({
|
||||
nuevo: res.dataValues.idPrograma,
|
||||
viejo: programas[j].idPrograma,
|
||||
});
|
||||
programas.splice(j, 1);
|
||||
j--;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw err;
|
||||
});
|
||||
}
|
||||
}
|
||||
console.log('\n');
|
||||
})
|
||||
.catch((err) => {
|
||||
throw err;
|
||||
});
|
||||
}
|
||||
|
||||
for (let i = 0; i < alumnos.length; i++) {
|
||||
let nombre = '';
|
||||
let usuario = alumnos[i].idAlumno;
|
||||
|
||||
for (let j = 0; j < registros.length; j++) {
|
||||
if (alumnos[i].idAlumno === registros[j].idAlumno) {
|
||||
nombre = registros[j].nombre;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (alumnos[i].idAlumno.length === 8) usuario = '0' + usuario;
|
||||
await Usuario.create({
|
||||
idTipoUsuario: 3,
|
||||
usuario,
|
||||
password: alumnos[i].password ? alumnos[i].password : null,
|
||||
nombre,
|
||||
activo: alumnos[i].password ? true : false,
|
||||
})
|
||||
.then((res) => {
|
||||
idsAlumnos.push({
|
||||
nuevo: res.dataValues.idUsuario,
|
||||
viejo: alumnos[i].idAlumno,
|
||||
});
|
||||
console.log(
|
||||
`Se agrego correctamente al alumno ${res.dataValues.usuario}`
|
||||
);
|
||||
})
|
||||
.catch((err) => {
|
||||
throw err;
|
||||
});
|
||||
}
|
||||
|
||||
for (let i = 0; i < registros.length; i++) {
|
||||
let idUsuario;
|
||||
let idPrograma;
|
||||
let idStatus;
|
||||
let idCarrera = await Carrera.findOne({
|
||||
where: {
|
||||
carrera: registros[i].carrera,
|
||||
},
|
||||
})
|
||||
.then(async (res) => {
|
||||
if (!res) {
|
||||
return await Carrera.create({ carrera: registros[i].carrera })
|
||||
.then((res) => res.dataValues.idCarrera)
|
||||
.catch((err) => {
|
||||
throw err;
|
||||
});
|
||||
}
|
||||
return res.dataValues.idCarrera;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw err;
|
||||
});
|
||||
|
||||
for (let j = 0; j < idsAlumnos.length; j++)
|
||||
if (registros[i].idAlumno === idsAlumnos[j].viejo) {
|
||||
idUsuario = idsAlumnos[j].nuevo;
|
||||
break;
|
||||
}
|
||||
for (let j = 0; j < idsProgramas.length; j++)
|
||||
if (registros[i].idPrograma === idsProgramas[j].viejo) {
|
||||
idPrograma = idsProgramas[j].nuevo;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (registros[i].idStatus) {
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
case 6:
|
||||
idStatus = registros[i].idStatus;
|
||||
break;
|
||||
case 7:
|
||||
if (registros[i].cartaTermino || registros[i].informeGlobal)
|
||||
idStatus = 8;
|
||||
else idStatus = 7;
|
||||
break;
|
||||
case 8:
|
||||
idStatus = 10;
|
||||
break;
|
||||
}
|
||||
|
||||
await Servicio.create({
|
||||
creditos: registros[i].creditos,
|
||||
correo: registros[i].correo,
|
||||
fechaInicio: registros[i].fechaInicio,
|
||||
fechaFin: registros[i].fechaFin,
|
||||
cartaAceptacion: registros[i].cartaAceptacion,
|
||||
// carpeta: registros[i]., // hay que limpiar drive de carpetas de mas
|
||||
telefono: registros[i].telefono ? registros[i].telefono : null,
|
||||
direccion: registros[i].direccion ? registros[i].direccion : null,
|
||||
fechaNacimiento: registros[i].fechaNacimiento
|
||||
? registros[i].fechaNacimiento
|
||||
: null,
|
||||
cartaTermino: registros[i].cartaTermino
|
||||
? registros[i].cartaTermino
|
||||
: null,
|
||||
informeGlobal: registros[i].informeGlobal
|
||||
? registros[i].informeGlobal
|
||||
: null,
|
||||
programaInterno: registros[i].progInterno
|
||||
? registros[i].progInterno
|
||||
: null,
|
||||
profesor: registros[i].prof ? registros[i].prof : null,
|
||||
vistoBuenoAcatlan:
|
||||
registros[i].vistoBuenoAcatlan === 'true' ? true : null,
|
||||
idUsuario,
|
||||
idPrograma,
|
||||
idStatus,
|
||||
idCarrera,
|
||||
createdAt: registros[i].createdAt,
|
||||
updatedAt: registros[i].updatedAt,
|
||||
})
|
||||
.then((res) => {
|
||||
console.log(
|
||||
`Linea ${i}\nSe agrego correctamente el servico social del alumno ${res.dataValues.idUsuario} con numero de cuenta ${registros[i].idAlumno}`
|
||||
);
|
||||
})
|
||||
.catch((err) => {
|
||||
throw err;
|
||||
});
|
||||
console.log('\n');
|
||||
}
|
||||
};
|
||||
|
||||
guardar();
|
||||
@@ -1,3 +1,4 @@
|
||||
require('../config/config');
|
||||
const colors = require('colors');
|
||||
const encriptar = require('../helper/encriptar');
|
||||
const Carrera = require('./tablas/Carrera');
|
||||
@@ -105,11 +106,11 @@ const dataStatus = async () => {
|
||||
const dataAdmin = async () => {
|
||||
console.log('\nPaso 5) Instalando admin.'.bold.blue);
|
||||
await Usuario.create({
|
||||
usuario: 'admin',
|
||||
password: encriptar.encriptar('qwertyui'),
|
||||
usuario: process.env.ADMIN,
|
||||
password: encriptar.encriptar(process.env.ADMIN_PASSWORD),
|
||||
nombre: 'COESI',
|
||||
idTipoUsuario: 1,
|
||||
activo: true,
|
||||
nombre: 'COESI',
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ Servicio.init(
|
||||
allowNull: false,
|
||||
},
|
||||
telefono: {
|
||||
type: DataTypes.STRING(10),
|
||||
type: DataTypes.STRING(15),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
@@ -51,7 +51,10 @@ Servicio.init(
|
||||
},
|
||||
carpeta: {
|
||||
type: DataTypes.STRING(60),
|
||||
allowNull: false,
|
||||
// allowNull:false,
|
||||
allowNull: true,
|
||||
// comentar linea de abajo
|
||||
defaultValue: null,
|
||||
},
|
||||
cartaAceptacion: {
|
||||
type: DataTypes.STRING(60),
|
||||
@@ -68,7 +71,7 @@ Servicio.init(
|
||||
defaultValue: null,
|
||||
},
|
||||
programaInterno: {
|
||||
type: DataTypes.STRING(80),
|
||||
type: DataTypes.STRING(150),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
|
||||
@@ -22,7 +22,7 @@ Usuario.init(
|
||||
defaultValue: null,
|
||||
},
|
||||
nombre: {
|
||||
type: DataTypes.STRING(60),
|
||||
type: DataTypes.STRING(70),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user