From ef328ecf8a90407cc275819e5d76fa6e9c27364c Mon Sep 17 00:00:00 2001 From: alfredojl Date: Thu, 10 Sep 2020 03:06:23 -0500 Subject: [PATCH] Filled out DB fixed. --- .gitignore | 1 + helpers/fillDB.js | 364 ++++++++++--------------- helpers/tables/ActivoFijo.js | 31 +++ helpers/tables/DescripcionAdicional.js | 16 ++ helpers/tables/Equipo.js | 79 ++++++ helpers/tables/Inventario.js | 39 +++ helpers/tables/Marca.js | 36 +++ helpers/tables/OS.js | 32 +++ helpers/tables/Printers.js | 26 ++ helpers/tables/Tipo.js | 29 ++ helpers/tables/UResponsable.js | 25 ++ helpers/tables/Ubicacion.js | 27 ++ helpers/tables/Uso.js | 24 ++ helpers/tables/ubicaciones.json | 17 ++ helpers/{ => tables}/unidades.json | 4 - helpers/tables/usos.json | 1 + package.json | 2 +- scratch/token | 2 +- server/controller/api/computers.js | 23 ++ server/middlewares/authentication.js | 34 ++- server/models/install.js | 8 +- server/models/tablas/ActivoFijo.js | 1 + server/models/tablas/Equipo.js | 3 +- server/models/tablas/Inventario.js | 1 + server/models/tablas/Marca.js | 1 + server/models/tablas/OS.js | 1 + server/models/tablas/Printers.js | 4 + server/models/tablas/Tipo.js | 1 + server/models/tablas/UResponsable.js | 1 + server/models/tablas/Ubicacion.js | 1 + server/models/tablas/Uso.js | 1 + server/routes/index.js | 5 +- server/routes/login.js | 3 +- server/routes/user.js | 14 + 34 files changed, 623 insertions(+), 234 deletions(-) create mode 100644 helpers/tables/ActivoFijo.js create mode 100644 helpers/tables/DescripcionAdicional.js create mode 100644 helpers/tables/Equipo.js create mode 100644 helpers/tables/Inventario.js create mode 100644 helpers/tables/Marca.js create mode 100644 helpers/tables/OS.js create mode 100644 helpers/tables/Printers.js create mode 100644 helpers/tables/Tipo.js create mode 100644 helpers/tables/UResponsable.js create mode 100644 helpers/tables/Ubicacion.js create mode 100644 helpers/tables/Uso.js create mode 100644 helpers/tables/ubicaciones.json rename helpers/{ => tables}/unidades.json (94%) create mode 100644 helpers/tables/usos.json create mode 100644 server/controller/api/computers.js create mode 100644 server/routes/user.js diff --git a/.gitignore b/.gitignore index 1846749..1bb4a98 100644 --- a/.gitignore +++ b/.gitignore @@ -38,6 +38,7 @@ node_modules/ jspm_packages/ ./.env scratch/ +./server/controller/api # TypeScript v1 declaration files typings/ diff --git a/helpers/fillDB.js b/helpers/fillDB.js index d645654..906f012 100644 --- a/helpers/fillDB.js +++ b/helpers/fillDB.js @@ -1,14 +1,14 @@ -const activoFijo = require('../server/models/tablas/ActivoFijo'); -const DescripcionAdicional = require('../server/models/tablas/DescripcionAdicional'); -const Equipo = require('../server/models/tablas/Equipo'); -const Inventario = require('../server/models/tablas/Inventario'); -const Marca = require('../server/models/tablas/Marca'); -const OS = require('../server/models/tablas/OS'); -const Printers = require('../server/models/tablas/Printers'); -const Tipo = require('../server/models/tablas/Tipo'); -const Ubicacion = require('../server/models/tablas/Ubicacion'); -const UResponsable = require('../server/models/tablas/UResponsable'); -const Uso = require('../server/models/tablas/Uso'); +const fillActivoFijo = require('./tables/ActivoFijo'); +const fillDA = require('./tables/DescripcionAdicional'); +const fillEquipo = require('./tables/Equipo'); +const fillInventario = require('./tables/Inventario'); +const fillMarca = require('./tables/Marca'); +const fillOS = require('./tables/OS'); +const fillPrinters = require('./tables/Printers'); +const fillTipo = require('./tables/Tipo'); +const fillUbicacion = require('./tables/Ubicacion'); +const fillUResponsable = require('./tables/UResponsable'); +const fillUso = require('./tables/Uso'); const faker = require('faker'); faker.locale = "es_MX"; @@ -16,217 +16,155 @@ faker.locale = "es_MX"; const colors = require('colors'); const symbols = require('log-symbols'); -let rows = 5; +let rows = 10; +let faileds = 0; +let ok = 0; +let censo = 0; -async function fillingUp() { - await fillActivoFijo(); - await fillDA(); - await fillEquipo(); - await fillInventario(); - await fillMarca(); - await fillOS(); - await fillPrinters(); - await fillTipo(); - await fillUbicacion(); - await fillUResponsable(); - await fillUso(); +async function fillingEquipo() { + for (let i = 0; i < rows; i++) { + let noInventario = faker.phone.phoneNumber("2######"); + let idActivoFijo = idUso = faker.random.number({ + min: 1, + max: 5 + }); + + // await fillDA(); + await fillInventario(noInventario, idActivoFijo) + .then(() => { + console.log(`${ i + 1 }/${ rows } records created on inventario-equipo`); + censo++; + }) + .catch((e) => { + throw new Error(e); + }); + await fillEquipo(noInventario, idActivoFijo) + .then(() => { + console.log(`${ i + 1 }/${ rows } records created on equipo`); + censo++; + }) + .catch((e) => { + throw new Error(e); + }); + } + return; } -async function fillActivoFijo() { - let af = faker.random.arrayElement([ - "PC", - "Laptop", - "Impresora", - "Servidor", - "Ipad", - "Chromebook" - ]); - - // console.log("Activo fijo: ", af); - - await activoFijo.create({ - activoFijo: af - }); +async function fillingPrinters() { + for (let i = 0; i < rows; i++) { + let noInventario = faker.phone.phoneNumber("2######"); + let idActivoFijo = 6; + await fillInventario(noInventario, idActivoFijo) + .then(() => console.log(`${ i + 1 }/${ rows } records created on inventario-printers`)) + .catch((e) => { + console.log(symbols.warning, 'Error creating «inventario-printers»'); + throw new Error(e); + }); + await fillPrinters(noInventario) + .then(() => console.log(`${ i + 1 }/${ rows } records created on printers`)) + .catch((e) => { + console.log(symbols.warning, 'Error creating «printers»'); + throw new Error(e); + }); + } + return; } -async function fillDA() { - let da = faker.lorem.sentence(); - - // console.log("Descripción adicional: ", da); - - await DescripcionAdicional.create({ - descripcion: da - }) -} - -async function fillEquipo() { - let modelo = faker.vehicle.model(); - let noSerie = faker.vehicle.vin(); - let procesador = faker.random.arrayElement([ - "Intel Core i3", - "Intel Core i5", - "Intel Core i7", - "Ryzen 3", - "Ryzen 5", - "Ryzen 7", - ]); - let vProcesador = faker.random.number({ min: 2000, max: 4500 }) - let memoria = faker.random.arrayElement([ - "DDR2", - "DDR3", - "DDR4" - ]); - let memoriasz = faker.random.arrayElement([ - 4096, - 2048, - 8192 - ]); - let vMemoria = faker.random.number({ min: 1400, max: 1800, precision: 4 }); - let graficos = faker.random.arrayElement([ - "Intel HD Graphics", - "Intel Iris", - "Intel Iris Plus", - "Radeon Vega 8", - "Radeon Vega 7", - "Radeon Vega Plus", - "Radeon Vega Graphics", - ]); - let hdd = faker.random.number({ - min: 80, - max: 990, - precision: 2 - }); - - // console.log("Modelo: ", modelo, "\nNúmero de serie: ", noSerie, "\nProcesador: ", procesador, "\nVelocidad de procesador: ", vProcesador, "\nMemoria: ", memoria, "\nCantidad de memoria: ", memoriasz, "\nVelocidad de memoria: ", vMemoria, "\nGráficos: ", graficos, "\nTamaño de almacenamiento: ", hdd); - - await Equipo.create({ - modelo, - noSerie, - procesador, - vProcesador, - memoria, - memoriasz, - vMemoria, - graficos, - hdd - }); -}; - -async function fillInventario() { - let noInventario = faker.phone.phoneNumber("2######") - let noResguardo = faker.phone.phoneNumber("#####") - // console.log("Inventario: ", noInventario, "\nResguardo: ", noResguardo); - - await Inventario.create({ - noInventario, - noResguardo - }); -}; - -async function fillMarca() { - let marca = faker.random.arrayElement([ - "HP", - "ECOIN", - "SONY", - "LENOVO", - "DELL", - "ACER", - "ASUS", - "APPLE", - "COMPAQ", - "GATEWAY", - "ECOIN", - "IBM" - ]); - - // console.log("Marca: ", marca); - - await Marca.create({ - marca - }); -}; - -async function fillOS() { - let osname = faker.random.arrayElement([ - "Windows 7", - "Windows 10", - "Debian", - "Fedora", - "CentOS", - "Ubuntu", - "MacOS" - ]); - // console.log("Sistema operativo: ", osname); - - await OS.create({ - osname - }); -}; - -async function fillPrinters() { - let noSerie = faker.vehicle.vin(); - // console.log("Número de serie impresora: ", noSerie); - - await Printers.create({ - noSerie - }); -}; - -async function fillTipo() { - let tipo = faker.random.arrayElement([ - "Impresora", - "Multifuncional", - "Láser", - "Plotter" - ]); - // console.log("Tipo de impresora: ", tipo); - - await Tipo.create({ - tipo - }); -}; - -async function fillUbicacion() { - let ubicacion = faker.name.jobArea(); - - // console.log("Ubicación: ", ubicacion); - - await Ubicacion.create({ - ubicacion - }); -}; - -async function fillUResponsable() { - let unidades = require('./unidades.json'); - let uResponsable = faker.random.arrayElement(unidades); - let nombreResponsable = faker.name.findName(); - // console.log("Unidad responsable: ", uResponsable, "\nNombre del responsable: ", nombreResponsable); - - await UResponsable.create({ - uResponsable, - nombreResponsable - }); -}; - -async function fillUso() { - let uso = faker.name.jobType(); - // console.log("Uso: ", uso); - - await Uso.create({ - uso - }); -}; - async function exec() { + await fillActivoFijo() + .then(() => { + console.log(symbols.success, '«activoFijo» filled out.'.green.bold) + ok++; + }) + .catch(() => { + console.log(symbols.warning, 'Error creating «activoFijo».'.yellow.bold); + faileds++; + }); + await fillMarca() + .then(() => { + console.log(symbols.success, '«marca» filled out.'.green.bold) + ok++; + }) + .catch(() => { + console.log(symbols.warning, 'Error creating marca».'.yellow.bold); + faileds++; + }); + await fillOS() + .then(() => { + console.log(symbols.success, '«OS» filled out.'.green.bold) + ok++; + }) + .catch(() => { + console.log(symbols.warning, 'Error creating «OS».'.yellow.bold); + faileds++; + }); + await fillTipo() + .then(() => { + console.log(symbols.success, '«tipo» filled out.'.green.bold) + ok++; + }) + .catch(() => { + console.log(symbols.warning, 'Error creating «tipo».'.yellow.bold); + faileds++; + }); + await fillUResponsable() + .then((records) => { + console.log(symbols.success, `${ records } records filled out.`.green.bold) + ok++; + }) + .catch(() => { + console.log(symbols.warning, 'Error creating «uResponsable».'.yellow.bold); + faileds++; + }); + await fillUbicacion() + .then(() => { + console.log(symbols.success, '«ubicacion» filled out.'.green.bold) + ok++; + }) + .catch(() => { + console.log(symbols.warning, 'Error creating «ubicacion».'.yellow.bold); + faileds++; + }); + await fillUso() + .then(() => { + console.log(symbols.success, '«uso» filled out.'.green.bold) + ok++; + }) + .catch(() => { + console.log(symbols.warning, 'Error creating «uso».'.yellow.bold); + faileds++; + }); - console.log(symbols.info, "Filling up database...".blue.bold); + console.log(`\nFilling out ${ rows } records on equipo, printers and inventario. Please wait...\n`.cyan.italic.bold); - for (let i = 0; i < rows; i++) { - console.log(`Creating record ${i + 1}/${rows}.`.yellow); - await fillingUp(); - } - console.log(symbols.success, `${ rows } records created succesfully.`.green.bold); + await fillingEquipo() + .then(() => { + console.log(symbols.success, `${ rows } records created on equipo.\n`.green.bold); + ok++; + }) + .catch((e) => { + console.log(symbols.warning, 'Error creating «equipo».\n', e); + faileds++; + }); + await fillingPrinters() + .then(() => { + console.log(symbols.success, `${ rows } records created on printers.\n`.green.bold); + ok++; + }) + .catch((e) => { + console.log(symbols.warning, 'Error creating «printers».\n', e); + faileds++; + }); + + if (censo / 2 === rows) ok++; + else faileds++; + + console.log(symbols.success, `${ censo } records added on inventario`.green.bold); + console.log(`\n${ symbols.success }`, ` ${ ok } tables filled out succesfully.`.green.bold); + console.log(symbols.error, ` ${ faileds } tables wasn't filled out successfully.`.red.bold); + + process.exit(); } exec(); \ No newline at end of file diff --git a/helpers/tables/ActivoFijo.js b/helpers/tables/ActivoFijo.js new file mode 100644 index 0000000..6f3afae --- /dev/null +++ b/helpers/tables/ActivoFijo.js @@ -0,0 +1,31 @@ +const ActivoFijo = require('../../server/models/tablas/ActivoFijo'); + +async function fillActivoFijo() { + console.log('\n\tFilling out «activoFijo».'.cyan.italic.bold); + let af = [ + "PC", + "Laptop", + "Servidor", + "Ipad", + "Chromebook", + "Impresora" + ]; + let count = 1; + let limit = 6; + + for (activoFijo of af) { + await ActivoFijo.create({ + activoFijo + }) + .then(() => { + console.log(`${ count }/${ limit }\trecords created.`); + count++; + }) + .catch(() => { + throw new Error() + }); + }; + +}; + +module.exports = fillActivoFijo; \ No newline at end of file diff --git a/helpers/tables/DescripcionAdicional.js b/helpers/tables/DescripcionAdicional.js new file mode 100644 index 0000000..bd08f9c --- /dev/null +++ b/helpers/tables/DescripcionAdicional.js @@ -0,0 +1,16 @@ +const DescripcionAdicional = require('../../server/models/tablas/DescripcionAdicional'); + +const faker = require('faker'); +faker.locale = "es_MX"; + +async function fillDA() { + let da = faker.lorem.sentence(); + + // console.log("Descripción adicional: ", da); + + await DescripcionAdicional.create({ + descripcion: da + }); +}; + +module.exports = fillDA; \ No newline at end of file diff --git a/helpers/tables/Equipo.js b/helpers/tables/Equipo.js new file mode 100644 index 0000000..784f6f5 --- /dev/null +++ b/helpers/tables/Equipo.js @@ -0,0 +1,79 @@ +const Equipo = require('../../server/models/tablas/Equipo'); + +const faker = require('faker'); +faker.locale = "es_MX"; + +async function fillEquipo(noInventario, idActivoFijo) { + let modelo = faker.vehicle.model(); + let noSerie = faker.vehicle.vin(); + let idMarca = faker.random.number({ + min: 1, + max: 11 + }); + let idOS = faker.random.number({ + min: 1, + max: 7 + }); + let procesador = faker.random.arrayElement([ + "Intel Core i3", + "Intel Core i5", + "Intel Core i7", + "Ryzen 3", + "Ryzen 5", + "Ryzen 7", + ]); + let vProcesador = faker.random.number({ min: 2000, max: 4500 }) + let memoria = faker.random.arrayElement([ + "DDR2", + "DDR3", + "DDR4" + ]); + let memoriasz = faker.random.arrayElement([ + 4096, + 2048, + 8192 + ]); + let vMemoria = faker.random.number({ min: 1400, max: 1800, precision: 4 }); + let graficos = faker.random.arrayElement([ + "Intel HD Graphics", + "Intel Iris", + "Intel Iris Plus", + "Radeon Vega 8", + "Radeon Vega 7", + "Radeon Vega Plus", + "Radeon Vega Graphics", + ]); + let hdd = faker.random.number({ + min: 80, + max: 990, + precision: 2 + }); + + // console.log("Modelo: ", modelo, "\nNúmero de serie: ", noSerie, "\nProcesador: ", procesador, "\nVelocidad de procesador: ", vProcesador, "\nMemoria: ", memoria, "\nCantidad de memoria: ", memoriasz, "\nVelocidad de memoria: ", vMemoria, "\nGráficos: ", graficos, "\nTamaño de almacenamiento: ", hdd); + + await Equipo.create({ + modelo, + noSerie, + procesador, + vProcesador, + memoria, + memoriasz, + vMemoria, + graficos, + hdd, + noInventario, + idMarca, + idOS + // idDescripcion + // idActivoFijo + }) + .then(() => { + // console.log(`${ count }/${ limit }\trecords created.`); + // count++; + }) + .catch(() => { + throw new Error(); + }); +}; + +module.exports = fillEquipo; \ No newline at end of file diff --git a/helpers/tables/Inventario.js b/helpers/tables/Inventario.js new file mode 100644 index 0000000..2c3a10e --- /dev/null +++ b/helpers/tables/Inventario.js @@ -0,0 +1,39 @@ +const Inventario = require('../../server/models/tablas/Inventario'); + +const faker = require('faker'); +faker.locale = "es_MX"; + +async function fillInventario(noInventario, idActivoFijo) { + let idUbicacion = faker.random.number({ + min: 1, + max: 15 + }); + let idUnidadResponsable = faker.random.number({ + min: 1, + max: 101 + }); + let idUso = faker.random.number({ + min: 1, + max: 6 + }); + let noResguardo = faker.phone.phoneNumber("#####") + // console.log("Inventario: ", noInventario, "\nResguardo: ", noResguardo); + + await Inventario.create({ + noResguardo, + idActivoFijo, + noInventario, + idUnidadResponsable, + idUbicacion, + idUso + }) + .then(() => { + // console.log(`${ count }/${ limit }\trecords created.`); + // count++; + }) + .catch(() => { + throw new Error(); + }); +}; + +module.exports = fillInventario; \ No newline at end of file diff --git a/helpers/tables/Marca.js b/helpers/tables/Marca.js new file mode 100644 index 0000000..c6c4b5c --- /dev/null +++ b/helpers/tables/Marca.js @@ -0,0 +1,36 @@ +const Marca = require('../../server/models/tablas/Marca'); + +async function fillMarca() { + let count = 1; + let limit = 11; + let marcas = [ + "HP", + "ECOIN", + "SONY", + "LENOVO", + "DELL", + "ACER", + "ASUS", + "APPLE", + "COMPAQ", + "GATEWAY", + "IBM" + ]; + + console.log('\n\tFilling out «marca».'.cyan.italic.bold); + + for (marca of marcas) { + await Marca.create({ + marca + }) + .then(() => { + console.log(`${ count }/${ limit }\trecords created.`); + count++; + }) + .catch(() => { + throw new Error(); + }); + }; +}; + +module.exports = fillMarca; \ No newline at end of file diff --git a/helpers/tables/OS.js b/helpers/tables/OS.js new file mode 100644 index 0000000..c1e6023 --- /dev/null +++ b/helpers/tables/OS.js @@ -0,0 +1,32 @@ +const OS = require('../../server/models/tablas/OS'); + +async function fillOS() { + let count = 1; + let limit = 7; + let sistemas = [ + "Windows 7", + "Windows 10", + "Debian", + "Fedora", + "CentOS", + "Ubuntu", + "MacOS" + ]; + + console.log('\n\tFilling out «OS».'.cyan.italic.bold); + + for (osname of sistemas) { + await OS.create({ + osname + }) + .then(() => { + console.log(`${ count }/${ limit }\trecords created.`); + count++; + }) + .catch(() => { + throw new Error(); + }); + }; +}; + +module.exports = fillOS; \ No newline at end of file diff --git a/helpers/tables/Printers.js b/helpers/tables/Printers.js new file mode 100644 index 0000000..c493b78 --- /dev/null +++ b/helpers/tables/Printers.js @@ -0,0 +1,26 @@ +const Printers = require('../../server/models/tablas/Printers'); + +const faker = require('faker'); +faker.locale = "es_MX"; + +async function fillPrinters(noInventario) { + let noSerie = faker.vehicle.vin(); + let idMarca = faker.random.number({ + min: 1, + max: 11 + }); + let idTipo = faker.random.number({ + min: 1, + max: 4 + }); + // console.log("Número de serie impresora: ", noSerie); + + await Printers.create({ + noInventario, + noSerie, + idMarca, + idTipo + }); +}; + +module.exports = fillPrinters; \ No newline at end of file diff --git a/helpers/tables/Tipo.js b/helpers/tables/Tipo.js new file mode 100644 index 0000000..63517da --- /dev/null +++ b/helpers/tables/Tipo.js @@ -0,0 +1,29 @@ +const Tipo = require('../../server/models/tablas/Tipo'); + +async function fillTipo() { + let count = 1; + let limit = 4; + let tipos = [ + "Impresora", + "Multifuncional", + "Láser", + "Plotter" + ]; + + console.log('\n\tFilling out «tipo».'.cyan.italic.bold); + + for (tipo of tipos) { + await Tipo.create({ + tipo + }) + .then(() => { + console.log(`${ count }/${ limit }\trecords created.`); + count++; + }) + .catch(() => { + throw new Error(); + }); + }; +}; + +module.exports = fillTipo; \ No newline at end of file diff --git a/helpers/tables/UResponsable.js b/helpers/tables/UResponsable.js new file mode 100644 index 0000000..f4930ed --- /dev/null +++ b/helpers/tables/UResponsable.js @@ -0,0 +1,25 @@ +const UResponsable = require('../../server/models/tablas/UResponsable'); + +const faker = require('faker'); +faker.locale = 'es_MX'; + +async function fillUResponsable() { + let unidades = require('./unidades.json'); + let nombreResponsable = ''; + + console.log(`\n\tFilling out with ${ unidades.length } records on uResponsable, please wait...`.cyan.italic.bold); + + for (uResponsable of unidades) { + nombreResponsable = faker.name.findName(); + await UResponsable.create({ + uResponsable, + nombreResponsable + }) + .catch(() => { + throw new Error(); + }); + }; + return unidades.length; +}; + +module.exports = fillUResponsable; \ No newline at end of file diff --git a/helpers/tables/Ubicacion.js b/helpers/tables/Ubicacion.js new file mode 100644 index 0000000..69b2b9e --- /dev/null +++ b/helpers/tables/Ubicacion.js @@ -0,0 +1,27 @@ +const Ubicacion = require('../../server/models/tablas/Ubicacion'); + +const faker = require('faker'); +faker.locale = "es_MX"; + +async function fillUbicacion() { + let ubicaciones = require('./ubicaciones'); + let count = 1; + let limit = 15; + + console.log('\n\tFilling out «ubicacion».'.cyan.italic.bold); + + for (ubicacion of ubicaciones) { + await Ubicacion.create({ + ubicacion + }) + .then(() => { + console.log(`${ count }/${ limit }\trecords created.`); + count++; + }) + .catch(() => { + throw new Error(); + }); + }; +}; + +module.exports = fillUbicacion; \ No newline at end of file diff --git a/helpers/tables/Uso.js b/helpers/tables/Uso.js new file mode 100644 index 0000000..2a8bf8c --- /dev/null +++ b/helpers/tables/Uso.js @@ -0,0 +1,24 @@ +const Uso = require('../../server/models/tablas/Uso'); + +async function fillUso() { + let usos = require('./usos.json'); + + let count = 1; + let limit = 6; + + console.log('\n\tFilling out «uso».'.cyan.italic.bold); + + for (uso of usos) { + await Uso.create({ + uso + }) + .then(() => { + console.log(`${ count }/${ limit }\trecords created.`); + count++; + }) + .catch(() => { + throw new Error(); + }); + }; +} +module.exports = fillUso; \ No newline at end of file diff --git a/helpers/tables/ubicaciones.json b/helpers/tables/ubicaciones.json new file mode 100644 index 0000000..d29819c --- /dev/null +++ b/helpers/tables/ubicaciones.json @@ -0,0 +1,17 @@ +[ + "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" +] \ No newline at end of file diff --git a/helpers/unidades.json b/helpers/tables/unidades.json similarity index 94% rename from helpers/unidades.json rename to helpers/tables/unidades.json index 60d3386..d2b755b 100644 --- a/helpers/unidades.json +++ b/helpers/tables/unidades.json @@ -70,10 +70,6 @@ "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", - "NO APLICA, LOS BIENES FUERON DADOS DE BAJA", - "PAIDI (DEVOLVER LOS BIENES AL ALMACÉN AL TÉRMINO DEL PROYECTO", - "LOS BIENES DEBEN SER DEVUELTOS AL ALMACÉN AL TERMINAR EL PROYECTO", - "LOS BIENES DEBEN SER DEVUELTOS AL ALMACÉN AL TERMINAR EL PROYECTO", "PROGRAMA DE ACTUARÍA", "PROGRAMA DE ARQUITECTURA", "PROGRAMA DE COMUNICACIÓN", diff --git a/helpers/tables/usos.json b/helpers/tables/usos.json new file mode 100644 index 0000000..ed1364f --- /dev/null +++ b/helpers/tables/usos.json @@ -0,0 +1 @@ +["Analista","Estratega","Especialista","Product Owner","Asistente","Gerente"] \ No newline at end of file diff --git a/package.json b/package.json index 4cd195e..3afd887 100644 --- a/package.json +++ b/package.json @@ -32,4 +32,4 @@ "gmail-send": "^1.8.10", "nodemon": "^2.0.4" } -} \ No newline at end of file +} diff --git a/scratch/token b/scratch/token index 6b795b2..cec4563 100644 --- a/scratch/token +++ b/scratch/token @@ -1 +1 @@ -eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7ImlkQWRtaW4iOjQsIm5hbWUiOiJhbGltYSIsInVzZXJOYW1lIjoiQWxmcmVkbyBMaW1hIiwicGFzc3dvcmQiOiIkMmIkMTAka2dFcmlRN1MwbGdsU0YzakdYZ0hEdXNIblNJbFh1T3pHc3JILjR1SGI3N1JLY1c1TUpELksiLCJpc0FkbWluIjp0cnVlLCJjcmVhdGVkQXQiOiIyMDIwLTA4LTI1VDE4OjQ2OjAwLjAwMFoiLCJ1cGRhdGVkQXQiOiIyMDIwLTA4LTI1VDE4OjQ2OjAwLjAwMFoifSwiaWF0IjoxNTk5NDQ0NTA5LCJleHAiOjE1OTk1MzA5MDl9.edj4jwFw0uAyJn92UB6LsuC-STAu0hJC-sb3T0ncReQ \ No newline at end of file +eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7ImlkQWRtaW4iOjIsIm5hbWUiOiJhbGZyZWRvLmxpbWFAYWNhdGxhbi51bmFtLm14IiwidXNlck5hbWUiOiJBbGZyZWRvIExpbWEiLCJwYXNzd29yZCI6IiQyYiQxMCRrZ0VyaVE3UzBsZ2xTRjNqR1hnSER1c0huU0lsWHVPekdzckguNHVIYjc3UktjVzVNSkQuSyIsImlzQWRtaW4iOmZhbHNlLCJjcmVhdGVkQXQiOiIyMDIwLTA4LTI1VDE4OjQzOjM5LjAwMFoiLCJ1cGRhdGVkQXQiOiIyMDIwLTA4LTI1VDE4OjQzOjM5LjAwMFoifSwiaWF0IjoxNTk5NjAwNjc2LCJleHAiOjE1OTk2ODcwNzZ9.o6fZL839jIktsgd1Y8Xrd8uPMOnhjEv9783PBhl7-Bk \ No newline at end of file diff --git a/server/controller/api/computers.js b/server/controller/api/computers.js new file mode 100644 index 0000000..cbbe108 --- /dev/null +++ b/server/controller/api/computers.js @@ -0,0 +1,23 @@ +const activoFijo = require('../../models/tablas/ActivoFijo'); +const DescripcionAdicional = require('../../models/tablas/DescripcionAdicional'); +const Equipo = require('../../models/tablas/Equipo'); +const Inventario = require('../../models/tablas/Inventario'); +const Marca = require('../../models/tablas/Marca'); +const OS = require('../../models/tablas/OS'); +const Printers = require('../../models/tablas/Printers'); +const Tipo = require('../../models/tablas/Tipo'); +const Ubicacion = require('../../models/tablas/Ubicacion'); +const UResponsable = require('../../models/tablas/UResponsable'); +const Uso = require('../../models/tablas/Uso'); + +const jwt = require('jsonwebtoken'); + +const computers = (req, res) => { + // res.json({ + // message: "Listo" + // }); + + +} + +module.exports = computers; \ No newline at end of file diff --git a/server/middlewares/authentication.js b/server/middlewares/authentication.js index 71731cd..7eadeb3 100644 --- a/server/middlewares/authentication.js +++ b/server/middlewares/authentication.js @@ -2,13 +2,13 @@ const jwt = require('jsonwebtoken'); const verifyToken = (req, res, next) => { - if (typeof localStorage === "undefined" || localStorage === null) { - var LocalStorage = require('node-localstorage').LocalStorage; - localStorage = new LocalStorage('./scratch'); - } - let localToken = localStorage.getItem('token'); + // if (typeof localStorage === "undefined" || localStorage === null) { + // var LocalStorage = require('node-localstorage').LocalStorage; + // localStorage = new LocalStorage('./scratch'); + // } + // let localToken = localStorage.getItem('token'); - console.log(localToken); + let localToken = req.get('token'); jwt.verify(localToken, process.env.TOKEN_SEED, (err, decoded) => { if (err) { @@ -22,7 +22,25 @@ const verifyToken = (req, res, next) => { req.user = decoded.user; next(); - }) + }); + } -module.exports = verifyToken; \ No newline at end of file +const verifyAdmin = (req, res, next) => { + let isAdmin = !!req.user.isAdmin; + + if (!isAdmin) { + return res.status(401).json({ + err: { + message: 'Is not admin.' + } + }) + }; + + next(); +} + +module.exports = { + verifyToken, + verifyAdmin +}; \ No newline at end of file diff --git a/server/models/install.js b/server/models/install.js index d26cc5b..020df0b 100644 --- a/server/models/install.js +++ b/server/models/install.js @@ -28,8 +28,6 @@ async function remove() { console.log(logSymbols.success, "impresoras"); await inventario.drop(); console.log(logSymbols.success, "inventario"); - await admin.drop(); - console.log(logSymbols.success, "admin"); await os.drop(); console.log(logSymbols.success, "os"); await activofijo.drop(); @@ -101,6 +99,12 @@ async function createFirstUsers() { isAdmin: true }); + await admin.create({ + name: 'billie', + userName: 'Billie', + password: bcrypt.hashSync('contraseña', 10) + }); + } async function exec() { diff --git a/server/models/tablas/ActivoFijo.js b/server/models/tablas/ActivoFijo.js index 530dc7a..32e81b0 100644 --- a/server/models/tablas/ActivoFijo.js +++ b/server/models/tablas/ActivoFijo.js @@ -12,6 +12,7 @@ ActivoFijo.init({ activoFijo: { type: Sequelize.CHAR, allowNull: false, + unique: true }, }, { sequelize, diff --git a/server/models/tablas/Equipo.js b/server/models/tablas/Equipo.js index 5c79020..54e0a28 100644 --- a/server/models/tablas/Equipo.js +++ b/server/models/tablas/Equipo.js @@ -1,3 +1,4 @@ +const ActivoFIjo = require("./ActivoFijo"); const Sequelize = require("sequelize"); const sequelize = require("../../config/sequelize.conf"); const Inventario = require("./Inventario"); @@ -56,7 +57,7 @@ Equipo.init({ Inventario.hasOne(Equipo, { foreignKey: 'noInventario' }); Marca.hasOne(Equipo, { foreignKey: 'idMarca' }); -DescripcionAdicional.hasOne(Equipo, { foreignKey: 'idDescripcion' }); +// DescripcionAdicional.hasOne(Equipo, { foreignKey: 'idDescripcion' }); OS.hasOne(Equipo, { foreignKey: 'idOS' }); module.exports = Equipo; \ No newline at end of file diff --git a/server/models/tablas/Inventario.js b/server/models/tablas/Inventario.js index cb95b03..0e18400 100644 --- a/server/models/tablas/Inventario.js +++ b/server/models/tablas/Inventario.js @@ -13,6 +13,7 @@ Inventario.init({ type: Sequelize.CHAR, primaryKey: true, allowNull: false, + unique: true }, noResguardo: { type: Sequelize.INTEGER, diff --git a/server/models/tablas/Marca.js b/server/models/tablas/Marca.js index 75a98fa..635be40 100644 --- a/server/models/tablas/Marca.js +++ b/server/models/tablas/Marca.js @@ -12,6 +12,7 @@ Marca.init({ marca: { type: Sequelize.CHAR, allowNull: false, + unique: true }, }, { sequelize, diff --git a/server/models/tablas/OS.js b/server/models/tablas/OS.js index 7f19d57..70b9e75 100644 --- a/server/models/tablas/OS.js +++ b/server/models/tablas/OS.js @@ -12,6 +12,7 @@ OS.init({ osname: { type: Sequelize.CHAR, allowNull: false, + unique: true }, }, { sequelize, diff --git a/server/models/tablas/Printers.js b/server/models/tablas/Printers.js index 0f3fa7a..0496408 100644 --- a/server/models/tablas/Printers.js +++ b/server/models/tablas/Printers.js @@ -16,6 +16,10 @@ Printers.init({ type: Sequelize.CHAR, allowNull: false, }, + // modelo: { + // type: Sequelize.CHAR, + + // }, }, { sequelize, tableName: "printers", diff --git a/server/models/tablas/Tipo.js b/server/models/tablas/Tipo.js index b64b2ae..bf0d81c 100644 --- a/server/models/tablas/Tipo.js +++ b/server/models/tablas/Tipo.js @@ -12,6 +12,7 @@ Tipo.init({ tipo: { type: Sequelize.CHAR, allowNull: false, + unique: true }, }, { sequelize, diff --git a/server/models/tablas/UResponsable.js b/server/models/tablas/UResponsable.js index 96a2feb..7074446 100644 --- a/server/models/tablas/UResponsable.js +++ b/server/models/tablas/UResponsable.js @@ -12,6 +12,7 @@ UResponsable.init({ uResponsable: { type: Sequelize.CHAR, allowNull: false, + unique: true }, nombreResponsable: { type: Sequelize.CHAR, diff --git a/server/models/tablas/Ubicacion.js b/server/models/tablas/Ubicacion.js index abfc69e..7a08ed8 100644 --- a/server/models/tablas/Ubicacion.js +++ b/server/models/tablas/Ubicacion.js @@ -12,6 +12,7 @@ Ubicacion.init({ ubicacion: { type: Sequelize.CHAR, allowNull: false, + unique: true }, }, { sequelize, diff --git a/server/models/tablas/Uso.js b/server/models/tablas/Uso.js index 1a9d3a8..8328640 100644 --- a/server/models/tablas/Uso.js +++ b/server/models/tablas/Uso.js @@ -12,6 +12,7 @@ Uso.init({ uso: { type: Sequelize.CHAR, allowNull: false, + unique: true }, }, { sequelize, diff --git a/server/routes/index.js b/server/routes/index.js index 5686022..10357c5 100644 --- a/server/routes/index.js +++ b/server/routes/index.js @@ -1,6 +1,7 @@ let express = require("express"); let app = express(); -app.use(require('./login')) +app.use(require('./login')); +app.use(require('./user')); -module.exports = app \ No newline at end of file +module.exports = app; \ No newline at end of file diff --git a/server/routes/login.js b/server/routes/login.js index 11ab44f..5545700 100644 --- a/server/routes/login.js +++ b/server/routes/login.js @@ -6,7 +6,6 @@ const route = '/login' //logica del login, ejemplo let post = require('../controller/login/post'); -const Admin = require("../models/tablas/Admin"); //let get = require('../controller/login/get') app.post(route, async(req, res) => { @@ -15,4 +14,4 @@ app.post(route, async(req, res) => { }); -module.exports = app \ No newline at end of file +module.exports = app; \ No newline at end of file diff --git a/server/routes/user.js b/server/routes/user.js new file mode 100644 index 0000000..6a57b05 --- /dev/null +++ b/server/routes/user.js @@ -0,0 +1,14 @@ +let express = require('express'); +let app = express(); + +const route = '/api/computers'; +const computers = require('../controller/api/computers'); +const { verifyToken, verifyAdmin } = require('../middlewares/authentication'); + +app.get(route, verifyToken, (req, res) => { + + return computers(req, res); + +}); + +module.exports = app; \ No newline at end of file