- Gruppi si chiamano ora "Organizzazioni".
- Categorie dei Gruppi aggiornate. - Email ora compare sul profilo se non hai telegram e anche sugli annunci.
This commit is contained in:
@@ -17,11 +17,11 @@ module.exports = {
|
||||
const mydbfile = require(pathfile);
|
||||
|
||||
if (mydbfile && mydbfile.list) {
|
||||
return table.insertMany(mydbfile.list, {ordered: false}).
|
||||
then((ris) => {
|
||||
console.log('Populate table ', tablename);
|
||||
return !!ris;
|
||||
});
|
||||
return table.insertMany(mydbfile.list, { ordered: false }).
|
||||
then((ris) => {
|
||||
console.log('Populate table ', tablename);
|
||||
return !!ris;
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
@@ -31,52 +31,62 @@ module.exports = {
|
||||
},
|
||||
|
||||
async insertIntoDb_NoDuplicate(attiva, tablename, table, field) {
|
||||
|
||||
let numrec = 0;
|
||||
let numupdated = 0;
|
||||
try {
|
||||
|
||||
if (!attiva && await table.countDocuments({}) > 0)
|
||||
return;
|
||||
if (!attiva && await table.countDocuments({}) > 0) return;
|
||||
|
||||
const pathfile = Path.join(__dirname, tablename + '.js');
|
||||
if (tools.isFileExists(pathfile)) {
|
||||
|
||||
const mydbfile = require(pathfile);
|
||||
|
||||
if (mydbfile && mydbfile.list) {
|
||||
for (const rec of mydbfile.list) {
|
||||
let obj = {};
|
||||
obj[field] = rec[field];
|
||||
let query = {};
|
||||
query[field] = rec[field];
|
||||
|
||||
var mynewrec = new table(rec);
|
||||
|
||||
if (rec.hasOwnProperty('idapp')) {
|
||||
obj.idapop = rec['idapp'];
|
||||
if (rec.hasOwnProperty('_id')) {
|
||||
query._id = rec._id;
|
||||
}
|
||||
|
||||
const exist = await table.find(obj);
|
||||
if (exist.length <= 0) {
|
||||
try {
|
||||
const ris = await mynewrec.save();
|
||||
if (ris) {
|
||||
if (rec.hasOwnProperty('idapp')) {
|
||||
query.idapp = rec.idapp;
|
||||
}
|
||||
|
||||
try {
|
||||
const existingDoc = await table.findOne(query);
|
||||
if (!existingDoc) {
|
||||
|
||||
const { value: existingDoc, upserted } = await table.findOneAndUpdate(
|
||||
query,
|
||||
{ $set: rec },
|
||||
{ upsert: true, new: true }
|
||||
);
|
||||
|
||||
if (upserted) {
|
||||
// Il documento non esisteva, è stato creato
|
||||
console.log('Inserted document with _id:', existingDoc._id);
|
||||
numrec++;
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('error ', e);
|
||||
}
|
||||
|
||||
} else {
|
||||
// Il documento esiste, lo aggiorniamo
|
||||
await table.updateOne({ _id: existingDoc._id }, { $set: rec });
|
||||
numupdated++;
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('Error processing record:', e);
|
||||
}
|
||||
}
|
||||
|
||||
if (numrec > 0)
|
||||
console.log('*** Insert', numrec, 'record on ' + tablename);
|
||||
|
||||
if (numrec > 0 || numupdated > 0) {
|
||||
console.log(`*** Inserted ${numrec} and updated ${numupdated} records in ${tablename}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('error insertIntoDb', e);
|
||||
console.log('Error in insertIntoDb_NoDuplicate:', e);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
async rewriteTable(table) {
|
||||
@@ -85,15 +95,15 @@ module.exports = {
|
||||
let field = '';
|
||||
|
||||
try {
|
||||
const {City} = require('../models/city');
|
||||
const {Province} = require('../models/province');
|
||||
const {Sector} = require('../models/sector');
|
||||
const {SectorGood} = require('../models/sectorgood');
|
||||
const {Skill} = require('../models/skill');
|
||||
const {Good} = require('../models/good');
|
||||
const { City } = require('../models/city');
|
||||
const { Province } = require('../models/province');
|
||||
const { Sector } = require('../models/sector');
|
||||
const { SectorGood } = require('../models/sectorgood');
|
||||
const { Skill } = require('../models/skill');
|
||||
const { Good } = require('../models/good');
|
||||
// const {SubSkill} = require('../models/subskill');
|
||||
const {Contribtype} = require('../models/contribtype');
|
||||
const {Level} = require('../models/level');
|
||||
const { Contribtype } = require('../models/contribtype');
|
||||
const { Level } = require('../models/level');
|
||||
|
||||
if (table === 'cities') {
|
||||
mytab = City;
|
||||
@@ -127,11 +137,11 @@ module.exports = {
|
||||
if (mytab) {
|
||||
await mytab.collection.drop();
|
||||
// mongoose.connection.db.dropCollection(table, function(err) {
|
||||
console.log('Delete ', table);
|
||||
// await mytab.remove({});
|
||||
console.log('Delete ', table);
|
||||
// await mytab.remove({});
|
||||
|
||||
this.insertIntoDb_NoDuplicate(false, table, mytab, field);
|
||||
// });
|
||||
this.insertIntoDb_NoDuplicate(false, table, mytab, field);
|
||||
// });
|
||||
}
|
||||
return true;
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user