- creato editor di Pagine (iniziato)
- fix: mancano i "t," su alcuni componenti...
This commit is contained in:
@@ -690,3 +690,6 @@ function generateCSV(data, outputPath) {
|
||||
// const Order = mongoose.model('Order', OrderSchema);
|
||||
|
||||
// module.exports = { Order };
|
||||
|
||||
|
||||
// **** TOTALPRICE !!!
|
||||
@@ -495,36 +495,38 @@ class CronMod {
|
||||
await MyBot.generateBotMenuRecords(idapp);
|
||||
} else if (mydata.dbop === 'GenerateVapiKey') {
|
||||
await tools.generateVapiKey();
|
||||
} else if (mydata.dbop === 'convertProductInfos') {
|
||||
const products = await Product.find({ idProductInfo: { $exists: true } });
|
||||
console.log(
|
||||
'eseguiDbOpUser: convertProductInfos - TrovaticonvertProductInfos ',
|
||||
products.length,
|
||||
' prodotti con idProductInfo'
|
||||
);
|
||||
|
||||
/*} else if (mydata.dbop === 'visuNave') {
|
||||
mystr = await Nave.getNavePos(idapp, parseInt(mydata.riga), parseInt(mydata.col));
|
||||
|
||||
const visu_nave_Bot = await Settings.getValDbSettings(idapp, 'VISU_NAVE_BOT');
|
||||
if (visu_nave_Bot)
|
||||
telegrambot.sendMsgTelegramToTheAdmin(idapp, mystr, true);
|
||||
|
||||
ris = { mystr };
|
||||
} else if (mydata.dbop === 'getnavibyuser') {
|
||||
|
||||
let arrnavi = null;
|
||||
|
||||
const user = await User.getUserShortDataByUsername(idapp, mydata.username);
|
||||
if (user) {
|
||||
arrnavi = await Nave.getArrPosizioniByUsername(idapp, user.username);
|
||||
|
||||
for (let mynave of arrnavi) {
|
||||
mynave._doc.rec = await Nave.getNaveByRigaCol(idapp, mynave.riga, mynave.col);
|
||||
}
|
||||
|
||||
let aggiornati = 0;
|
||||
for (const product of products) {
|
||||
const productInfo = await ProductInfo.findById(product.idProductInfo);
|
||||
if (productInfo) {
|
||||
const productInfoObj = productInfo.toObject();
|
||||
delete productInfoObj._id;
|
||||
delete productInfoObj.__v;
|
||||
await Product.updateOne(
|
||||
{ _id: product._id },
|
||||
{
|
||||
$set: { productInfo: productInfoObj },
|
||||
$unset: { idProductInfo: 1 },
|
||||
}
|
||||
);
|
||||
|
||||
aggiornati++;
|
||||
|
||||
// ✅ Cancella il record ProductInfo ora che è stato copiato
|
||||
await ProductInfo.deleteOne({ _id: productInfo._id });
|
||||
}
|
||||
|
||||
ris = { data: arrnavi };
|
||||
|
||||
*/
|
||||
}
|
||||
console.log('eseguiDbOpUser - Aggiornati ', aggiornati, ' prodotti');
|
||||
}
|
||||
|
||||
// console.log('ris', ris);
|
||||
|
||||
return ris;
|
||||
} catch (e) {
|
||||
console.log(e.message);
|
||||
|
||||
@@ -1316,193 +1316,6 @@ router.post('/import', authenticate, async (req, res) => {
|
||||
);
|
||||
|
||||
return res.status(200).send({ updated, imported, errors });
|
||||
} else if (cmd === shared_consts.Cmd.MACRO_RANKING) {
|
||||
/*
|
||||
let updated = 0;
|
||||
let imported = 0;
|
||||
let errors = 0;
|
||||
|
||||
const ripopola = true; // SETTARE su TRUE
|
||||
|
||||
if (ripopola) {
|
||||
dataObjects = null;
|
||||
|
||||
try {
|
||||
dataObjects = JSON.parse(`[${data.arrdata}]`);
|
||||
} catch (e) {
|
||||
dataObjects = null;
|
||||
}
|
||||
|
||||
if (dataObjects && dataObjects[0]) {
|
||||
// Cancella la collection ImportaIsbn
|
||||
await ImportaIsbn.deleteMany({ idapp });
|
||||
|
||||
const numtot = dataObjects[0].length
|
||||
|
||||
console.log('Numero di RECORD da Importare = ', numtot);
|
||||
|
||||
// Aggiungi i record su ImportaIsbn
|
||||
for (const recinv of dataObjects[0]) {
|
||||
let recmacro = recinv;
|
||||
|
||||
recmacro.idapp = idapp;
|
||||
|
||||
//recmacro._id = recmacro.id;
|
||||
recmacro.sku = recmacro.IdArticolo;
|
||||
|
||||
if (recmacro.DataPubblicazione) {
|
||||
|
||||
// delete recmacro.id;
|
||||
|
||||
let queryprod = { idapp, sku: recmacro.sku };
|
||||
|
||||
// 13872
|
||||
|
||||
try {
|
||||
let risrec = await ImportaIsbn.findOneAndUpdate(queryprod, { $set: recmacro }, { new: true, upsert: true, strict: false });
|
||||
if (risrec) {
|
||||
imported++;
|
||||
if ((imported % 100) === 0)
|
||||
console.log('Importati dir TEMPORANEA ... ', imported + '/' + numtot);
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Rileggi tutti i record di ImportaIsbn
|
||||
dataObjects = await ImportaIsbn.find({ idapp }).lean();
|
||||
|
||||
let numprod = dataObjects.length;
|
||||
|
||||
console.log('*** INIZIO IMPORT RANKING ... NUMRECORD = ', numprod);
|
||||
|
||||
let indprod = 0;
|
||||
let newprod = 0;
|
||||
|
||||
|
||||
if (numprod) {
|
||||
// Rimuove prima tutti i valori precedenti
|
||||
let risupdate = await ProductInfo.updateMany({ idapp }, {
|
||||
$set: {
|
||||
totVen: 0,
|
||||
totFat: 0,
|
||||
vLast3M: 0,
|
||||
vLast6M: 0,
|
||||
vLast1Y: 0,
|
||||
vLast2Y: 0,
|
||||
rank3M: 0,
|
||||
rank6M: 0,
|
||||
rank1Y: 0,
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
imported = 0;
|
||||
|
||||
for (const product of dataObjects) {
|
||||
let isnuovo = false
|
||||
let setta = false
|
||||
|
||||
let importa = true;
|
||||
|
||||
//if (!product.title || !product.isbn)
|
||||
if (!product.sku || !product.DataPubblicazione)
|
||||
importa = false;
|
||||
|
||||
if (importa) {
|
||||
let versGM = product.Versione ? product.Versione : '';
|
||||
|
||||
// split versioneGM in array with separated ","
|
||||
let arrversGM = versGM.split(",").map(x => x.trim());
|
||||
|
||||
const recproductInfoAttuale = await ProductInfo.findOne({ idapp, code: product.isbn });
|
||||
|
||||
let productInfo = {
|
||||
idapp: product.idapp,
|
||||
code: product.isbn ? product.isbn : product.code,
|
||||
sku: product.sku,
|
||||
idCatProds: recproductInfoAttuale?.idCatProds,
|
||||
|
||||
// id_wp: product._id,
|
||||
|
||||
// name: product.title,
|
||||
totVen: product.totVen || 0,
|
||||
totFat: product.totFat || 0,
|
||||
vLast3M: product.vLast3M || 0,
|
||||
fatLast3M: product.fatLast3M || 0,
|
||||
fatLast6M: product.fatLast6M || 0,
|
||||
vLast6M: product.vLast6M || 0,
|
||||
vLast1Y: product.vLast1Y || 0,
|
||||
vLast2Y: product.vLast2Y || 0,
|
||||
rank3M: product.rank3M || 0,
|
||||
rank6M: product.rank6M || 0,
|
||||
rank1Y: product.rank1Y || 0,
|
||||
|
||||
}
|
||||
|
||||
if (!productInfo.idCatProds) {
|
||||
productInfo.idCatProds = [];
|
||||
}
|
||||
|
||||
|
||||
// Aggiorna la collana solo se non è stata già impostata nel record attuale
|
||||
//if (recproductInfoAttuale && !recproductInfoAttuale.idCollana && product.DescrizioneCollana) {
|
||||
if (recproductInfoAttuale && product.DescrizioneCollana) {
|
||||
const idCollanaNum = parseInt(product.IdCollana)
|
||||
|
||||
reccollana = await Collana.findOne({ idapp, idCollana: idCollanaNum }).lean();
|
||||
if (!reccollana) {
|
||||
try {
|
||||
// Non esiste questa collana, quindi la creo !
|
||||
reccollana = new Collana({ idapp, idCollana: idCollanaNum, title: product.DescrizioneCollana });
|
||||
ris = await reccoll.save();
|
||||
} catch (e) {
|
||||
console.error('Err', e);
|
||||
}
|
||||
}
|
||||
|
||||
if (reccollana)
|
||||
productInfo.idCollana = reccollana._id;
|
||||
|
||||
}
|
||||
|
||||
if (recproductInfoAttuale && product.DescrArgomento) {
|
||||
|
||||
productInfo = await updateProductInfo(productInfo, product, idapp, product.DescrArgomento);
|
||||
}
|
||||
|
||||
if (product.DataPubblicazione) {
|
||||
productInfo.date_pub = new Date(product.DataPubblicazione);
|
||||
// convert data to timestamp
|
||||
productInfo.date_pub_ts = productInfo.date_pub.getTime();
|
||||
}
|
||||
if (product.dataUltimoOrdine) {
|
||||
productInfo.dataUltimoOrdine = new Date(product.dataUltimoOrdine);
|
||||
}
|
||||
|
||||
|
||||
// Update ProductInfo
|
||||
let risrecInfo = await ProductInfo.findOneAndUpdate({ idapp, code: productInfo.code }, { $set: productInfo }, { new: true, upsert: false });
|
||||
if (risrecInfo) {
|
||||
imported++;
|
||||
if (imported % 100 === 0)
|
||||
console.log('Importati... ', imported + '/' + numprod);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log('*** IMPORTATI: ', imported, ' [Prodotti = ' + indprod + '] *** NUOVI: ', newprod, 'AGGIORNATI = ' + updated + ' (su ' + dataObjects.length + ' RECORD)');
|
||||
|
||||
return res.status(200).send({ updated, imported, errors });
|
||||
*/
|
||||
} else if (cmd === shared_consts.Cmd.MACRO_CATALOGO_JSON) {
|
||||
try {
|
||||
const macro = new Macro(idapp, { importadaFDV: true }); // Crea un'istanza della classe Macro
|
||||
@@ -1598,6 +1411,7 @@ router.post('/import', authenticate, async (req, res) => {
|
||||
);
|
||||
|
||||
// .... ANDARE AVANTI DA QUI... .productInfo.... SISTEMARE!
|
||||
|
||||
if (risrecInfo) {
|
||||
productImported.productInfo = risrecInfo._id;
|
||||
|
||||
|
||||
@@ -191,6 +191,26 @@ function subDays(date, days) {
|
||||
return newDate;
|
||||
}
|
||||
|
||||
router.delete('/mypage/:id', authenticate, async (req, res) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
|
||||
|
||||
|
||||
// Trova il record di MyPage da cancellare
|
||||
const pageToDelete = await MyPage.findByIdAndRemove(id);
|
||||
|
||||
if (!pageToDelete) {
|
||||
return res.status(404).json({ error: 'Pagina non trovata' });
|
||||
}
|
||||
|
||||
res.json({ message: `Pagina eliminata con successo: ${pageToDelete.path}` });
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
res.status(500).json({ error: 'Errore durante l\'eliminazione della pagina' });
|
||||
}
|
||||
});
|
||||
|
||||
router.get('/pageviews/users', authenticate_noerror, async (req, res) => {
|
||||
try {
|
||||
const { idapp } = req.query;
|
||||
|
||||
@@ -900,6 +900,30 @@ router.post('/getpage', async (req, res) => {
|
||||
return found;
|
||||
});
|
||||
|
||||
router.post('/savepage', authenticate, async (req, res) => {
|
||||
const params = req.body;
|
||||
const idapp = req.body.idapp;
|
||||
const mypage = params.page;
|
||||
|
||||
try {
|
||||
if (mypage?._id) {
|
||||
let found = await MyPage.findOneAndUpdate({ idapp, _id: mypage._id }, mypage, { upsert: true, new: true })
|
||||
.then((ris) => {
|
||||
if (ris) {
|
||||
return res.send({ code: server_constants.RIS_CODE_OK, mypage: ris });
|
||||
}
|
||||
return res.send({ code: server_constants.RIS_CODE_ERR, msg: '' });
|
||||
})
|
||||
.catch((e) => {
|
||||
console.log(e.message);
|
||||
res.status(400).send(e);
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Error', e);
|
||||
}
|
||||
});
|
||||
|
||||
async function exportPage(idapp, pageId) {
|
||||
try {
|
||||
const myexp = {
|
||||
|
||||
@@ -1126,23 +1126,6 @@ async function eseguiDbOpUser(idapp, mydata, locale, req, res) {
|
||||
await User.findOneAndUpdate({ _id: mydata._id }, { $set: { 'profile.noCircIta': mydata.value } });
|
||||
} else if (mydata.dbop === 'noFoto') {
|
||||
await User.findOneAndUpdate({ _id: mydata._id }, { $set: { 'profile.noFoto': mydata.value } });
|
||||
} else if (mydata.dbop === 'convertProductInfos') {
|
||||
const products = await Product.find({ idProductInfo: { $exists: true } });
|
||||
for (const product of products) {
|
||||
const productInfo = await ProductInfo.findById(product.idProductInfo);
|
||||
if (productInfo) {
|
||||
const productInfoObj = productInfo.toObject();
|
||||
delete productInfoObj._id;
|
||||
delete productInfoObj.__v;
|
||||
await Product.updateOne(
|
||||
{ _id: product._id },
|
||||
{
|
||||
$set: { productInfo: productInfoObj },
|
||||
$unset: { idProductInfo: 1 },
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e.message);
|
||||
|
||||
@@ -791,7 +791,10 @@ connectToDatabase(connectionUrl, options)
|
||||
return [
|
||||
'https://localhost:3000',
|
||||
'https://localhost:8089',
|
||||
'https://localhost:8082',
|
||||
'https://localhost:8083',
|
||||
'https://localhost:8084',
|
||||
'https://localhost:8085',
|
||||
'https://localhost:8088',
|
||||
'https://localhost:8099',
|
||||
];
|
||||
@@ -864,6 +867,7 @@ connectToDatabase(connectionUrl, options)
|
||||
|
||||
function setupMiddleware(app, corsOptions, isDebug = false) {
|
||||
app.use(cors(corsOptions));
|
||||
app.set('trust proxy', true);
|
||||
app.use(express.json());
|
||||
app.options('*', cors(corsOptions));
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
1.2.67
|
||||
1.2.68
|
||||
Reference in New Issue
Block a user