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);
};
BotSchema.statics.DuplicateAllRecords = async function (idapporig, idappdest) {
return tools.DuplicateAllRecords(this, idapporig, idappdest);
};
BotSchema.statics.findAllIdApp = async function(idapp) {
const Bot = this;

View File

@@ -4,6 +4,7 @@ const Schema = mongoose.Schema;
mongoose.Promise = global.Promise;
mongoose.level = "F";
const tools = require('../tools/general');
const { ObjectID } = require('mongodb');
// Resolving error Unknown modifier: $pushAll
@@ -11,7 +12,7 @@ mongoose.plugin(schema => {
schema.options.usePushEach = true
});
const cfgserverSchema = new Schema({
const CfgServerSchema = new Schema({
chiave: {
type: String,
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,6 +91,7 @@ SettingsSchema.statics.DuplicateAllRecords = async function (idapporig, idappdes
SettingsSchema.statics.findAllIdApp = async function (idapp, serv, crypted = false) {
const Settings = this;
try {
let myfind = '';
if (serv) {
myfind = {idapp, serv};
@@ -99,24 +100,27 @@ SettingsSchema.statics.findAllIdApp = async function (idapp, serv, crypted = fal
// myfind = {...myfind, $or: [{ crypted: { $exists: false } }, { crypted: { $exists: true, $eq: crypted } }]};
const arrorig = await Settings.find(myfind, (err, arrrec) => {
return arrrec
});
const arrorig = await Settings.find(myfind).lean();
let myarr = []
if (!crypted) {
arrorig.forEach((rec) => {
for (let rec of arrorig) {
if (rec.crypted) {
rec._doc.value_str = ''
rec.value_str = ''
}
myarr.push({...rec});
}
myarr.push({...rec._doc});
})
} else {
myarr = [...arrorig];
}
return myarr;
}catch (e) {
console.error('Settings: findAllIdApp', e);
return null;
}
};
SettingsSchema.statics.setKeyNum = async function (idapp, key, value) {

View File

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

View File

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

View File

@@ -15,7 +15,7 @@ const {ObjectID} = require('mongodb');
const {Graduatoria} = require('../models/graduatoria');
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
@@ -1236,7 +1236,7 @@ router.get(process.env.LINK_CHECK_UPDATES, authenticate, async (req, res) => {
return res.status(404).send();
}
await cfgserver.find({idapp}).then((arrcfgrec) => {
await CfgServer.find({idapp}).then((arrcfgrec) => {
if (!arrcfgrec)
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) => {
// console.table(arrdata);
return res.send({
cfgServer: arrcfgrec,
CfgServer: arrcfgrec,
usersList: arrdata[0],
last_msgs: arrdata[1],
});

View File

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

View File

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

View File

@@ -3391,7 +3391,7 @@ class Telegram {
}
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(/<div>/g, '');

View File

@@ -1759,7 +1759,7 @@ module.exports = {
let num = 0;
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.idapp = idappdest;
@@ -2704,7 +2704,7 @@ module.exports = {
refreshAllTablesInMem(idapp, table, updatebot, username) {
const telegrambot = require('../telegram/telegrambot');
if (table === shared_consts.TAB_MYBOTS || updatebot) {
if (table === shared_consts.TAB_BOTS || updatebot) {
telegrambot.reloadMenuBot(idapp);
}

View File

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

View File

@@ -68,7 +68,7 @@ module.exports = {
TAB_SETTINGS: 'settings',
TAB_SITES: 'sites',
TAB_MYGROUPS: 'mygroups',
TAB_MYBOTS: 'mybots',
TAB_BOTS: 'bots',
TAB_USERS: 'users',
KEY_TO_CRYPTED: ['PWD_FROM'],
@@ -123,7 +123,7 @@ module.exports = {
'circuits',
'movements'],
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'],