- corretto problema ROGNOSO : Risolvere la questione "Sessioni multiple", se apro 2 browser l'ultimo va a cancellare il precedente, e mi da errore di email non valida !
Il problema era sulla fetch nel service worker, gestita in quel modo personalizzato, andava in conflitto, non tenendo le chiamate bloccanti, ma uscivano prima che arrivasse la risposta del server. - Per chi è da tanto che non si collega a RISO, compare "Email non verificata"... (si risolve chiudendo su ESCI e riloggandosi)... però andrebbe sistemata. (stesso problema di prima).
This commit is contained in:
@@ -31,6 +31,7 @@
|
||||
"ejs": "^3.1.10",
|
||||
"email-templates": "^12.0.2",
|
||||
"express": "^4.21.2",
|
||||
"fast-csv": "^5.0.5",
|
||||
"formidable": "^3.5.2",
|
||||
"ghostscript4js": "^3.2.3",
|
||||
"helmet": "^8.1.0",
|
||||
|
||||
@@ -17,6 +17,8 @@ const authenticateMiddleware = async (req, res, next, withUser = false, lean = f
|
||||
const refreshToken = req.header('x-refrtok');
|
||||
const logPrefix = noError ? (withUser ? (lean ? 'WITHUSERLEAN' : 'WITHUSER') : 'NOERROR') : 'AUTH';
|
||||
|
||||
// console.log('authenticateMiddleware, token:', token, ' refreshToken:', refreshToken, 'withUser:', withUser, 'noError:', noError);
|
||||
|
||||
if (!token) {
|
||||
req.user = null;
|
||||
req.token = null;
|
||||
@@ -28,10 +30,14 @@ const authenticateMiddleware = async (req, res, next, withUser = false, lean = f
|
||||
|
||||
const user = await User.findByToken(token, 'auth', false, withUser, lean);
|
||||
|
||||
req.statuscode2 = null;
|
||||
|
||||
if (user.code !== server_constants.RIS_CODE_OK) {
|
||||
req.user = null;
|
||||
req.token = null;
|
||||
req.code = user.code;
|
||||
if (user.code === server_constants.RIS_CODE_HTTP_FORBIDDEN_TOKEN_EXPIRED)
|
||||
console.log('TOKEN SCADUTO!');
|
||||
} else {
|
||||
req.user = user.user;
|
||||
req.token = token;
|
||||
@@ -42,7 +48,9 @@ const authenticateMiddleware = async (req, res, next, withUser = false, lean = f
|
||||
if (user.code === server_constants.RIS_CODE_HTTP_FORBIDDEN_TOKEN_EXPIRED) {
|
||||
console.log(` TOKEN SCADUTO ! `);
|
||||
if (noError) {
|
||||
req.statuscode2 = server_constants.RIS_CODE_HTTP_FORBIDDEN_TOKEN_EXPIRED;
|
||||
return next()
|
||||
// return res.status(server_constants.RIS_CODE_HTTP_FORBIDDEN_TOKEN_EXPIRED).send();
|
||||
} else {
|
||||
return res.status(server_constants.RIS_CODE_HTTP_FORBIDDEN_TOKEN_EXPIRED).send();
|
||||
}
|
||||
|
||||
@@ -253,11 +253,15 @@ CatalogSchema.statics.getCatalogById = async function (id) {
|
||||
model: 'Gasordine',
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
// controlla prima se nella lista ci sono dei product che non esistono piu allora li devi rimuovere !
|
||||
for (const catalog of arrrec) {
|
||||
let old_lista = [...catalog.lista_prodotti];
|
||||
|
||||
let nuova_lista = [...catalog.lista_prodotti];
|
||||
|
||||
const originalLength = catalog.lista_prodotti.length;
|
||||
catalog.lista_prodotti = catalog.lista_prodotti.filter(
|
||||
nuova_lista = nuova_lista.filter(
|
||||
(product) =>
|
||||
product.productInfo &&
|
||||
product.productInfo.code &&
|
||||
@@ -266,11 +270,21 @@ CatalogSchema.statics.getCatalogById = async function (id) {
|
||||
product.productInfo.imagefile !== 'noimg.jpg' &&
|
||||
!product.delete
|
||||
);
|
||||
if (catalog.lista_prodotti.length !== originalLength) {
|
||||
await catalog.save();
|
||||
|
||||
// Se la nuova lista è diversa da quella precedente di più del 10%, allora non aggiorna, perché potrebbe esserci un problema
|
||||
let differencePercentage = (100 * Math.abs(originalLength - nuova_lista.length)) / originalLength;
|
||||
if (differencePercentage < 10) {
|
||||
// Aggiorno la lista solo se è cambiata poco
|
||||
// confronta l'array nuova_lista con l'array catalog.lista_prodotti
|
||||
let differents = tools.areDifferentProduct(catalog.lista_prodotti, nuova_lista);
|
||||
|
||||
if (differents) {
|
||||
// aggiorna la lista
|
||||
catalog.lista_prodotti = nuova_lista;
|
||||
await catalog.save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const transformedArrRec = arrrec.map((catalog) => ({
|
||||
...catalog.toObject(), // Converte il documento Mongoose in un oggetto JavaScript puro
|
||||
|
||||
@@ -15,7 +15,7 @@ const { MyGroup } = require('./mygroup');
|
||||
const tableModel = shared_consts.TABLES_MYBACHECAS;
|
||||
|
||||
// Resolving error Unknown modifier: $pushAll
|
||||
mongoose.plugin(schema => {
|
||||
mongoose.plugin((schema) => {
|
||||
schema.options.usePushEach = true;
|
||||
});
|
||||
|
||||
@@ -43,32 +43,37 @@ const MyBachecaSchema = new Schema({
|
||||
idStatusSkill: [
|
||||
{
|
||||
type: Number,
|
||||
}],
|
||||
},
|
||||
],
|
||||
idContribType: [
|
||||
{
|
||||
type: String,
|
||||
}],
|
||||
},
|
||||
],
|
||||
idCity: [
|
||||
{
|
||||
type: Number,
|
||||
}],
|
||||
},
|
||||
],
|
||||
dateTimeStart: {
|
||||
type: Date,
|
||||
},
|
||||
dateTimeEnd: {
|
||||
type: Date,
|
||||
required: false, // non obbligatorio
|
||||
default: null, // valore predefinito esplicito (opzionale)
|
||||
},
|
||||
organisedBy: {
|
||||
type: String
|
||||
type: String,
|
||||
},
|
||||
contact_phone: {
|
||||
type: String
|
||||
type: String,
|
||||
},
|
||||
contact_email: {
|
||||
type: String
|
||||
type: String,
|
||||
},
|
||||
contact_telegram: {
|
||||
type: String
|
||||
type: String,
|
||||
},
|
||||
address: {
|
||||
type: String,
|
||||
@@ -103,7 +108,8 @@ const MyBachecaSchema = new Schema({
|
||||
description: {
|
||||
type: String,
|
||||
},
|
||||
}],
|
||||
},
|
||||
],
|
||||
note: {
|
||||
type: String,
|
||||
default: '',
|
||||
@@ -121,15 +127,17 @@ const MyBachecaSchema = new Schema({
|
||||
date_updated: {
|
||||
type: Date,
|
||||
},
|
||||
link_conference: {
|
||||
type: String,
|
||||
},
|
||||
},
|
||||
...Reaction.getFieldsForReactions(),
|
||||
...tools.getFieldsForAnnunci()
|
||||
...tools.getFieldsForAnnunci(),
|
||||
});
|
||||
|
||||
MyBachecaSchema.pre('save', async function (next) {
|
||||
if (this.isNew) {
|
||||
if (!this.date_created)
|
||||
this.date_created = new Date();
|
||||
if (!this.date_created) this.date_created = new Date();
|
||||
}
|
||||
|
||||
next();
|
||||
@@ -138,13 +146,9 @@ MyBachecaSchema.pre('save', async function (next) {
|
||||
MyBachecaSchema.statics.findAllIdApp = async function (idapp) {
|
||||
const MyBacheca = this;
|
||||
|
||||
const query = [
|
||||
{ $match: { idapp } },
|
||||
{ $sort: { descr: 1 } },
|
||||
];
|
||||
const query = [{ $match: { idapp } }, { $sort: { descr: 1 } }];
|
||||
|
||||
return await MyBacheca.aggregate(query);
|
||||
|
||||
};
|
||||
|
||||
MyBachecaSchema.statics.getFieldsForSearch = function () {
|
||||
@@ -160,7 +164,6 @@ MyBachecaSchema.statics.getFieldsLastForSearch = function () {
|
||||
];
|
||||
};
|
||||
|
||||
|
||||
MyBachecaSchema.statics.executeQueryTable = function (idapp, params, user) {
|
||||
params.fieldsearch = this.getFieldsForSearch();
|
||||
params.fieldsearch_last = this.getFieldsLastForSearch();
|
||||
@@ -184,16 +187,14 @@ MyBachecaSchema.statics.executeQueryTable = function (idapp, params, user) {
|
||||
MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
|
||||
const MyBacheca = this;
|
||||
|
||||
|
||||
let myparsid = {
|
||||
'_id': id,
|
||||
_id: id,
|
||||
idapp,
|
||||
};
|
||||
|
||||
let query = [
|
||||
{
|
||||
$match:
|
||||
myparsid,
|
||||
$match: myparsid,
|
||||
},
|
||||
{
|
||||
$sort: {
|
||||
@@ -202,28 +203,25 @@ MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
|
||||
},
|
||||
{
|
||||
$addFields: {
|
||||
'myId1': {
|
||||
'$toObjectId': '$userId',
|
||||
myId1: {
|
||||
$toObjectId: '$userId',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
'$lookup': {
|
||||
'from': 'users',
|
||||
'localField': 'myId1',
|
||||
'foreignField': '_id',
|
||||
'as': 'user',
|
||||
$lookup: {
|
||||
from: 'users',
|
||||
localField: 'myId1',
|
||||
foreignField: '_id',
|
||||
as: 'user',
|
||||
},
|
||||
},
|
||||
{
|
||||
'$replaceRoot': {
|
||||
'newRoot': {
|
||||
'$mergeObjects': [
|
||||
$replaceRoot: {
|
||||
newRoot: {
|
||||
$mergeObjects: [
|
||||
{
|
||||
'$arrayElemAt': [
|
||||
'$user',
|
||||
0,
|
||||
],
|
||||
$arrayElemAt: ['$user', 0],
|
||||
},
|
||||
'$$ROOT',
|
||||
],
|
||||
@@ -234,22 +232,19 @@ MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
|
||||
$project: shared_consts.getProjectForAll({}, tableModel),
|
||||
},
|
||||
{
|
||||
'$lookup': {
|
||||
'from': 'skills',
|
||||
'localField': 'idSkill',
|
||||
'foreignField': '_id',
|
||||
'as': 'recSkill',
|
||||
$lookup: {
|
||||
from: 'skills',
|
||||
localField: 'idSkill',
|
||||
foreignField: '_id',
|
||||
as: 'recSkill',
|
||||
},
|
||||
},
|
||||
{
|
||||
'$replaceRoot': {
|
||||
'newRoot': {
|
||||
'$mergeObjects': [
|
||||
$replaceRoot: {
|
||||
newRoot: {
|
||||
$mergeObjects: [
|
||||
{
|
||||
'$arrayElemAt': [
|
||||
'$recSkill',
|
||||
0,
|
||||
],
|
||||
$arrayElemAt: ['$recSkill', 0],
|
||||
},
|
||||
'$$ROOT',
|
||||
],
|
||||
@@ -260,22 +255,19 @@ MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
|
||||
$project: shared_consts.getProjectForAll({}, tableModel),
|
||||
},
|
||||
{
|
||||
'$lookup': {
|
||||
'from': 'sectors',
|
||||
'localField': 'idSector',
|
||||
'foreignField': '_id',
|
||||
'as': 'sector',
|
||||
$lookup: {
|
||||
from: 'sectors',
|
||||
localField: 'idSector',
|
||||
foreignField: '_id',
|
||||
as: 'sector',
|
||||
},
|
||||
},
|
||||
{
|
||||
'$replaceRoot': {
|
||||
'newRoot': {
|
||||
'$mergeObjects': [
|
||||
$replaceRoot: {
|
||||
newRoot: {
|
||||
$mergeObjects: [
|
||||
{
|
||||
'$arrayElemAt': [
|
||||
'$sector',
|
||||
0,
|
||||
],
|
||||
$arrayElemAt: ['$sector', 0],
|
||||
},
|
||||
'$$ROOT',
|
||||
],
|
||||
@@ -284,10 +276,10 @@ MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
'from': 'mygroups',
|
||||
'localField': 'groupname',
|
||||
'foreignField': 'groupname',
|
||||
'as': 'mygrp',
|
||||
from: 'mygroups',
|
||||
localField: 'groupname',
|
||||
foreignField: 'groupname',
|
||||
as: 'mygrp',
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -308,14 +300,11 @@ MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
|
||||
},
|
||||
},*/
|
||||
{
|
||||
'$replaceRoot': {
|
||||
'newRoot': {
|
||||
'$mergeObjects': [
|
||||
$replaceRoot: {
|
||||
newRoot: {
|
||||
$mergeObjects: [
|
||||
{
|
||||
'$arrayElemAt': [
|
||||
'$MyBacheca',
|
||||
0,
|
||||
],
|
||||
$arrayElemAt: ['$MyBacheca', 0],
|
||||
},
|
||||
'$$ROOT',
|
||||
],
|
||||
@@ -326,22 +315,19 @@ MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
|
||||
$project: shared_consts.getProjectForAll({}, tableModel),
|
||||
},
|
||||
{
|
||||
'$lookup': {
|
||||
'from': 'cities',
|
||||
'localField': 'idCity',
|
||||
'foreignField': '_id',
|
||||
'as': 'mycities',
|
||||
$lookup: {
|
||||
from: 'cities',
|
||||
localField: 'idCity',
|
||||
foreignField: '_id',
|
||||
as: 'mycities',
|
||||
},
|
||||
},
|
||||
{
|
||||
'$replaceRoot': {
|
||||
'newRoot': {
|
||||
'$mergeObjects': [
|
||||
$replaceRoot: {
|
||||
newRoot: {
|
||||
$mergeObjects: [
|
||||
{
|
||||
'$arrayElemAt': [
|
||||
'$mycities',
|
||||
0,
|
||||
],
|
||||
$arrayElemAt: ['$mycities', 0],
|
||||
},
|
||||
'$$ROOT',
|
||||
],
|
||||
@@ -370,20 +356,18 @@ MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
MyBachecaSchema.statics.getCompleteRecord = function (idapp, id) {
|
||||
const MyBacheca = this;
|
||||
|
||||
return MyBacheca.getMyRecById(idapp, id);
|
||||
|
||||
};
|
||||
|
||||
|
||||
const MyBacheca = mongoose.model('MyBacheca', MyBachecaSchema);
|
||||
|
||||
MyBacheca.createIndexes()
|
||||
.then(() => { })
|
||||
.catch((err) => { throw err; });
|
||||
|
||||
.then(() => {})
|
||||
.catch((err) => {
|
||||
throw err;
|
||||
});
|
||||
|
||||
module.exports = { MyBacheca };
|
||||
|
||||
@@ -39,6 +39,8 @@ const MyEventSchema = new Schema({
|
||||
},
|
||||
dateTimeEnd: {
|
||||
type: Date,
|
||||
required: false, // non obbligatorio
|
||||
default: null, // valore predefinito esplicito (opzionale)
|
||||
},
|
||||
bgcolor: {
|
||||
type: String,
|
||||
|
||||
@@ -551,7 +551,6 @@ UserSchema.methods.toJSON = function () {
|
||||
};
|
||||
|
||||
UserSchema.methods.generateAuthToken = function (req) {
|
||||
// console.log("GENERA TOKEN : ");
|
||||
const user = this;
|
||||
|
||||
const useragent = req.get('User-Agent');
|
||||
@@ -568,34 +567,37 @@ UserSchema.methods.generateAuthToken = function (req) {
|
||||
|
||||
if (attiva_scadenza)
|
||||
token = jwt
|
||||
.sign({ _id: prova, smart: user._id.toHexString(), access, un: user.username }, process.env.SIGNCODE, {
|
||||
.sign({ _id: user._id.toHexString(), access, un: user.username }, process.env.SIGNCODE, {
|
||||
expiresIn: numsec,
|
||||
})
|
||||
.toString();
|
||||
else
|
||||
token = jwt
|
||||
.sign({ _id: prova, smart: user._id.toHexString(), access, un: user.username }, process.env.SIGNCODE)
|
||||
.sign({ _id: user._id.toHexString(), access, un: user.username }, process.env.SIGNCODE)
|
||||
.toString();
|
||||
|
||||
const refreshToken = jwt
|
||||
.sign({ _id: prova, smart: user._id.toHexString(), access, un: user.username }, process.env.SECRK, {
|
||||
.sign({ _id: user._id.toHexString(), access, un: user.username }, process.env.SECRK, {
|
||||
expiresIn: process.env.REFRESH_TOKEN_LIFE,
|
||||
})
|
||||
.toString();
|
||||
const date_login = new Date();
|
||||
|
||||
// CANCELLA IL PRECEDENTE !
|
||||
user.tokens = user.tokens.filter(function (tok) {
|
||||
return tok.access !== access || (tok.access === access && tok.browser !== browser);
|
||||
});
|
||||
|
||||
user.tokens.push({ access, browser, token, date_login, refreshToken });
|
||||
// Controlla se il token è già presente per la coppia access-browser
|
||||
const idx = user.tokens.findIndex((tok) => tok.access === access && tok.browser === browser);
|
||||
if (idx === -1) {
|
||||
user.tokens.push({ access, browser, token, date_login, refreshToken });
|
||||
} else {
|
||||
// Se il token esiste già, sostituisce il valore vecchio con il nuovo
|
||||
user.tokens[idx] = { access, browser, token, date_login, refreshToken };
|
||||
}
|
||||
|
||||
user.lasttimeonline = new Date();
|
||||
|
||||
return user
|
||||
.save()
|
||||
.then(() => {
|
||||
console.log('########## HO CREATO UN NUOVO TOKEN E REFRESHTOKEN !!!!! ----------- ');
|
||||
return { token, refreshToken };
|
||||
})
|
||||
.catch((err) => {
|
||||
@@ -811,7 +813,7 @@ UserSchema.statics.findByToken = async function (token, typeaccess, con_auth, wi
|
||||
if (withlean) {
|
||||
user = await User.findOne(
|
||||
{
|
||||
_id: decoded.smart,
|
||||
_id: decoded._id,
|
||||
tokens: {
|
||||
$elemMatch: {
|
||||
token,
|
||||
@@ -824,7 +826,7 @@ UserSchema.statics.findByToken = async function (token, typeaccess, con_auth, wi
|
||||
} else {
|
||||
user = await User.findOne(
|
||||
{
|
||||
_id: decoded.smart,
|
||||
_id: decoded._id,
|
||||
tokens: {
|
||||
$elemMatch: {
|
||||
token,
|
||||
@@ -852,7 +854,7 @@ UserSchema.statics.findByToken = async function (token, typeaccess, con_auth, wi
|
||||
const start_find = process.hrtime.bigint();
|
||||
user = await User.findOne(
|
||||
{
|
||||
_id: decoded.smart,
|
||||
_id: decoded._id,
|
||||
tokens: {
|
||||
$elemMatch: {
|
||||
token,
|
||||
@@ -893,11 +895,28 @@ UserSchema.statics.findByTokenAnyAccess = function (token) {
|
||||
}
|
||||
|
||||
return User.findOne({
|
||||
_id: decoded.smart,
|
||||
_id: decoded._id,
|
||||
'tokens.token': token,
|
||||
}).lean();
|
||||
};
|
||||
|
||||
UserSchema.statics.findByRefreshTokenAnyAccess = function (refreshToken) {
|
||||
const User = this;
|
||||
let decoded;
|
||||
|
||||
try {
|
||||
decoded = jwt.verify(refreshToken, process.env.SECRK);
|
||||
} catch (e) {
|
||||
console.error('Err findByRefreshTokenAnyAccess:', e);
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
|
||||
return User.findOne({
|
||||
_id: decoded._id,
|
||||
'tokens.refreshToken': refreshToken,
|
||||
});
|
||||
};
|
||||
|
||||
UserSchema.statics.findByCredentials = async function (idapp, username, password, pwdcrypted) {
|
||||
const User = this;
|
||||
let pwd = '';
|
||||
@@ -1583,7 +1602,7 @@ UserSchema.statics.createNewRequestPwd = function (idapp, email, code) {
|
||||
} else {
|
||||
// Creo il tokenforgot
|
||||
user.tokenforgot = jwt
|
||||
.sign({ _id: 'prova123##', smart: user._id.toHexString() }, process.env.SIGNCODE)
|
||||
.sign({ _id: user._id.toHexString() }, process.env.SIGNCODE)
|
||||
.toString();
|
||||
user.date_tokenforgot = new Date();
|
||||
user.tokenforgot_code = 100000 + Math.round(Math.random() * 899999);
|
||||
@@ -1621,7 +1640,7 @@ UserSchema.statics.createNewRequestPwdByUsernameAndGetLink = async function (ida
|
||||
const prova = 'dasdas1231#11';
|
||||
// Creo il tokenforgot
|
||||
user.tokenforgot = jwt
|
||||
.sign({ _id: prova, smart: user._id.toHexString(), ...additionalData }, process.env.SIGNCODE)
|
||||
.sign({ _id: user._id.toHexString(), ...additionalData }, process.env.SIGNCODE)
|
||||
.toString();
|
||||
user.date_tokenforgot = new Date();
|
||||
user.tokenforgot_code = 100000 + Math.round(Math.random() * 899999);
|
||||
|
||||
@@ -64,6 +64,14 @@ class CronMod {
|
||||
forzaricarica: false,
|
||||
});
|
||||
ris = { mystr };
|
||||
} else if (mydata.dbop === 'EsportaInfoProductExtra') {
|
||||
const macro = new Macro(idapp, {});
|
||||
mystr = await macro.EsportaInfoProductExtra();
|
||||
ris = { mystr };
|
||||
} else if (mydata.dbop === 'ImportaInfoProductExtra') {
|
||||
const macro = new Macro(idapp, {});
|
||||
mystr = await macro.ImportaInfoProductExtra();
|
||||
ris = { mystr };
|
||||
} else if (mydata.dbop === 'ScraperEstraiDatiAmazon-NoUpdate') {
|
||||
mystr = await AmazonBookScraper.ScraperMultipleDataAmazon(idapp, {
|
||||
update: false,
|
||||
|
||||
@@ -19,6 +19,25 @@ const T_WEB_Ordini = require('../models/t_web_ordini');
|
||||
const T_Web_Argomenti = require('../models/t_web_argomenti');
|
||||
const { JobsInProgress } = require('../models/JobsInProgress');
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const csv = require('fast-csv');
|
||||
|
||||
// Mappa i campi semplici (senza prefisso 'productInfo.')
|
||||
const campiProductInfo = [
|
||||
'code',
|
||||
'descr_trafiletto_catalogo',
|
||||
'sottotitolo',
|
||||
'descrizione_completa_macro',
|
||||
'img2',
|
||||
'img3',
|
||||
'img4',
|
||||
'link',
|
||||
'checkout_link',
|
||||
];
|
||||
|
||||
const CSV_PATH = path.resolve(__dirname, '../products.csv');
|
||||
|
||||
class Macro {
|
||||
constructor(idapp, options) {
|
||||
this.idapp = idapp;
|
||||
@@ -445,6 +464,7 @@ class Macro {
|
||||
if (recproducts.length > 10 && lavoromassivo && options.rimuovieventualiCancellati) {
|
||||
// disattiva dalla tabella product tutti i campi date_updated_fromGM
|
||||
const result = await Product.updateMany({ idapp: options.idapp }, { $unset: { date_updated_fromGM: null } });
|
||||
|
||||
let quanti_rimossi = result.modifiedCount;
|
||||
console.log(`Sbianca date_updated_fromGM da Product: (${quanti_rimossi} su ${result.matchedCount})`);
|
||||
rimuoviTabellePerIniziare = true;
|
||||
@@ -649,7 +669,9 @@ class Macro {
|
||||
{ new: true, upsert: false, returnOriginal: false }
|
||||
).lean();
|
||||
|
||||
product.productInfo = this.preparaProductInfo(product);
|
||||
const productInfoOriginale = risprod?.productInfo || {};
|
||||
const productInfoAggiornata = this.preparaProductInfo(product);
|
||||
product.productInfo = { ...productInfoOriginale, ...productInfoAggiornata };
|
||||
await this.gestisciCategorie(product);
|
||||
await this.gestisciAutori(product);
|
||||
await this.gestisciEditore(product);
|
||||
@@ -670,7 +692,6 @@ class Macro {
|
||||
await this.gestisciGasOrdine(product);
|
||||
await this.gestisciVariazioni(product, options);
|
||||
|
||||
|
||||
const imagefile = await this.aggiornaImmagineSeNecessario(risprod, forzacaricamento || dataFutura);
|
||||
if (imagefile) {
|
||||
product.productInfo.imagefile = imagefile;
|
||||
@@ -1217,6 +1238,96 @@ class Macro {
|
||||
|
||||
return mystr;
|
||||
}
|
||||
|
||||
async EsportaInfoProductExtra() {
|
||||
console.log('EsportaInfoProductExtra...');
|
||||
|
||||
try {
|
||||
const products = await Product.find({}, campiProductInfo.map((f) => `productInfo.${f}`).join(' ')).lean();
|
||||
|
||||
const ws = fs.createWriteStream(CSV_PATH);
|
||||
|
||||
let prodExported = 0;
|
||||
|
||||
// Scrivi l'intestazione
|
||||
const header = ['code', ...campiProductInfo.slice(1)]; // 'code' è il primo campo
|
||||
await new Promise((resolve, reject) => {
|
||||
const csvStream = csv.format({ headers: header });
|
||||
csvStream.pipe(ws);
|
||||
|
||||
for (const p of products) {
|
||||
const row = campiProductInfo.map((field) => p.productInfo?.[field] ?? '');
|
||||
const rowToExport = campiProductInfo.slice(1).some((field) => p.productInfo && p.productInfo[field]);
|
||||
if (rowToExport) {
|
||||
csvStream.write(row);
|
||||
prodExported++;
|
||||
}
|
||||
}
|
||||
csvStream.end();
|
||||
ws.on('finish', resolve);
|
||||
ws.on('error', reject);
|
||||
});
|
||||
|
||||
console.log(`Esportazione completata: ${prodExported} su ${products.length} prodotti salvati in ${CSV_PATH}`);
|
||||
return prodExported;
|
||||
} catch (error) {
|
||||
console.error("Errore durante l'esportazione:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
async ImportaInfoProductExtra() {
|
||||
console.log('ImportaInfoProductExtra...');
|
||||
|
||||
const records = [];
|
||||
try {
|
||||
await new Promise((resolve, reject) => {
|
||||
const rs = fs.createReadStream(CSV_PATH);
|
||||
rs.pipe(csv.parse({ headers: true }))
|
||||
.on('error', reject)
|
||||
.on('data', (row) => {
|
||||
// Costruisci un oggetto productInfo corretto
|
||||
const productInfo = {};
|
||||
for (const field of campiProductInfo) {
|
||||
productInfo[field] = row[field] ?? '';
|
||||
}
|
||||
records.push({
|
||||
code: row.code, // usato per la ricerca
|
||||
productInfo,
|
||||
});
|
||||
})
|
||||
.on('end', resolve);
|
||||
});
|
||||
|
||||
console.log(`Letti ${records.length} record da ${CSV_PATH}`);
|
||||
|
||||
let aggiornati = 0;
|
||||
for (const { code, productInfo } of records) {
|
||||
if (!code) continue;
|
||||
|
||||
// Costruisci un oggetto $set con i campi annidati
|
||||
const update = {};
|
||||
for (const [key, value] of Object.entries(productInfo)) {
|
||||
// Salta il campo 'code' perché è usato per la ricerca, non va aggiornato
|
||||
if (key === 'code') continue;
|
||||
update[`productInfo.${key}`] = value;
|
||||
}
|
||||
|
||||
const result = await Product.findOneAndUpdate(
|
||||
{ 'productInfo.code': code },
|
||||
{ $set: update },
|
||||
{ upsert: false, new: true }
|
||||
).lean();
|
||||
|
||||
if (result) aggiornati++;
|
||||
}
|
||||
|
||||
console.log(`Aggiornati ${aggiornati} prodotti.`);
|
||||
return aggiornati;
|
||||
} catch (error) {
|
||||
console.error("Errore durante l'importazione:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Macro;
|
||||
|
||||
40771
src/server/products copia.csv
Normal file
40771
src/server/products copia.csv
Normal file
File diff suppressed because one or more lines are too long
39228
src/server/products.csv
Normal file
39228
src/server/products.csv
Normal file
File diff suppressed because one or more lines are too long
@@ -1858,8 +1858,13 @@ router.post('/duprec/:table/:id', authenticate, async (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
router.get('/loadsite/:userId/:idapp', authenticate_noerror_WithUserLean, (req, res) => {
|
||||
load(req, res, '0');
|
||||
router.get('/loadsite/:userId/:idapp', authenticate_noerror_WithUserLean, async (req, res) => {
|
||||
try {
|
||||
await load(req, res, '0');
|
||||
} catch (e) {
|
||||
console.error('loadsite error', e);
|
||||
res.status(500).send({ error: 'Impossibile caricare il sito' });
|
||||
}
|
||||
});
|
||||
|
||||
// Funzione di test per misurare le performance di MongoDB
|
||||
@@ -2073,6 +2078,7 @@ async function load(req, res, version = '0') {
|
||||
crons: version >= 91 ? Cron.findAllIdApp() : Promise.resolve([]),
|
||||
raccoltacataloghis: version >= 91 ? RaccoltaCataloghi.findAllIdApp(idapp) : Promise.resolve([]),
|
||||
myuserextra: req.user ? User.addExtraInfo(idapp, req.user, version) : Promise.resolve(null),
|
||||
statuscode2: version >= 91 ? req.statuscode2 : Promise.resolve([]),
|
||||
};
|
||||
|
||||
// Esecuzione parallela di tutte le promesse
|
||||
@@ -2187,6 +2193,7 @@ async function load(req, res, version = '0') {
|
||||
tipoformato: data.tipoformato,
|
||||
crons: data.crons,
|
||||
raccoltacataloghis: data.raccoltacataloghis,
|
||||
statuscode2: data.statuscode2,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2203,7 +2210,7 @@ router.get(process.env.LINK_CHECK_UPDATES, authenticate_noerror, async (req, res
|
||||
|
||||
// console.log("POST " + process.env.LINK_CHECK_UPDATES + " userId=" + userId);
|
||||
if (!req.user) {
|
||||
return res.status(200).send();
|
||||
return res.status(req.code).send();
|
||||
}
|
||||
|
||||
await CfgServer.find({ idapp })
|
||||
|
||||
@@ -27,11 +27,9 @@ router.post('/', authenticate, async (req, res) => {
|
||||
} else {
|
||||
return res.send({ code: server_constants.RIS_CODE_ERR, notif: '' });
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
router.get('/setall/:username/:qualinotif/:idapp', authenticate, async (req, res) => {
|
||||
|
||||
const idapp = req.params.idapp;
|
||||
const username = req.params.username;
|
||||
const qualinotif = parseInt(req.params.qualinotif);
|
||||
@@ -58,11 +56,9 @@ router.get('/setall/:username/:qualinotif/:idapp', authenticate, async (req, res
|
||||
} catch (e) {
|
||||
res.status(400).send(e);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
router.get('/set/:_id/:idapp', authenticate, async (req, res) => {
|
||||
|
||||
const _id = req.params._id;
|
||||
const username_call = req.user.username;
|
||||
|
||||
@@ -76,19 +72,14 @@ router.get('/set/:_id/:idapp', authenticate, async (req, res) => {
|
||||
return res.send(true);
|
||||
}
|
||||
res.send(false);
|
||||
|
||||
} catch (e) {
|
||||
res.status(400).send(e);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
async function delNotif(res, idapp, username, id, username_call) {
|
||||
|
||||
try {
|
||||
if (username === username_call) {
|
||||
|
||||
await SendNotif.findOneAndDelete({ idapp, _id: id });
|
||||
return res.send(true);
|
||||
}
|
||||
@@ -97,22 +88,17 @@ async function delNotif(res, idapp, username, id, username_call) {
|
||||
}
|
||||
|
||||
return res.send(false);
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
router.get('/del/:username/:id/:idapp', authenticate, async (req, res) => {
|
||||
|
||||
try {
|
||||
return delNotif(res, req.params.idapp, req.params.username, req.params.id, req.user.username);
|
||||
|
||||
} catch (e) {
|
||||
return res.status(400).send(e);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
router.get('/delall/:username/:qualinotif/:idapp', authenticate, async (req, res) => {
|
||||
|
||||
const idapp = req.params.idapp;
|
||||
const username = req.params.username;
|
||||
const qualinotif = parseInt(req.params.qualinotif);
|
||||
@@ -128,15 +114,13 @@ router.get('/delall/:username/:qualinotif/:idapp', authenticate, async (req, res
|
||||
query.typedir = { $ne: shared_consts.TypeNotifs.TYPEDIR_CIRCUITS };
|
||||
}
|
||||
const ris = await SendNotif.deleteMany(query);
|
||||
if (ris)
|
||||
return res.send(true);
|
||||
if (ris) return res.send(true);
|
||||
}
|
||||
} catch (e) {
|
||||
return res.status(400).send(e);
|
||||
}
|
||||
|
||||
return res.send(false);
|
||||
|
||||
});
|
||||
|
||||
router.get('/:username/:lastdataread/:idapp', authenticate_noerror, (req, res) => {
|
||||
@@ -144,7 +128,6 @@ router.get('/:username/:lastdataread/:idapp', authenticate_noerror, (req, res) =
|
||||
});
|
||||
|
||||
async function getNotif(req, res) {
|
||||
|
||||
try {
|
||||
// tools.mylog('GET NotifS : ', req.params);
|
||||
const username = req.params.username;
|
||||
@@ -152,33 +135,54 @@ async function getNotif(req, res) {
|
||||
const idapp = req.params.idapp;
|
||||
|
||||
// var category = req.params.category;
|
||||
if (!req.user) {
|
||||
return res.status(200).send();
|
||||
}
|
||||
|
||||
if (req.user.idapp !== idapp) {
|
||||
// I'm trying to get something not mine!
|
||||
return res.status(404).send({ code: server_constants.RIS_CODE_NOT_MY_USERNAME });
|
||||
}
|
||||
|
||||
const arrnotif = await SendNotif.findAllNotifByUsernameIdAndIdApp(username, lastdataread, idapp, shared_consts.LIMIT_NOTIF_FOR_USER, shared_consts.QualiNotifs.OTHERS);
|
||||
const arrnotif = await SendNotif.findAllNotifByUsernameIdAndIdApp(
|
||||
username,
|
||||
lastdataread,
|
||||
idapp,
|
||||
shared_consts.LIMIT_NOTIF_FOR_USER,
|
||||
shared_consts.QualiNotifs.OTHERS
|
||||
);
|
||||
let arrnotifcoins_inattesa = null;
|
||||
|
||||
if (await User.isAdminByUsername(idapp, req.user.username)) {
|
||||
arrnotifcoins_inattesa = await SendNotif.findAllNotifCoinsAllIdAndIdApp(idapp);
|
||||
} else {
|
||||
arrnotifcoins_inattesa = await SendNotif.findAllNotifByUsernameIdAndIdApp(username, lastdataread, idapp, shared_consts.LIMIT_NOTIFCOINS_IN_ATTESA_FOR_USER, shared_consts.QualiNotifs.CIRCUITS, [{ status: 0 }]);
|
||||
arrnotifcoins_inattesa = await SendNotif.findAllNotifByUsernameIdAndIdApp(
|
||||
username,
|
||||
lastdataread,
|
||||
idapp,
|
||||
shared_consts.LIMIT_NOTIFCOINS_IN_ATTESA_FOR_USER,
|
||||
shared_consts.QualiNotifs.CIRCUITS,
|
||||
[{ status: 0 }]
|
||||
);
|
||||
}
|
||||
|
||||
const arrnotifcoins = await SendNotif.findAllNotifByUsernameIdAndIdApp(username, lastdataread, idapp, shared_consts.LIMIT_NOTIFCOINS_FOR_USER, shared_consts.QualiNotifs.CIRCUITS, [{ status: {$ne: 0 }}]);
|
||||
|
||||
const arrnotifcoins = await SendNotif.findAllNotifByUsernameIdAndIdApp(
|
||||
username,
|
||||
lastdataread,
|
||||
idapp,
|
||||
shared_consts.LIMIT_NOTIFCOINS_FOR_USER,
|
||||
shared_consts.QualiNotifs.CIRCUITS,
|
||||
[{ status: { $ne: 0 } }]
|
||||
);
|
||||
|
||||
//++Todo: Ottimizzare ! Non occorre inviare tutti questi dati !!! Solo per il Circuito ?!
|
||||
const userprofile = await User.getExtraInfoByUsername(idapp, req.user.username);
|
||||
|
||||
return res.send({ arrnotif, arrnotifcoins: [...arrnotifcoins, ...arrnotifcoins_inattesa], userprofile });
|
||||
|
||||
} catch (e) {
|
||||
console.log(e.message);
|
||||
res.status(400).send(e);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = router;
|
||||
|
||||
@@ -94,13 +94,16 @@ router.delete('/del', authenticate, async (req, res) => {
|
||||
// tools.mylog("TOKENREM = " + req.token);
|
||||
try {
|
||||
|
||||
const browser = req.get('User-Agent');
|
||||
return await Subscription.findOneAndDelete(
|
||||
{ userId: req.user._id, access: req.access, browser }).then(() => {
|
||||
res.status(200).send();
|
||||
}, () => {
|
||||
res.status(400).send();
|
||||
});
|
||||
if (req.user) {
|
||||
const browser = req.get('User-Agent');
|
||||
return await Subscription.findOneAndDelete(
|
||||
{ userId: req.user._id, access: req.access, browser }).then(() => {
|
||||
res.status(200).send();
|
||||
}, () => {
|
||||
res.status(400).send();
|
||||
});
|
||||
}
|
||||
res.status(400).send();
|
||||
} catch (e) {
|
||||
console.error('Err:', e.message);
|
||||
}
|
||||
|
||||
@@ -659,8 +659,8 @@ router.post('/newtok', async (req, res) => {
|
||||
return res.status(400).send({ error: 'Refresh token mancante' });
|
||||
}
|
||||
|
||||
const recFound = await User.findOne({ 'tokens.refreshToken': refreshToken });
|
||||
|
||||
const recFound = await User.findByRefreshTokenAnyAccess(refreshToken);
|
||||
|
||||
if (!recFound) {
|
||||
return res.status(403).send({ error: 'Refresh token non valido' });
|
||||
}
|
||||
|
||||
@@ -86,24 +86,10 @@ module.exports = {
|
||||
paramemail.send = !previewonly;
|
||||
}
|
||||
|
||||
// if (!transport) {
|
||||
// transport = this.getTransport(mylocalsconf);
|
||||
// }
|
||||
|
||||
|
||||
if (transport) {
|
||||
paramemail.transport = transport;
|
||||
} else {
|
||||
paramemail.transport = this.getTransport(mylocalsconf);
|
||||
/*
|
||||
// console.log('1b . transport gmail');
|
||||
paramemail.transport = {
|
||||
service: 'gmail',
|
||||
auth: {
|
||||
user: tools.getEmailByIdApp(mylocalsconf.idapp),
|
||||
pass: tools.getPwdByIdApp(mylocalsconf.idapp)
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
// se non è presente la password, non inviare l'email e manda messaggio di errore !
|
||||
|
||||
@@ -801,6 +801,7 @@ connectToDatabase(connectionUrl, options)
|
||||
'https://localhost:8085',
|
||||
'https://localhost:8088',
|
||||
'https://localhost:8099',
|
||||
'https://localhost:8094',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -970,7 +970,7 @@ const MyTelegramBot = {
|
||||
|
||||
keyb = cl.getInlineKeyboard(myuser.lang, [
|
||||
{
|
||||
text: '✅ Abilita fiducia a ' + myuser.username,
|
||||
text: '✅ Abilita fiducia a ' + myuser.username + ' in ' + name,
|
||||
callback_data:
|
||||
InlineConferma.RISPOSTA_SI +
|
||||
myfunc + tools.SEP +
|
||||
@@ -2506,7 +2506,7 @@ class Telegram {
|
||||
file = '~/batch/test_restart_server.sh';
|
||||
}
|
||||
|
||||
let messaggio = this.chisono(rec) + ' Restart il Server (Node.Js) : ' + process.version;
|
||||
let messaggio = this.chisono(rec) + ' Restart il Server (Node.Js) : ' + file + ' ' + process.version;
|
||||
|
||||
messaggio += '\nVersione Server: ' + (await tools.getVersServer());
|
||||
|
||||
|
||||
@@ -1247,8 +1247,8 @@ module.exports = {
|
||||
cmdrichiesta,
|
||||
myuserdata,
|
||||
usernameDest,
|
||||
'',
|
||||
circuitname,
|
||||
'',
|
||||
myreccircuit._id,
|
||||
'',
|
||||
extrarec.groupname
|
||||
@@ -6082,25 +6082,30 @@ module.exports = {
|
||||
} catch (e) {
|
||||
aggiornatoimg = { ris: false };
|
||||
}
|
||||
let nontrovato = false;
|
||||
if (
|
||||
aggiornatoimg?.code === 404 ||
|
||||
(aggiornatoimg?.filepath && aggiornatoimg?.filepath?.includes('noimg.jpg'))
|
||||
) {
|
||||
nontrovato = true;
|
||||
// non trovato quindi la prossima volta non richiederlo
|
||||
await Product.setImgNotFound(product._id);
|
||||
}
|
||||
|
||||
if (aggiornatoimg?.filepath?.includes('noimg.jpg')) {
|
||||
// nascondi il prodotto se non trovo l'immagine !
|
||||
await Product.updateOne({ _id: product._id }, { $set: { deleted: true } });
|
||||
|
||||
aggiornatoimg = { ris: false, deleted: true };
|
||||
// nascondi il prodotto se non trovo l'immagine !
|
||||
// await Product.updateOne({ _id: product._id }, { $set: { deleted: true } });
|
||||
|
||||
aggiornatoimg = { ris: false, deleted: true };
|
||||
}
|
||||
|
||||
if (aggiornatoimg?.filepath) {
|
||||
const filenamebase = path.basename(aggiornatoimg.filepath);
|
||||
// const img = '/upload/products/' + filenamebase;
|
||||
imagefile = filenamebase;
|
||||
if (nontrovato) {
|
||||
imagefile = '';
|
||||
}
|
||||
}
|
||||
|
||||
return { imagefile, aggiornatoimg: aggiornatoimg.ris };
|
||||
@@ -6236,6 +6241,17 @@ module.exports = {
|
||||
return mydate;
|
||||
},
|
||||
|
||||
areDifferentArrayString(array1, array2) {
|
||||
// confronta l'array1 con l'array2 (sono array di stringhe) e torna se sono diversi
|
||||
return !array1.every((val, index) => array2[index] === val);
|
||||
},
|
||||
|
||||
areDifferentProduct(array1prod, array2prod) {
|
||||
// confronta l'array1 con l'array2 e torna se sono diversi
|
||||
// la struttura è product.productInfo.code , quindi puoi controllare se sono uguali il code
|
||||
return !array1prod.every((val1, index) => array2prod[index].productInfo.code === val1.productInfo.code);
|
||||
},
|
||||
|
||||
getvalueByJsonText(valore) {
|
||||
if (valore && valore['#text']) {
|
||||
if (valore['#text']) return valore['#text'];
|
||||
|
||||
@@ -973,6 +973,7 @@ module.exports = {
|
||||
max_partecip: 1,
|
||||
contribstr: 1,
|
||||
link_maplocation: 1,
|
||||
link_conference: 1,
|
||||
//**ADDFIELD_MYBACHECAS
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
1.2.71
|
||||
1.2.72
|
||||
0
upload/products.csv
Normal file
0
upload/products.csv
Normal file
|
|
Reference in New Issue
Block a user