43 lines
1.2 KiB
JavaScript
43 lines
1.2 KiB
JavaScript
const UResponsable = require('../../server/models/tablas/UResponsable');
|
|
const progress = require('cli-progress');
|
|
const colors = require('colors');
|
|
|
|
const faker = require('faker');
|
|
faker.locale = 'es_MX';
|
|
|
|
async function fillUResponsable() {
|
|
let unidades = require('./unidades.json');
|
|
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',
|
|
barIncompleteChar: '\u2591',
|
|
hideCursor: true,
|
|
stopOnComplete: true,
|
|
barsize: 30,
|
|
align: 'right'
|
|
});
|
|
|
|
console.log(`\n\tFilling out with ${ limit } records on uResponsable, please wait...`.cyan.italic.bold);
|
|
|
|
bar.start(limit, 0);
|
|
for (uResponsable of unidades) {
|
|
nombreResponsable = nombres[count];
|
|
await UResponsable.create({
|
|
uResponsable,
|
|
nombreResponsable
|
|
})
|
|
.catch(() => {
|
|
bar.stop();
|
|
throw new Error();
|
|
});
|
|
bar.increment();
|
|
count++;
|
|
};
|
|
return limit;
|
|
};
|
|
|
|
module.exports = fillUResponsable; |