Files

43 lines
1.2 KiB
JavaScript
Raw Permalink Normal View History

2020-09-10 03:06:23 -05:00
const UResponsable = require('../../server/models/tablas/UResponsable');
2020-09-11 00:27:05 -05:00
const progress = require('cli-progress');
const colors = require('colors');
2020-09-10 03:06:23 -05:00
const faker = require('faker');
faker.locale = 'es_MX';
async function fillUResponsable() {
let unidades = require('./unidades.json');
2020-10-06 19:56:55 -05:00
var nombres = require('./nombres.json');
2020-09-11 00:27:05 -05:00
let limit = unidades.length;
2020-10-06 19:56:55 -05:00
let count = 0;
2020-09-11 00:27:05 -05:00
const bar = new progress.SingleBar({
format: 'uResponsable |' + colors.cyan('{bar}') + '| {percentage}%' + ' || {value}/{total} records created.',
barCompleteChar: '\u2588',
barIncompleteChar: '\u2591',
hideCursor: true,
stopOnComplete: true,
barsize: 30,
align: 'right'
});
2020-09-10 03:06:23 -05:00
2020-09-11 00:27:05 -05:00
console.log(`\n\tFilling out with ${ limit } records on uResponsable, please wait...`.cyan.italic.bold);
2020-09-10 03:06:23 -05:00
2020-09-11 00:27:05 -05:00
bar.start(limit, 0);
2020-09-10 03:06:23 -05:00
for (uResponsable of unidades) {
2020-10-06 19:56:55 -05:00
nombreResponsable = nombres[count];
2020-09-10 03:06:23 -05:00
await UResponsable.create({
uResponsable,
nombreResponsable
})
.catch(() => {
2020-09-11 00:27:05 -05:00
bar.stop();
2020-09-10 03:06:23 -05:00
throw new Error();
});
2020-09-11 00:27:05 -05:00
bar.increment();
2020-10-06 19:56:55 -05:00
count++;
2020-09-10 03:06:23 -05:00
};
2020-09-11 00:27:05 -05:00
return limit;
2020-09-10 03:06:23 -05:00
};
module.exports = fillUResponsable;