Corretto Duplicazione Sito (es: da 1 a 14)

This commit is contained in:
Paolo Arena
2022-05-14 00:31:53 +02:00
parent 6bee532b9b
commit bedd724523
12 changed files with 72 additions and 46 deletions

View File

@@ -60,6 +60,13 @@ BotSchema.statics.executeQueryTable = function(idapp, params) {
return tools.executeQueryTable(this, idapp, params); return tools.executeQueryTable(this, idapp, params);
}; };
BotSchema.statics.DuplicateAllRecords = async function (idapporig, idappdest) {
return tools.DuplicateAllRecords(this, idapporig, idappdest);
};
BotSchema.statics.findAllIdApp = async function(idapp) { BotSchema.statics.findAllIdApp = async function(idapp) {
const Bot = this; const Bot = this;

View File

@@ -4,6 +4,7 @@ const Schema = mongoose.Schema;
mongoose.Promise = global.Promise; mongoose.Promise = global.Promise;
mongoose.level = "F"; mongoose.level = "F";
const tools = require('../tools/general');
const { ObjectID } = require('mongodb'); const { ObjectID } = require('mongodb');
// Resolving error Unknown modifier: $pushAll // Resolving error Unknown modifier: $pushAll
@@ -11,7 +12,7 @@ mongoose.plugin(schema => {
schema.options.usePushEach = true schema.options.usePushEach = true
}); });
const cfgserverSchema = new Schema({ const CfgServerSchema = new Schema({
chiave: { chiave: {
type: String, type: String,
trim: true, trim: true,
@@ -28,4 +29,19 @@ const cfgserverSchema = new Schema({
}, },
}); });
mongoose.model('cfgserver', cfgserverSchema); CfgServerSchema.statics.DuplicateAllRecords = async function (idapporig, idappdest) {
return tools.DuplicateAllRecords(this, idapporig, idappdest);
};
CfgServerSchema.statics.findAllIdApp = async function(idapp) {
const myfind = { idapp };
return await CfgServer.find(myfind).lean();
};
const CfgServer = mongoose.model('CfgServer', CfgServerSchema);
module.exports = {CfgServer};

View File

@@ -91,32 +91,36 @@ SettingsSchema.statics.DuplicateAllRecords = async function (idapporig, idappdes
SettingsSchema.statics.findAllIdApp = async function (idapp, serv, crypted = false) { SettingsSchema.statics.findAllIdApp = async function (idapp, serv, crypted = false) {
const Settings = this; const Settings = this;
let myfind = ''; try {
if (serv) { let myfind = '';
myfind = {idapp, serv }; if (serv) {
} else myfind = {idapp, serv};
myfind = { idapp }; } else
myfind = {idapp};
// myfind = {...myfind, $or: [{ crypted: { $exists: false } }, { crypted: { $exists: true, $eq: crypted } }]}; // myfind = {...myfind, $or: [{ crypted: { $exists: false } }, { crypted: { $exists: true, $eq: crypted } }]};
const arrorig = await Settings.find(myfind, (err, arrrec) => { const arrorig = await Settings.find(myfind).lean();
return arrrec
});
let myarr = [] let myarr = []
if (!crypted) { if (!crypted) {
arrorig.forEach((rec) => { for (let rec of arrorig) {
if (rec.crypted) { if (rec.crypted) {
rec._doc.value_str = '' rec.value_str = ''
}
myarr.push({...rec});
} }
myarr.push({...rec._doc}); } else {
}) myarr = [...arrorig];
} else { }
myarr = [...arrorig];
return myarr;
}catch (e) {
console.error('Settings: findAllIdApp', e);
return null;
} }
return myarr;
}; };
SettingsSchema.statics.setKeyNum = async function (idapp, key, value) { SettingsSchema.statics.setKeyNum = async function (idapp, key, value) {

View File

@@ -61,9 +61,7 @@ TemplEmailSchema.statics.findAllIdApp = async function (idapp) {
const myfind = { idapp }; const myfind = { idapp };
return await TemplEmail.find(myfind, (err, arrrec) => { return TemplEmail.find(myfind).lean();
return arrrec
});
}; };

View File

@@ -1,7 +1,7 @@
const express = require('express'); const express = require('express');
const router = express.Router(); const router = express.Router();
const mongoose = require('mongoose').set('debug', false); const mongoose = require('mongoose').set('debug', false);
const cfgserver = mongoose.model('cfgserver'); const {CfgServer} = require('../models/cfgserver');
const shared_consts = require('../tools/shared_nodejs'); const shared_consts = require('../tools/shared_nodejs');
@@ -16,10 +16,10 @@ router.post('/updateval', authenticate, async (req, res) => {
idapp = req.body.idapp; idapp = req.body.idapp;
pair = req.body.pairval; pair = req.body.pairval;
return await cfgserver.findOneAndUpdate( return await CfgServer.findOneAndUpdate(
{chiave: pair.chiave, idapp, userId: pair.userId}, {$set: pair}, {chiave: pair.chiave, idapp, userId: pair.userId}, {$set: pair},
{new: false}).then((item) => { {new: false}).then((item) => {
// cfgserver.find({ chiave: pair.chiave }, (err, item) => { // CfgServer.find({ chiave: pair.chiave }, (err, item) => {
if (!!item) { if (!!item) {
res.status(200).send(); res.status(200).send();
} else { } else {

View File

@@ -15,7 +15,7 @@ const {ObjectID} = require('mongodb');
const {Graduatoria} = require('../models/graduatoria'); const {Graduatoria} = require('../models/graduatoria');
const mongoose = require('mongoose').set('debug', false); const mongoose = require('mongoose').set('debug', false);
const cfgserver = mongoose.model('cfgserver'); const {CfgServer} = require('../models/cfgserver');
// const uuidv4 = require('uuid/v4'); // I chose v4 you can select others // const uuidv4 = require('uuid/v4'); // I chose v4 you can select others
@@ -1236,7 +1236,7 @@ router.get(process.env.LINK_CHECK_UPDATES, authenticate, async (req, res) => {
return res.status(404).send(); return res.status(404).send();
} }
await cfgserver.find({idapp}).then((arrcfgrec) => { await CfgServer.find({idapp}).then((arrcfgrec) => {
if (!arrcfgrec) if (!arrcfgrec)
return res.status(404).send(); return res.status(404).send();
@@ -1265,7 +1265,7 @@ router.get(process.env.LINK_CHECK_UPDATES, authenticate, async (req, res) => {
return Promise.all([usersList, last_msgs]).then((arrdata) => { return Promise.all([usersList, last_msgs]).then((arrdata) => {
// console.table(arrdata); // console.table(arrdata);
return res.send({ return res.send({
cfgServer: arrcfgrec, CfgServer: arrcfgrec,
usersList: arrdata[0], usersList: arrdata[0],
last_msgs: arrdata[1], last_msgs: arrdata[1],
}); });

View File

@@ -930,9 +930,9 @@ async function eseguiDbOp(idapp, mydata, locale) {
ris = populate.rewriteTable('contribtypes'); ris = populate.rewriteTable('contribtypes');
} else if (mydata.dbop === 'copyFrom1To13') { } else if (mydata.dbop === 'copyFrom1To14') {
const idapporig = 1; const idapporig = 1;
const idappdest = 13; const idappdest = 14;
if (!idapporig || !idappdest) if (!idapporig || !idappdest)
return; return;
@@ -957,11 +957,12 @@ async function eseguiDbOp(idapp, mydata, locale) {
await mytable.DuplicateAllRecords(idapporig, idappdest). await mytable.DuplicateAllRecords(idapporig, idappdest).
then((numrec) => { then((numrec) => {
// tools.mylogshow(' REC TO MODIFY: ', rec); // tools.mylogshow(' REC TO MODIFY: ', rec);
numrectot += numrec; if (numrec)
numrectot += numrec;
}); });
} }
ris = numrectot; ris = true;
} catch (e) { } catch (e) {
console.log('e', e); console.log('e', e);
@@ -1090,8 +1091,7 @@ router.post('/dbop', authenticate, async (req, res) => {
res.send(ris); res.send(ris);
} catch (e) { } catch (e) {
res.status(400).send(); res.status(400).send({code: server_constants.RIS_CODE_ERR, msg: e});
res.send({code: server_constants.RIS_CODE_ERR, msg: e});
console.log(e.message); console.log(e.message);
} }

View File

@@ -62,15 +62,13 @@ let telegrambot = null;
const tools = require('./tools/general'); const tools = require('./tools/general');
require('./models/cfgserver');
const shared_consts = require('./tools/shared_nodejs'); const shared_consts = require('./tools/shared_nodejs');
var mongoose = require('mongoose').set('debug', false); var mongoose = require('mongoose').set('debug', false);
mongoose.set('debug', process.env.DEBUG); mongoose.set('debug', process.env.DEBUG);
const cfgserver = mongoose.model('cfgserver'); const {CfgServer} = require('./models/cfgserver');
const {ObjectID} = require('mongodb'); const {ObjectID} = require('mongodb');
const populate = require('./populate/populate'); const populate = require('./populate/populate');
@@ -302,7 +300,7 @@ function populateDBadmin() {
valore: '0.1.2', valore: '0.1.2',
}]; }];
let cfg = new cfgserver(cfgserv[0]).save(); let cfg = new CfgServer(cfgserv[0]).save();
} }
function mycron() { function mycron() {

View File

@@ -3391,7 +3391,7 @@ class Telegram {
} }
try { try {
console.log('textORIG', text.substring(0, 100)); console.log('<<< SEND MSG: >>> ', text.substring(0, 100));
text = text.replace(/<br>/g, '\n'); text = text.replace(/<br>/g, '\n');
text = text.replace(/<br\/>/g, '\n'); text = text.replace(/<br\/>/g, '\n');
text = text.replace(/<div>/g, ''); text = text.replace(/<div>/g, '');

View File

@@ -1759,7 +1759,7 @@ module.exports = {
let num = 0; let num = 0;
for (let ind = 0; ind < arrrec.length; ind++) { for (let ind = 0; ind < arrrec.length; ind++) {
let newrec = new mythistable(arrrec[ind]._doc); let newrec = new mythistable(arrrec[ind]);
newrec._id = new ObjectID(); newrec._id = new ObjectID();
newrec.idapp = idappdest; newrec.idapp = idappdest;
@@ -2704,7 +2704,7 @@ module.exports = {
refreshAllTablesInMem(idapp, table, updatebot, username) { refreshAllTablesInMem(idapp, table, updatebot, username) {
const telegrambot = require('../telegram/telegrambot'); const telegrambot = require('../telegram/telegrambot');
if (table === shared_consts.TAB_MYBOTS || updatebot) { if (table === shared_consts.TAB_BOTS || updatebot) {
telegrambot.reloadMenuBot(idapp); telegrambot.reloadMenuBot(idapp);
} }

View File

@@ -42,6 +42,7 @@ const Pickup = require('../models/pickup');
const {Newstosent} = require('../models/newstosent'); const {Newstosent} = require('../models/newstosent');
const {MyPage} = require('../models/mypage'); const {MyPage} = require('../models/mypage');
const {MyBot} = require('../models/bot'); const {MyBot} = require('../models/bot');
const {CfgServer} = require('../models/cfgserver');
const {CalZoom} = require('../models/calzoom'); const {CalZoom} = require('../models/calzoom');
const {Gallery} = require('../models/gallery'); const {Gallery} = require('../models/gallery');
const {TemplEmail} = require('../models/templemail'); const {TemplEmail} = require('../models/templemail');
@@ -139,8 +140,10 @@ module.exports = {
mytable = Gallery; mytable = Gallery;
else if (tablename === 'mypage') else if (tablename === 'mypage')
mytable = MyPage; mytable = MyPage;
else if (tablename === 'mybots') else if (tablename === 'bots')
mytable = MyBot; mytable = MyBot;
else if (tablename === 'cfgservers')
mytable = CfgServer;
else if (tablename === 'calzoom') else if (tablename === 'calzoom')
mytable = CalZoom; mytable = CalZoom;
else if (tablename === 'templemail') else if (tablename === 'templemail')

View File

@@ -68,7 +68,7 @@ module.exports = {
TAB_SETTINGS: 'settings', TAB_SETTINGS: 'settings',
TAB_SITES: 'sites', TAB_SITES: 'sites',
TAB_MYGROUPS: 'mygroups', TAB_MYGROUPS: 'mygroups',
TAB_MYBOTS: 'mybots', TAB_BOTS: 'bots',
TAB_USERS: 'users', TAB_USERS: 'users',
KEY_TO_CRYPTED: ['PWD_FROM'], KEY_TO_CRYPTED: ['PWD_FROM'],
@@ -123,7 +123,7 @@ module.exports = {
'circuits', 'circuits',
'movements'], 'movements'],
TABLES_USER_ID: ['mygroups', 'myskills', 'mybachecas', 'myhosps', 'mygoods'], TABLES_USER_ID: ['mygroups', 'myskills', 'mybachecas', 'myhosps', 'mygoods'],
TABLES_UPDATE_LASTMODIFIED: ['myskills', 'mybachecas', 'myhosps', 'mygoods', 'mybots'], TABLES_UPDATE_LASTMODIFIED: ['myskills', 'mybachecas', 'myhosps', 'mygoods', 'bots'],
TABLES_PERM_CHANGE_FOR_USERS: ['myskills', 'mybachecas', 'myhosps', 'mygoods'], TABLES_PERM_CHANGE_FOR_USERS: ['myskills', 'mybachecas', 'myhosps', 'mygoods'],