Files
freeplanet_serverside/src/server/populate/populate.js

76 lines
1.9 KiB
JavaScript
Raw Normal View History

2022-01-23 23:25:34 +01:00
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() {
2022-02-03 00:33:15 +01:00
const abilita = false;
const scrivi_citta = false;
2022-01-23 23:25:34 +01:00
let ris = null;
2022-01-26 01:31:22 +01:00
if (abilita) {
// Sectors
const { Sector } = require('../models/sector');
this.insertIntoDb('sectors', Sector)
// CatGrps
const { CatGrp } = require('../models/catgrp');
this.insertIntoDb('catgrps', CatGrp)
2022-01-26 01:31:22 +01:00
// Skills (Competenze)
const { Skill } = require('../models/skill');
this.insertIntoDb('skills', Skill)
// SubSectors
const { SubSkill } = require('../models/subskill');
this.insertIntoDb('subskills', SubSkill)
2022-02-03 00:33:15 +01:00
// Levels
const { Level } = require('../models/level');
this.insertIntoDb('levels', Level)
// Status
const { StatusSkill } = require('../models/statusSkill');
this.insertIntoDb('statusskills', StatusSkill)
if (scrivi_citta) {
// Cities
const {City} = require('../models/city');
this.insertIntoDb('cities', City)
2022-01-26 01:31:22 +01:00
// Province
const {Province} = require('../models/province');
this.insertIntoDb('provinces', Province)
}
2022-01-26 01:31:22 +01:00
// Contribtypes
const { Contribtype } = require('../models/contribtype');
this.insertIntoDb('contribtypes', Contribtype)
}
2022-01-23 23:25:34 +01:00
},
};