From 766f79b9d118a62ebd1129bba8b543d43541b184 Mon Sep 17 00:00:00 2001 From: alfredojl Date: Tue, 6 Oct 2020 19:56:55 -0500 Subject: [PATCH 1/2] . --- helpers/tables/UResponsable.js | 7 +- helpers/tables/Ubicacion.js | 10 +- helpers/tables/nombres.json | 100 +++++++++++++++++ helpers/tables/ubicaciones.json | 16 +-- helpers/tables/unidades.json | 122 ++++++++++---------- server/controller/upload/postE.js | 179 +++++++++++++----------------- server/models/tablas/Ubicacion.js | 2 +- 7 files changed, 248 insertions(+), 188 deletions(-) create mode 100644 helpers/tables/nombres.json diff --git a/helpers/tables/UResponsable.js b/helpers/tables/UResponsable.js index 399bb40..634bfc2 100644 --- a/helpers/tables/UResponsable.js +++ b/helpers/tables/UResponsable.js @@ -7,8 +7,10 @@ faker.locale = 'es_MX'; async function fillUResponsable() { let unidades = require('./unidades.json'); - let nombreResponsable = ''; + var nombres = require('./nombres.json'); let limit = unidades.length; + let count = 0; + const bar = new progress.SingleBar({ format: 'uResponsable |' + colors.cyan('{bar}') + '| {percentage}%' + ' || {value}/{total} records created.', barCompleteChar: '\u2588', @@ -23,7 +25,7 @@ async function fillUResponsable() { bar.start(limit, 0); for (uResponsable of unidades) { - nombreResponsable = faker.name.findName(); + nombreResponsable = nombres[count]; await UResponsable.create({ uResponsable, nombreResponsable @@ -33,6 +35,7 @@ async function fillUResponsable() { throw new Error(); }); bar.increment(); + count++; }; return limit; }; diff --git a/helpers/tables/Ubicacion.js b/helpers/tables/Ubicacion.js index 33d018c..67c7853 100644 --- a/helpers/tables/Ubicacion.js +++ b/helpers/tables/Ubicacion.js @@ -2,12 +2,9 @@ const Ubicacion = require('../../server/models/tablas/Ubicacion'); const progress = require('cli-progress'); const colors = require('colors'); -const faker = require('faker'); -faker.locale = "es_MX"; - async function fillUbicacion() { let ubicaciones = require('./ubicaciones'); - let limit = 15; + let limit = ubicaciones.length; const bar = new progress.SingleBar({ format: 'ubicacion |' + colors.cyan('{bar}') + '| {percentage}%' + ' || {value}/{total} records created.', barCompleteChar: '\u2588', @@ -25,9 +22,10 @@ async function fillUbicacion() { await Ubicacion.create({ ubicacion }) - .catch(() => { + .catch((e) => { bar.stop(); - throw new Error(); + console.log(e); + throw new Error(e); }); bar.increment(); }; diff --git a/helpers/tables/nombres.json b/helpers/tables/nombres.json new file mode 100644 index 0000000..f6ae6b2 --- /dev/null +++ b/helpers/tables/nombres.json @@ -0,0 +1,100 @@ +[ + "Lic. María Claudia Otake González", + "Mtro. José Luis Castañón Zurita", + "Lic. Fernando Israel González Trejo", + "Dra. Lucía Elena Acosta Ugalde", + "Lic. Gloria Isabel Moctezuma Nájera", + "Lic. Verónica Puma Galicia", + "Ing. Carlos Rojas Gutiérrez", + "Mtra. Laura Angélica Chávez Tovar", + "Ing. Gabriel Alejandro López Campos", + "Lic. Alberto Guerrero Meneses", + "Mtro. Christian Roberto Salazar Montiel", + "Dr. Felipe Cruz Díaz", + "Mtro. Fernando Martínez Ramírez", + "Dra. Ericka Judith Arias Guzmán", + "NO HAY", + "Profa. Yuritzia Navarrete Avila", + "Lic. Cynthia Maricela Uribe Pacheco", + "Lic. Gloria Elena Araiza Ledezma", + "Prof. Carlos Gerardo Cabrera Lerma", + "Lic. José Ángel Hernández Rivera", + "Ing. Carlos Arce León", + "Prof. Emmanuel Castañeda Pérez", + "Mtra. Heidy Jojana Oliva Tello", + "Lic. Eva Ocaña Islas", + "Mtro. Juan José Sanabria López", + "Mtra. Nancy Lara Hernández", + "Mtro. Adrián Luis Maldonado González", + "Lic. José Antonio González Santos", + "Lic. Adriana Zúñiga Pérez", + "No es Adscripción", + "Lic. Leticia Juárez Ortega", + "Lic. María Patricia Javier Pérez", + "Dra. Rosa Martha Gutiérrez Rodríguez", + "Lic. Miguel Ángel De La Calleja López", + "Prof. David Rey Ávila", + "Arq. Miguel Ángel Guevara Reyes", + "Dra. Graciela Carrazco López", + "C. Marfides Oralia Godoy Cortés", + "Lic. Edna Cristina Gutiérrez López", + "Lic. Omar Alberto González Contreras", + "Lic. José Alberto Bravo Hernández", + "Lic. Fabiola Virginia Lara Treviño", + "Lic. Jesús Jiménez Cruz", + "Lic. José Roberto Bautista Mora", + "Mtro. Gilberto González Pérez", + "Mtra. María Guadalupe Durán Pérez", + "Lic. Sandra Trejo Legorreta", + "D. G. Hugo Enrique García Ruiz", + "Mtra. Adriana Roque Del Angel", + "NO HAY", + "Lic. Juan Carlos Ramírez Martínez", + "Lic. Araceli Perez Palma", + "C. Francisco Gutiérrez Pérez", + "Lic. Anabel Moreno Baltazar", + "Arq. Erick Eduardo Casas Gutiérrez", + "Lic. Jesús Cervantes Arias", + "Ing. Leydi Rubí Pérez Vera", + "D. G. Laura Gutiérrez Ochoa", + "Lic. Gerardo Gabriel Mares Velasco", + "Lic. César Gómez Gómez", + "Lic. Erasmo González Castro", + "Lic. Jorge Reyes Caldera Arroyo", + "Dra. Claudia Márquez Díaz", + "Mtro. Rubén Juárez Santana", + "Mtra. María Luisa Morales Martínez", + "Act. Luz María Lavín Alanís", + "Lic. Aída Villalobos Sosa", + "Mtra. Marisela Rodríguez Pacheco", + "Act. Mahil Herrera Maldonado", + "Arq. Marcial Álvarez Salgado", + "Lic. Ariadna Uribe Ortiz", + "Mtra. Lidia Chávez Fonseca", + "Mtro. Esteban Piña Pérez", + "Lic. Jorge Villegas Hernández", + "Mtra. Xóchitl Adriana Hernández Martínez", + "Mtro. Ernesto de Icaza Villalpando", + "Ing. Omar Ulises Morales Dávila", + "Lic. Christian Carlos Delgado Elizondo", + "Mtra. María de Jesús Solís Solís", + "Lic. María Elena González Lupercio", + "Lic. María Guadalupe Alonso Quintana", + "Mtro. José Luis Castañón Zurita", + "Mtro. Carlos Nandayapa Hernández", + "Dr. Alejandro Byrd Orozco", + "Dr. David Morales González", + "Dra. Laura Páez Díaz de León", + "Mtra. Nora Del Consuelo Goris Mayans", + "Médico Lorena Hortensia Vázquez Bustos", + "Ing. Hugo César González Ramírez", + "Prof. Aarón Juárez Chávez", + "Lic. Roberto Carlos Castro Azcué", + "Lic. Yareth Perez Salgado", + "Lic. Samuel Ornelas Rosales", + "NO HAY", + "C. Carlos Armando Rosas Cruz", + "Profa. Norma Guadalupe Rojas Borja", + "Lic. José Gerardo Pérez Aguilar", + "Lic. Sara Luz Alvarado Aranda" +] \ No newline at end of file diff --git a/helpers/tables/ubicaciones.json b/helpers/tables/ubicaciones.json index d29819c..60ed2e6 100644 --- a/helpers/tables/ubicaciones.json +++ b/helpers/tables/ubicaciones.json @@ -1,17 +1,3 @@ [ - "Aula 1", - "Aula 2", - "Aula 3", - "Aula 4", - "Aula 5", - "Aula 6", - "Aula 7", - "Aula 8", - "Aula 9", - "Aula 10", - "Aula 11", - "Aula 12", - "Aula 13", - "Aula 14", - "Aula 15" + "Aula 1" ] \ No newline at end of file diff --git a/helpers/tables/unidades.json b/helpers/tables/unidades.json index daf6144..a665197 100644 --- a/helpers/tables/unidades.json +++ b/helpers/tables/unidades.json @@ -1,100 +1,98 @@ [ - "ÁREA DE CURSOS DEL CENTRO DE DESARROLLO TECNOLÓGICO", - "ÁREA DE SERVICIOS DE CÓMPUTO DE LA SECRETARÍA ADMINISTRATIVA", - "BIENES EN TRÁMITE DE ACTA ADMINISTRATIVA", - "BIENES PENDIENTES POR LOCALIZAR Y RESGUARDAR", - "CENTRO DE DESARROLLO TECNOLÓGICO", - "CENTRO DE DIFUSIÓN CULTURAL", - "CENTRO DE EDUCACIÓN CONTINUA", - "CENTRO DE ENSEÑANZA DE IDIOMAS", + "ÁREA DE CURSOS", + "AREA DE SERVICIOS DE COMPUTO DE LA SECRETARIA ADMINISTRATIVA", + "CENTRO DE DESARROLLO TECNOLOGICO", + "CENTRO DE DIFUSION CULTURAL", + "CENTRO DE EDUCACION CONTINUA", + "CENTRO DE ENSEñANZA DE IDIOMAS", "CENTRO DE ESTUDIOS MUNICIPALES Y METROPOLITANOS", - "CENTRO TECNOLÓGICO PARA LA EDUCACIÓN A DISTANCIA", - "COORDINACIÓN DE ACTIVIDADES DEPORTIVAS Y RECREATIVAS", - "COORDINACIÓN DE COMUNICACIÓN SOCIAL", + "CENTRO TECNOLÓGICO PARA LA EDUCACION A DISTANCIA, CETED", + "COORDINACION DE ACTIVIDADES DEPORTIVAS Y RECREATIVAS", + "COORDINACION DE COMUNICACION SOCIAL", "COORDINACIÓN DE GESTIÓN DE LA DIRECCIÓN", "COORDINACIÓN DE INVESTIGACIÓN MULTIDISCIPLINARIA", - "COORDINACIÓN DE SERVICIOS ACADÉMICOS", - "COORDINACIÓN DEL PROGRAMA DE ESTUDIOS DE POSGRADO", - "DEPARTAMENTO DE HEMEROTECA Y DOCUMENTACIÓN", + "COORDINACIÓN DE SERVICIOS ACADEMICOS", + "COORDINACION DE ESTUDIOS DE POSGRADO", + "DEPARTAMENTO DE HEMEROTECA Y DOCUMENTACION", "DEPARTAMENTO DE ACTIVIDADES CULTURALES Y DIFUSIÓN", "DEPARTAMENTO DE ADQUISICIONES", - "DEPARTAMENTO DE ADQUISICIONES BIBLIOGRÁFICAS Y PROCESOS TÉCNICOS", - "DEPARTAMENTO DE ALEMÁN, GRIEGO Y RUSO", + "DEPARTAMENTO DE ADQUISICIONES BIBLIOGRAFICAS Y PROCESOS TECNICOS", + "DEPARTAMENTO DE ALEMAN, GRIEGO Y RUSO", "DEPARTAMENTO DE ALMACENES E INVENTARIOS", - "DEPARTAMENTO DE ANÁLISIS DE RIESGOS NATURALES Y ANTROPOÉNICOS", - "DEPARTAMENTO DE APOYO TÉCNICO AL CENTRO CULTURAL", + "DEPARTAMENTO DE ANALISIS DE RIESGOS NATURALES Y ANTROPOENICOS (UIM)", + "DEPARTAMENTO DE APOYO TECNICO AL CENTRO CULTURAL", "DEPARTAMENTO DE CONSULTA", "DEPARTAMENTO DE ESPAÑOL PARA EXT. Y LENGUAS NO INDOEUROPEAS", "DEPARTAMENTO DE ESTUDIOS DE GOBIERNO Y POLÍTICAS PÚBLICAS", - "DEPARTAMENTO DE ESTUDIOS DE PROCURACIÓN DE JUSTICIA Y SEGURIDAD PÚBLICA", - "DEPARTAMENTO DE EXTENSIÓN CULTURAL", - "DEPARTAMENTO DE FORMACIÓN DOCENTE Y SUPERACIÓN ACADÉMICA", - "DEPARTAMENTO DE FRANCÉS", + "DEPARTAMENTO DE ESTUDIOS DE PROCURACION DE JUSTICIA Y SEGURIDAD PUBLICA", + "DEPARTAMENTO DE EXTENSION CULTURAL", + "DEPARTAMENTO DE FORMACION DOCENTE Y SUPERACION ACADEMICA", + "DEPARTAMENTO DE FRANCES", "DEPARTAMENTO DE IMAGEN CORPORATIVA E INSTITUCIONAL", "DEPARTAMENTO DE INGLÉS", "DEPARTAMENTO DE INTENDENCIA", - "DEPARTAMENTO DE INVESTIGACIÓN EDUCATIVA", - "DEPARTAMENTO DE INVESTIGACIÓN EN COMUNICACIÓN Y ESTUDIOS CULTURALES", + "DEPARTAMENTO DE INVESTIGACION EDUCATIVA", + "DEPARTAMENTO DE DESARROLLO E INVESTIGACIÓN EN COMUNICACIÓN Y ESTUDIOS CULTURALES", "DEPARTAMENTO DE ITALIANO Y LATÍN", "DEPARTAMENTO DE OBRA CIVIL Y PROYECTOS", - "DEPARTAMENTO DE ORIENTACIÓN EDUCATIVA", + "DEPARTAMENTO DE ORIENTACION EDUCATIVA", "DEPARTAMENTO DE PERSONAL", - "DEPARTAMENTO DE PORTUGUÉS", + "DEPARTAMENTO DE PORTUGUES", "DEPARTAMENTO DE PRESUPUESTO", - "DEPARTAMENTO DE PROMOCIÓN Y ORGANIZACIÓN DEPORTIVA", - "DEPARTAMENTO DE PROYECCIÓN EMPRESARIAL E INTERCAMBIO Y COLABORACIÓN INSTITUCIONAL", + "DEPARTAMENTO DE PROMOCION Y ORGANIZACION DEPORTIVA", + "DEPARTAMENTO DE DESARROLLO EMPRESARIAL E INTERCAMBIO Y COLABORACION", "DEPARTAMENTO DE PROYECTOS ADMINISTRATIVOS", - "DEPARTAMENTO DE REDES Y SOPORTE TÉCNICO", - "DEPARTAMENTO DE REGISTRO Y CERTIFICACIÓN DE LA DIVISIÓN S.U.A", - "DEPARTAMENTO DE REGISTRO Y CERTIFICACIÓN DE POSGRADO", - "DEPARTAMENTO DE REGISTRO Y CERTIFICACION DEL C.E.I", - "DEPARTAMENTO DE REPRODUCCIONES GRÁFICAS", + "DEPARTAMENTO DE REDES Y SOPORTE TÉCNICO (CEDETEC)", + "DEPARTAMENTO DE REGISTRO Y CERTIFICACION DE LA DIVISION S. U. A.", + "DEPARTAMENTO DE REGISTRO Y CERTIFICACION DE POSGRADO", + "DEPARTAMENTO DE REGISTRO Y CERTIFICACION DEL C.E.I.", + "DEPARTAMENTO DE REPRODUCCIONES GRAFICAS", "DEPARTAMENTO DE SERVICIO SOCIAL Y BOLSA DE TRABAJO", - "DEPARTAMENTO DE SERVICIOS AL PÚBLICO", + "DEPARTAMENTO DE SERVICIOS AL PUBLICO (CID)", "DEPARTAMENTO DE SERVICIOS AUDIOVISUALES", - "DEPARTAMENTO DE SERVICIOS DE CÓMPUTO", + "DEPARTAMENTO DE SERVICIOS DE COMPUTO", "DEPARTAMENTO DE SERVICIOS GENERALES DE MANTENIMIENTO", "DEPARTAMENTO DE SISTEMAS DE INFORMACIÓN", - "DEPARTAMENTO DE SUPERVISIÓN TÉCNICA Y SEGUIMIENTO", + "DEPARTAMENTO DE SUPERVISION TECNICA", "DEPARTAMENTO DE TALLERES Y LABORATORIOS", - "DEPARTAMENTO DE TECNOLOGÍA AMBIENTAL", - "DEPARTAMENTO DE TIPOGRAFÍA Y DISEÑO", - "DEPARTAMENTO DE TÍTULOS PROFESIONALES Y CERTIFICACIÓN", + "DEPARTAMENTO DE TECNOLOGIA AMBIENTAL (UIM)", + "DEPARTAMENTO DE TIPOGRAFIA Y DISEÑO", + "DEPARTAMENTO DE TITULOS PROFESIONALES Y CERTIFICACION", "DEPARTAMENTO DE TRANSPORTES Y SERVICIOS DE APOYO", "DEPARTAMENTO DE VIGILANCIA", - "DIVISIÓN DE CIENCIAS JURÍDICAS", - "DIVISIÓN DE CIENCIAS SOCIOECONÓMICAS", - "DIVISIÓN DE DISEÑO Y EDIFICACIÓN", - "DIVISIÓN DE HUMANIDADES", + "DIVISION DE CIENCIAS JURIDICAS", + "DIVISION DE CIENCIAS SOCIOECONOMICAS", + "DIVISION DE DISEÑO Y EDIFICACION", + "DIVISION DE HUMANIDADES", "DIVISIÓN DE MATEMÁTICAS E INGENIERÍA", - "DIVISIÓN DEL SISTEMA DE UNIVERSIDAD ABIERTA Y EDUCACIÓN A A DISTANCIA", - "LIBRERÍA UNIVERSITARIA DE LA FES ACATLÁN", - "PROGRAMA DE ACTUARÍA", + "DIVISION DEL SISTEMA DE UNIVERSIDAD ABIERTA Y EDUCACIÓN A A DISTANCIA", + "LIBRERIA UNIVERSITARIA DE LA FES ACATLAN", + "PROGRAMA DE ACTUARIA", "PROGRAMA DE ARQUITECTURA", "PROGRAMA DE COMUNICACIÓN", "PROGRAMA DE DERECHO", - "PROGRAMA DE DISEÑO GRÁFICO", - "PROGRAMA DE ECONOMÍA", - "PROGRAMA DE ENSEÑANZA DEL INGLÉS", + "PROGRAMA DE DISEÑO GRAFICO", + "PROGRAMA DE ECONOMIA", + "PROGRAMA DE ENSEÑANZA DEL INGLES", "PROGRAMA DE HUMANIDADES", - "PROGRAMA DE INGENIERÍA CIVIL", - "PROGRAMA DE MATEMÁTICAS APLICADAS Y COMPUTACIÓN", - "PROGRAMA DE PEDAGOGÍA", - "PROGRAMA DE SOCIOLOGÍA", - "PROGRAMA POLÍTICO", + "PROGRAMA DE INGENIERIA CIVIL", + "PROGRAMA DE MATEMATICAS APLICADAS Y COMPUTACION", + "PROGRAMA DE PEDAGOGIA", + "PROGRAMA DE SOCIOLOGIA", + "PROGRAMA POLITICO", "SECRETARÍA ADMINISTRATIVA", "SECRETARÍA DE ESTUDIOS PROFESIONALES", - "SECRETARÍA DE EXTENSIÓN UNIVERSITARIA Y VINCULACIÓN INSTITUCIONAL", + "SECRETARÍA DE EXTENSION UNIVERSITARIA Y VINCULACIÓN INSTITUCIONAL", "SECRETARÍA DE LA DIRECCIÓN", "SECRETARÍA DE POSGRADO E INVESTIGACIÓN", - "SECRETARÍA GENERAL", - "SERVICIO MÉDICO", + "SECRETARIA GENERAL", + "SERVICIO MEDICO", "SUPERINTENDENCIA DE OBRAS Y MANTENIMIENTO", - "UNIDAD DE ADMINISTRACIÓN ESCOLAR", - "UNIDAD DE ADMINISTRACIÓN Y RECURSOS", - "UNIDAD DE LA OFICINA JURÍDICA", - "UNIDAD DE PLANEACIÓN", - "UNIDAD DE PROCESO", + "UNIDAD DE ADMINISTRACION ESCOLAR", + "UNIDAD DE ADMINISTRACION Y RECURSOS", + "UNIDAD DE LA OFICINA JURIDICA", + "UNIDAD DE PLANEACION", + "UNIDAD DE PROCESO (U.P.A.)", "UNIDAD DE SERVICIOS A LA COMUNIDAD", "UNIDAD DE SERVICIOS EDITORIALES", "UNIDAD DE TALLERES, LABORATORIOS Y AUDIOVISUALES", diff --git a/server/controller/upload/postE.js b/server/controller/upload/postE.js index c0b2544..632b11c 100644 --- a/server/controller/upload/postE.js +++ b/server/controller/upload/postE.js @@ -14,103 +14,72 @@ const post = async(req, res) => { const file = req.files.equipos; let equipos = []; - let ubicaciones = []; - let unidades = []; - let usos = []; - let activos = []; - let os = []; - let marcas = []; - - await Ubicacion.findAll({ - attributes: ['ubicacion'], - order: ['idUbicacion'] - }) - .then(resultado => { - resultado.forEach(el => ubicaciones.push(Object.entries(el.dataValues))); - resultado = ubicaciones.flat(2); - ubicaciones = resultado.filter(ubicacion => ubicacion != 'ubicacion') - }) - .catch(err => res.status(500).json({ - ok: false, - error: err - })); - - await UResponsable.findAll({ - attributes: ['uResponsable'], - order: ['idUnidadResponsable'] - }) - .then((result) => { - result.forEach(el => unidades.push(Object.entries(el.dataValues))); - unidades = unidades.flat(2); - unidades = unidades.filter(filtro => filtro != 'uResponsable') - }).catch((err) => res.status(500).json({ - ok: false, - error: err - })); - - await Uso.findAll({ - attributes: ['uso'], - order: ['idUso'] - }) - .then((result) => { - result.forEach(el => usos.push(Object.entries(el.dataValues))); - usos = usos.flat(2); - usos = usos.filter(filtro => filtro != 'uso') - }).catch((err) => res.status(500).json({ - ok: false, - error: err - })); - - await ActivoFijo.findAll({ - attributes: ['activoFijo'], - order: ['idActivoFijo'] - }) - .then((result) => { - result.forEach(el => activos.push(Object.entries(el.dataValues))); - activos = activos.flat(2); - activos = activos.filter(filtro => filtro != 'activoFijo') - }).catch((err) => res.status(500).json({ - ok: false, - error: err - })); - - await OS.findAll({ - attributes: ['osname'], - order: ['idOS'] - }) - .then((result) => { - result.forEach(el => os.push(Object.entries(el.dataValues))); - os = os.flat(2); - os = os.filter(filtro => filtro != 'osname') - }).catch((err) => res.status(500).json({ - ok: false, - error: err - })); - - await Marca.findAll({ - attributes: ['marca'], - order: ['idMarca'] - }) - .then((result) => { - result.forEach(el => marcas.push(Object.entries(el.dataValues))); - marcas = marcas.flat(2); - marcas = marcas.filter(filtro => filtro != 'marca') - }).catch((err) => res.status(500).json({ - ok: false, - error: err - })); let data = await xlsx.parse(file.tempFilePath); data = Object.entries(data[0]); data.shift(); data = data[0][1] data.shift(); - data.forEach(row => { + for (row of data) { + if (row[1]) { + var activoFijo = await ActivoFijo.findOrCreate({ + where: { + activoFijo: row[1] || 'No declarado' + } + }) + .catch((res) => console.log(res)); + } + + if (row[3]) { + var marca = await Marca.findOrCreate({ + where: { + marca: row[3] || 'No declarado' + } + }) + .catch((e) => { throw new Error(e); }); + } + + if (row[12]) { + var os = await OS.findOrCreate({ + where: { + osname: row[12] || 'No declarado' + } + }) + .catch((e) => { throw new Error(e); }); + } + + if (row[14]) { + var uResponsable = await UResponsable.findOrCreate({ + where: { + uResponsable: row[14] || 'No declarado' + } + }) + .catch((e) => { throw new Error(e); }); + } + + if (row[16]) { + var ubicacion = await Ubicacion.findOrCreate({ + where: { + ubicacion: row[16] || 'No declarado' + } + }) + .catch((e) => { throw new Error(e); }); + } + + if (row[17]) { + var uso = await Uso.findOrCreate({ + where: { + uso: row[17] || 'No declarado' + } + }) + .catch((e) => { throw new Error(e); }); + } + let equipo = { noInventario: row[0], - activoFijo: activos.indexOf(row[1]) + 1, + idActivoFijo: activoFijo[0]['idActivoFijo'], modelo: row[2], - marca: marcas.indexOf(row[3]) + 1, + marca: marca[0]['idMarca'], noSerie: row[4], procesador: row[5], vProcesador: row[6], @@ -119,22 +88,23 @@ const post = async(req, res) => { memoria: row[9], vMemoria: row[10], graficos: row[11], - osname: os.indexOf(row[12]) + 1, + osname: os[0]['idOS'], noResguardo: row[13], - uResponsable: unidades.indexOf(row[14]) + 1, - ubicacion: ubicaciones.indexOf(row[16]) + 1, - uso: usos.indexOf(row[17]) + 1, + uResponsable: uResponsable[0]['idUnidadResponsable'], + ubicacion: ubicacion[0]['idUbicacion'], + uso: uso[0]['idUso'] } equipos.push(equipo); - }); + } - let count = 0; + + var count = 0; for (equipo of equipos) { count++; await Inventario.create({ noInventario: equipo.noInventario, noResguardo: equipo.noResguardo, - idActivoFijo: equipo.activoFijo, + idActivoFijo: equipo.idActivoFijo, idUnidadResponsable: equipo.uResponsable, idUbicacion: equipo.ubicacion, idUso: equipo.uso @@ -161,22 +131,27 @@ const post = async(req, res) => { noInventario: equipo.noInventario } }); - return res.status(500).json({ + res.status(500).json({ ok: false, err - }) + }); + throw new Error(e); }) }) - .catch((e) => res.status(500).json({ - ok: false, - e - })) - + .catch((e) => { + res.status(500).json({ + ok: false, + e + }); + throw new Error(e); + }) } res.json({ ok: true, message: `${ count } records created successfully.` + // equipos + // activoF }) } diff --git a/server/models/tablas/Ubicacion.js b/server/models/tablas/Ubicacion.js index 7a08ed8..6830c30 100644 --- a/server/models/tablas/Ubicacion.js +++ b/server/models/tablas/Ubicacion.js @@ -12,7 +12,7 @@ Ubicacion.init({ ubicacion: { type: Sequelize.CHAR, allowNull: false, - unique: true + // unique: true }, }, { sequelize, From c24ddc4cf5b17d9991f925ee62c82ed3d2fae061 Mon Sep 17 00:00:00 2001 From: alfredojl Date: Tue, 6 Oct 2020 20:16:17 -0500 Subject: [PATCH 2/2] . --- helpers/tables/Ubicacion.js | 52 ++++++++++++++----------------------- 1 file changed, 20 insertions(+), 32 deletions(-) diff --git a/helpers/tables/Ubicacion.js b/helpers/tables/Ubicacion.js index 67c7853..6830c30 100644 --- a/helpers/tables/Ubicacion.js +++ b/helpers/tables/Ubicacion.js @@ -1,34 +1,22 @@ -const Ubicacion = require('../../server/models/tablas/Ubicacion'); -const progress = require('cli-progress'); -const colors = require('colors'); +const Sequelize = require("sequelize"); +const sequelize = require("../../config/sequelize.conf"); -async function fillUbicacion() { - let ubicaciones = require('./ubicaciones'); - let limit = ubicaciones.length; - const bar = new progress.SingleBar({ - format: 'ubicacion |' + colors.cyan('{bar}') + '| {percentage}%' + ' || {value}/{total} records created.', - barCompleteChar: '\u2588', - barIncompleteChar: '\u2591', - hideCursor: true, - stopOnComplete: true, - barsize: 30, - align: 'right' - }); +class Ubicacion extends Sequelize.Model {} +Ubicacion.init({ + idUbicacion: { + type: Sequelize.INTEGER, + primaryKey: true, + autoIncrement: true, + allowNull: false, + }, + ubicacion: { + type: Sequelize.CHAR, + allowNull: false, + // unique: true + }, +}, { + sequelize, + tableName: "ubicacion", +}); - console.log('\n\tFilling out «ubicacion».'.cyan.italic.bold); - - bar.start(limit, 0); - for (ubicacion of ubicaciones) { - await Ubicacion.create({ - ubicacion - }) - .catch((e) => { - bar.stop(); - console.log(e); - throw new Error(e); - }); - bar.increment(); - }; -}; - -module.exports = fillUbicacion; \ No newline at end of file +module.exports = Ubicacion; \ No newline at end of file