55 lines
1.2 KiB
JavaScript
55 lines
1.2 KiB
JavaScript
|
|
const tools = require('../tools/general');
|
||
|
|
const Path = require('path')
|
||
|
|
|
||
|
|
module.exports = {
|
||
|
|
|
||
|
|
insertIntoDb(tablename, table) {
|
||
|
|
|
||
|
|
try {
|
||
|
|
const pathfile = Path.join(__dirname, tablename + '.js');
|
||
|
|
if (tools.isFileExists(pathfile)) {
|
||
|
|
const mydbfile = require(pathfile);
|
||
|
|
|
||
|
|
if (mydbfile && mydbfile.list) {
|
||
|
|
return table.insertMany(mydbfile.list, {ordered: false}).
|
||
|
|
then((ris) => {
|
||
|
|
console.log('Populate table ', tablename);
|
||
|
|
return !!ris;
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}catch (e){
|
||
|
|
console.log('error insertIntoDb', e);
|
||
|
|
}
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
popolaTabelleNuove() {
|
||
|
|
|
||
|
|
let ris = null;
|
||
|
|
// Sectors
|
||
|
|
const { Sector } = require('../models/sector');
|
||
|
|
this.insertIntoDb('sectors', Sector)
|
||
|
|
|
||
|
|
// Skills (Competenze)
|
||
|
|
const { Skill } = require('../models/skill');
|
||
|
|
this.insertIntoDb('skills', Skill)
|
||
|
|
|
||
|
|
// SubSectors
|
||
|
|
const { SubSkill } = require('../models/subskill');
|
||
|
|
this.insertIntoDb('subskills', SubSkill)
|
||
|
|
|
||
|
|
// Cities
|
||
|
|
const { City } = require('../models/city');
|
||
|
|
ris = this.insertIntoDb('cities', City)
|
||
|
|
|
||
|
|
// Province
|
||
|
|
const { Province } = require('../models/province');
|
||
|
|
ris = this.insertIntoDb('provinces', Province)
|
||
|
|
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
};
|
||
|
|
|