222 lines
7.4 KiB
JavaScript
222 lines
7.4 KiB
JavaScript
const fillActivoFijo = require('./tables/ActivoFijo');
|
|
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";
|
|
|
|
const colors = require('colors');
|
|
const symbols = require('log-symbols');
|
|
const progress = require('cli-progress');
|
|
const Inventario = require('../server/models/tablas/Inventario');
|
|
|
|
let rows = 100;
|
|
let faileds = 0;
|
|
let ok = 0;
|
|
let censo = 0;
|
|
|
|
async function fillingEquipo() {
|
|
let count = 1;
|
|
let barinventario = new progress.SingleBar({
|
|
format: 'inventario [' + colors.cyan('{bar}') + '] {percentage}%' + '|| {value}/{total} records created.',
|
|
barCompleteChar: '\u2588',
|
|
barIncompleteChar: '\u2591',
|
|
hideCursor: true,
|
|
stopOnComplete: true,
|
|
barsize: 30,
|
|
align: 'right'
|
|
});
|
|
let barequipo = new progress.SingleBar({
|
|
format: 'equipo [' + colors.cyan('{bar}') + '] {percentage}%' + '|| {value}/{total} records created.',
|
|
barCompleteChar: '\u2588',
|
|
barIncompleteChar: '\u2591',
|
|
hideCursor: true,
|
|
stopOnComplete: true,
|
|
barsize: 30,
|
|
align: 'right'
|
|
});
|
|
barinventario.start(rows, 0);
|
|
barequipo.start(rows, 0);
|
|
for (let i = 0; i < rows; i++) {
|
|
let noInventario = faker.phone.phoneNumber("2######");
|
|
let idActivoFijo = idUso = faker.random.number({
|
|
min: 1,
|
|
max: 5
|
|
});
|
|
|
|
await fillInventario(noInventario, idActivoFijo)
|
|
.then(() => censo++)
|
|
.catch(() => {
|
|
console.log(symbols.warning, 'Error creating «inventario-equipo»');
|
|
barinventario.stop();
|
|
throw new Error();
|
|
});
|
|
await fillEquipo(noInventario, idActivoFijo)
|
|
.catch(async() => {
|
|
await Inventario.destroy({
|
|
where: noInventario
|
|
})
|
|
then(() => censo--);
|
|
console.log(symbols.warning, 'Error creating «equipo»');
|
|
barequipo.stop();
|
|
throw new Error();
|
|
});
|
|
barinventario.increment();
|
|
barequipo.increment();
|
|
}
|
|
return;
|
|
}
|
|
|
|
async function fillingPrinters() {
|
|
let pInventario = new progress.SingleBar({
|
|
format: 'inventario [' + colors.cyan('{bar}') + '] {percentage}%' + '|| {value}/{total} records created.',
|
|
barCompleteChar: '\u2588',
|
|
barIncompleteChar: '\u2591',
|
|
hideCursor: true,
|
|
stopOnComplete: true,
|
|
barsize: 30,
|
|
align: 'right'
|
|
});
|
|
let barprinters = new progress.SingleBar({
|
|
format: 'printers [' + colors.cyan('{bar}') + '] {percentage}%' + '|| {value}/{total} records created.',
|
|
barCompleteChar: '\u2588',
|
|
barIncompleteChar: '\u2591',
|
|
hideCursor: true,
|
|
stopOnComplete: true,
|
|
barsize: 30,
|
|
align: 'right'
|
|
});
|
|
pInventario.start(rows, 0);
|
|
barprinters.start(rows, 0);
|
|
for (let i = 1; i <= rows; i++) {
|
|
let noInventario = faker.phone.phoneNumber("2######");
|
|
let idActivoFijo = 6;
|
|
|
|
await fillInventario(noInventario, idActivoFijo)
|
|
.then(() => censo++)
|
|
.catch(() => {
|
|
console.log(symbols.warning, 'Error creating «inventario-printers»');
|
|
pInventario.stop();
|
|
throw new Error();
|
|
});
|
|
await fillPrinters(noInventario, idActivoFijo)
|
|
.catch(async() => {
|
|
await Inventario.destroy({
|
|
where: noInventario
|
|
})
|
|
.then(() => censo--);
|
|
console.log(symbols.warning, 'Error creating «printers»');
|
|
barprinters.stop();
|
|
throw new Error();
|
|
});
|
|
pInventario.increment();
|
|
barprinters.increment();
|
|
}
|
|
return;
|
|
}
|
|
|
|
async function exec() {
|
|
await fillActivoFijo()
|
|
.then(() => {
|
|
console.log(symbols.success, '«activoFijo» filled out.'.green.bold)
|
|
ok++;
|
|
})
|
|
.catch(() => {
|
|
// console.log('\n');
|
|
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(`\nFilling out ${ rows } records on equipo, printers and inventario. Please wait...\n`.cyan.italic.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(); |