Files
censo2020Back/helpers/tables/UResponsable.js
T
2020-09-11 00:27:05 -05:00

40 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');
let nombreResponsable = '';
let limit = unidades.length;
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 = faker.name.findName();
await UResponsable.create({
uResponsable,
nombreResponsable
})
.catch(() => {
bar.stop();
throw new Error();
});
bar.increment();
};
return limit;
};
module.exports = fillUResponsable;