diff --git a/.env.development b/.env.development
index 3136acd..4e08963 100644
--- a/.env.development
+++ b/.env.development
@@ -1,4 +1,4 @@
-DATABASE=test_FreePlanet
+DATABASE=test_PiuCheBuono
UDB=paofreeplanet
PDB=mypassword@1A
SEND_EMAIL=0
diff --git a/src/server/locales/it.json b/src/server/locales/it.json
index 1e6ec92..5401f34 100644
--- a/src/server/locales/it.json
+++ b/src/server/locales/it.json
@@ -8,7 +8,9 @@
"NEW_HOSP": "❇️ %s ha aggiunto una nuova Ospitalità: \n%s",
"NEW_EVENT": "❇️ %s ha aggiunto un nuovo Evento: \n%s\n%s\n%s",
"NEW_EVENT_TELEGRAM": "%s\n\n❇️ %s\n\n%s\n\n%s",
- "ADDED_FROM": "\n\n(Evento aggiunto da %s)",
+ "NEW_ANNUNCIO_TELEGRAM": "❇️ %s\n\n%s\n\n%s",
+ "EVENT_ADDED_FROM": "\n\n(Evento aggiunto da %s)",
+ "ADDED_FROM": "\n\n(Aggiunto da %s)",
"CONTRIB": "\n💠 Contributo richiesto: %s",
"ORGANIZED_BY": "\nOrganizzato da %s",
"SHOW_POST": "👉🏻 vedi post su RISO",
diff --git a/src/server/models/circuit.js b/src/server/models/circuit.js
index efa7ccb..b4f20f7 100755
--- a/src/server/models/circuit.js
+++ b/src/server/models/circuit.js
@@ -593,6 +593,7 @@ CircuitSchema.statics.getUsersSingleCircuit = async function (idapp, username, c
{
$project: {
username: 1,
+ verified_by_aportador: 1,
name: 1,
surname: 1,
profile: 1,
diff --git a/src/server/models/movement.js b/src/server/models/movement.js
index 8894d2d..087f2e5 100755
--- a/src/server/models/movement.js
+++ b/src/server/models/movement.js
@@ -366,16 +366,20 @@ MovementSchema.statics.getQueryMovsByCircuitId = async function (idapp, username
notifId: 1,
'circuitfrom.symbol': 1,
'circuitto.symbol': 1,
+ 'userfrom.verified_by_aportador': 1,
'userfrom.username': 1,
'userfrom.profile.img': 1,
'userto.username': 1,
'userto.profile.img': 1,
+ 'userto.verified_by_aportador': 1,
'groupfrom.groupname': 1,
+ 'groupfrom.verified_by_aportador': 1,
'groupfrom.title': 1,
'groupfrom.photos': 1,
'groupto.groupname': 1,
'groupto.title': 1,
'groupto.photos': 1,
+ 'groupto.verified_by_aportador': 1,
'contocomfrom.path': 1,
'contocomfrom.name': 1,
'contocomto.path': 1,
diff --git a/src/server/models/productInfo.js b/src/server/models/productInfo.js
index 0e724d8..11b66f5 100755
--- a/src/server/models/productInfo.js
+++ b/src/server/models/productInfo.js
@@ -42,24 +42,34 @@ const productInfoSchema = new Schema({
type: String
},
size: {
- type: String
+ type: String // 11x4x3
},
weight: {
type: Number
},
- vegan: {
- type: Boolean
+ weight_lordo: {
+ type: Number
},
unit: {
type: Number,
default: 0,
},
+ unit_lordo: {
+ type: Number,
+ default: 0,
+ },
+ vegan: {
+ type: Boolean
+ },
icon: {
type: String,
},
img: {
type: String,
},
+ link_scheda: {
+ type: String,
+ },
link: {
type: String,
},
diff --git a/src/server/models/search.js b/src/server/models/search.js
index 6b6ed58..66d628f 100755
--- a/src/server/models/search.js
+++ b/src/server/models/search.js
@@ -20,6 +20,10 @@ const searchSchema = new Schema({
userId: {
type: String,
},
+ date_created: {
+ type: Date,
+ default: Date.now,
+ },
text: {
type: String,
},
diff --git a/src/server/models/sendnotif.js b/src/server/models/sendnotif.js
index 29540df..de14c61 100755
--- a/src/server/models/sendnotif.js
+++ b/src/server/models/sendnotif.js
@@ -217,7 +217,10 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function (recnotif, us
recnotif.openUrl = shared_consts.getDirectoryByTable(shared_consts.TABLES_MYHOSPS, true) + myidrec;
tag = 'newhosp';
}
- recnotif.linkaddTelegram = 'Vedi annuncio';
+ let eventobj = await tools.getAnnuncioForTelegram(recnotif.myrectableorig, mydescr, userorig);
+ newdescr = eventobj.newdescr;
+ recnotif.textcontent_Telegram = eventobj.newdescrtelegram;
+ recnotif.linkaddTelegram = i18n.__('SHOW_POST');
} else if (recnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_EVENTS) {
recnotif.openUrl = shared_consts.getDirectoryByTable(shared_consts.TABLES_MYBACHECAS, true) + myidrec;
tag = 'newevent';
diff --git a/src/server/models/user.js b/src/server/models/user.js
index 53538d1..d8a2cbe 100755
--- a/src/server/models/user.js
+++ b/src/server/models/user.js
@@ -4191,6 +4191,7 @@ UserSchema.statics.getLastOnlineUsers = async function (idapp) {
surname: 1,
lasttimeonline: 1,
date_reg: 1,
+ verified_by_aportador: 1,
'profile.img': 1,
index: 1,
}).sort({ lasttimeonline: -1 }).limit(lastn).then((arr) => {
@@ -4217,6 +4218,7 @@ UserSchema.statics.getLastSharedLink = async function (idapp) {
name: 1,
surname: 1,
lasttimeonline: 1,
+ verified_by_aportador: 1,
date_reg: 1,
'profile.img': 1,
index: 1,
@@ -4370,6 +4372,47 @@ UserSchema.statics.getUsersRegDaily = function (idapp, nrec) {
return query;
};
+UserSchema.statics.getUsersRegDailyAverage = function (idapp, nrec) {
+ const query = [
+ {
+ $match: {
+ idapp,
+ date_reg: { $gte: tools.IncDateNow(-(1000 * 60 * 60 * 24 * nrec)) },
+ $or: [
+ { deleted: { $exists: false } },
+ { deleted: { $exists: true, $eq: false } }
+ ],
+ },
+ },
+ {
+ $group: {
+ _id: {
+ $dateToString: {
+ format: '%Y-%m-%d',
+ date: '$date_reg',
+ timezone: 'Europe/Rome',
+ },
+ },
+ count: { $sum: 1 },
+ },
+ },
+ {
+ $group: {
+ _id: null,
+ total: { $sum: '$count' },
+ days: { $sum: 1 },
+ },
+ },
+ {
+ $project: {
+ _id: 0,
+ dailyAverage: { $divide: ['$total', '$days'] },
+ },
+ },
+ ];
+ return query;
+};
+
UserSchema.statics.getQueryUsersDiffusori = function (idapp) {
const query = [
@@ -4461,6 +4504,7 @@ UserSchema.statics.getQueryUsersDiffusori = function (idapp) {
idapp: 1,
"profile.img": 1,
'profile.mycircuits': 1,
+ 'profile.handshake': 1,
},
},
];
@@ -4668,6 +4712,19 @@ UserSchema.statics.getUsersRegWeekly = function (idapp, nrec) {
count: { $sum: 1 },
},
},
+ {
+ $group: {
+ _id: null, // Raggruppa tutti i risultati
+ total: { $sum: '$count' }, // Calcola il numero totale di iscritti
+ days: { $sum: 1 }, // Calcola il numero totale di giorni
+ },
+ },
+ {
+ $project: {
+ _id: 0, // Escludi il campo _id dal risultato finale
+ dailyAverage: { $divide: ['$total', '$days'] }, // Calcola la media giornaliera
+ },
+ },
{
$sort: { _id: 1 },
},
@@ -4715,6 +4772,36 @@ UserSchema.statics.calcnumRegUntilDay = async function (idapp) {
};
+function calculate30DayAverage(data) {
+ const averages = [];
+
+ for (let i = 0; i < data.length; i++) {
+ const startDate = new Date(data[i]._id);
+ let sum = data[i].count;
+ let count = 1;
+
+ for (let j = i + 1; j < data.length; j++) {
+ const currentDate = new Date(data[j]._id);
+ const diffInTime = Math.abs(startDate.getTime() - currentDate.getTime());
+ const diffInDays = Math.ceil(diffInTime / (1000 * 60 * 60 * 24));
+
+ if (diffInDays <= 30) {
+ sum += data[j].count;
+ count++;
+ } else {
+ break;
+ }
+ }
+
+ averages.push({
+ _id: data[i]._id,
+ dailyAverage: sum / count
+ });
+ }
+
+ return averages;
+}
+
UserSchema.statics.calcRegDaily = async function (idapp) {
const User = this;
@@ -4724,12 +4811,14 @@ UserSchema.statics.calcRegDaily = async function (idapp) {
});
};
+
+
UserSchema.statics.calcRegWeekly = async function (idapp) {
const User = this;
- return await User.aggregate(User.getUsersRegWeekly(idapp, 20 * 7)).then(ris => {
+ return await User.aggregate(User.getUsersRegDaily(idapp, 120)).then(ris => {
// console.table(ris);
- return ris.slice(0, -1);
+ return calculate30DayAverage(ris);
});
};
diff --git a/src/server/router/admin_router.js b/src/server/router/admin_router.js
index 457ce09..b9bb927 100755
--- a/src/server/router/admin_router.js
+++ b/src/server/router/admin_router.js
@@ -38,6 +38,151 @@ router.post('/updateval', authenticate, async (req, res) => {
});
+function fixURL(url) {
+ return url.replace(/https:\//g, 'https://');
+}
+
+
+function completaSettaggioProduct_AndProductInfo(arrcampi_productInfo, arrcampi_product, rec, product, productInfo) {
+
+ try {
+ if (shared_consts.CAMPI_PRODUCTINFO_CONVERT.includes('weight_and_unit')) {
+ const ris1 = tools.getWeightAndUnitByText(rec['weight_and_unit']);
+ if (ris1) {
+ productInfo.weight = ris1.weight;
+ productInfo.unit = ris1.unit;
+ }
+
+ }
+
+ if (shared_consts.CAMPI_PRODUCTINFO_CONVERT.includes('weight_and_unit_lordo')) {
+ const ris2 = tools.getWeightAndUnitByText(rec['weight_and_unit_lordo']);
+ if (ris2) {
+ productInfo.weight_lordo = ris2.weight;
+ productInfo.unit_lordo = ris2.unit;
+ }
+ }
+
+ if (rec.hasOwnProperty('link_scheda')) {
+ productInfo['link_scheda'] = fixURL(rec['link_scheda'])
+ }
+
+ for (const campo of shared_consts.PRODUCTINFO.CAMPI_FIRST_UPPERCASE) {
+ if (rec.hasOwnProperty(campo)) {
+ productInfo[campo] = tools.capitalize(rec[campo]);
+ }
+ }
+
+ // Conversione in Euro
+ for (campoprezzo of shared_consts.CAMPI_EURO) {
+ if (rec.hasOwnProperty(campoprezzo)) {
+ product[campoprezzo] = tools.convertPriceEurToValue(rec[campoprezzo])
+
+ }
+ }
+
+ if (!productInfo.img && product.code) {
+ productInfo.img = 'upload/products/' + product.code + '.jpg';
+ }
+
+ return { product, productInfo };
+
+ } catch (e) {
+ console.error('Err', e);
+ }
+
+
+ return { product, productInfo };
+}
+
+function getValoriAndIndice(dati, arrinclude) {
+ const campi = dati;
+
+ for (const key in campi) {
+ if (Object.hasOwnProperty.call(obj, key)) {
+ const value = obj[key];
+ console.log(`${key}: ${value}`);
+ }
+ }
+
+ const risultato = campi.map((campo, indice) => {
+ let mycampo = campo.trim();
+ if (arrinclude) {
+ if (arrinclude.includes(mycampo))
+ return { name: mycampo, ind: indice };
+ } else {
+ return { name: mycampo, ind: indice };
+ }
+
+ });
+
+ return risultato;
+}
+
+function getValoriAndIndice_ProductInfo(dati) {
+ //return getValoriAndIndice(dati, shared_consts.CAMPI_PRODUCTINFO)
+ return shared_consts.CAMPI_PRODUCTINFO;
+}
+
+function getValoriAndIndice_Product(dati) {
+ //return getValoriAndIndice(dati, shared_consts.CAMPI_PRODUCT);
+ return shared_consts.CAMPI_PRODUCT;
+}
+
+function extractArrayDataFromCSV(idapp, rec) {
+
+ try {
+ // la prima riga contiene il nome della proprietà:
+ let productInfo = {
+ idapp: idapp,
+ idCatProds: [],
+ idSubCatProds: [],
+ };
+
+ let product = {
+ idapp,
+ };
+
+ arrcampi_productInfo = getValoriAndIndice_ProductInfo(null);
+ arrcampi_product = getValoriAndIndice_Product(null);
+
+ for (const campoobj of arrcampi_productInfo) {
+ if (rec.hasOwnProperty(campoobj))
+ productInfo[campoobj] = rec[campoobj];
+ }
+
+ for (const campoobj of arrcampi_product) {
+ if (rec.hasOwnProperty(campoobj))
+ product[campoobj] = rec[campoobj];
+ }
+
+ const ris = completaSettaggioProduct_AndProductInfo(arrcampi_productInfo, arrcampi_product, rec, product, productInfo);
+
+ /*
+ // code: product.code,
+ name: product.name,
+ link: product.link,
+ idCatProds: [],
+ idSubCatProds: [],
+ img: 'upload/products/' + product.code + '.jpg',
+ weight: product.weight,
+ unit: tools.getIdUnitsByText(product.unit),
+ }
+
+
+ */
+
+ return ris;
+
+
+ } catch (e) {
+ console.error('Err', e);
+ }
+
+ return dataObjects;
+
+};
+
router.post('/import', authenticate, async (req, res) => {
const cmd = req.body.cmd;
const idapp = req.body.idapp;
@@ -64,7 +209,7 @@ router.post('/import', authenticate, async (req, res) => {
let inventario = recinv;
inventario.idapp = idapp;
-
+
let risrec = await Inventariogm.findOneAndUpdate(queryprod, { $set: inventario }, { new: true, upsert: true });
}
@@ -97,7 +242,7 @@ router.post('/import', authenticate, async (req, res) => {
arrcat = product.cat_name.trim().split(',');
for (const mycat of arrcat) {
let mycatstr = mycat.trim();
-
+
// Cerca la Categoria
reccateg = await CatProd.findOne({ idapp, name: mycatstr }).lean();
if (!reccateg) {
@@ -117,7 +262,7 @@ router.post('/import', authenticate, async (req, res) => {
arrsubcat = product.subcat_name.trim().split(',');
for (const mysubcat of arrsubcat) {
let mysubcatstr = mysubcat.trim();
-
+
// Cerca la Sotto Categoria
let recsubcateg = await SubCatProd.findOne({ idapp, name: mysubcatstr }).lean();
if (!recsubcateg) {
@@ -176,16 +321,16 @@ router.post('/import', authenticate, async (req, res) => {
ris = await recGas.save();
recGas = await Gasordine.findOne({ idapp, name: product.gas_name }).lean();
}
-
+
let recProductExist = null;
let queryprod = { idProductInfo: product.idProductInfo };
-
+
if (recGas) {
- queryprod = {...queryprod, idGasordine: recGas._id};
+ queryprod = { ...queryprod, idGasordine: recGas._id };
}
recProductExist = await Product.findOne({ queryprod }).lean();
-
+
if (!recProductExist) {
isnuovo = true;
}
@@ -225,6 +370,154 @@ router.post('/import', authenticate, async (req, res) => {
}
}
+ } else if (cmd === shared_consts.Cmd.PRODUCTS_V2) {
+
+ let arrrec = JSON.parse(`[${data.arrdata}]`);
+
+ let updated = 0;
+ let imported = 0;
+ let errors = 0;
+
+ let ind = 0
+
+ const [, ...myarrshift] = arrrec;
+
+ for (const rec of myarrshift) {
+
+ let risprod = extractArrayDataFromCSV(idapp, rec);
+ let product = risprod.product;
+ let productInfo = risprod.productInfo;
+
+ let isnuovo = false
+ let setta = false
+
+ let reccateg = null;
+ if (rec.cat_name) {
+ arrcat = rec.cat_name.trim().split(',');
+ for (const mycat of arrcat) {
+ let mycatstr = mycat.trim();
+
+ // Cerca la Categoria
+ reccateg = await CatProd.findOne({ idapp, name: mycatstr }).lean();
+ if (!reccateg) {
+ // Non esiste questo produttore, quindi lo creo !
+ reccateg = new CatProd({ idapp, name: mycatstr });
+ ris = await reccateg.save();
+ reccateg = await CatProd.findOne({ idapp, name: mycatstr }).lean();
+ }
+
+ if (reccateg) {
+ productInfo.idCatProds.push(reccateg._id);
+ }
+ }
+ }
+
+ if (rec.subcat_name) {
+ arrsubcat = rec.subcat_name.trim().split(',');
+ for (const mysubcat of arrsubcat) {
+ let mysubcatstr = mysubcat.trim();
+
+ // Cerca la Sotto Categoria
+ let recsubcateg = await SubCatProd.findOne({ idapp, name: mysubcatstr }).lean();
+ if (!recsubcateg) {
+ // Non esiste questa Sotto Categoria, quindi la creo !
+ const idCatProd = reccateg ? reccateg._id : ''
+ recsubcateg = new SubCatProd({ idapp, name: mysubcatstr, idCatProd });
+ ris = await recsubcateg.save();
+ recsubcateg = await SubCatProd.findOne({ idapp, name: mysubcatstr, idCatProd }).lean();
+ }
+
+ if (recsubcateg) {
+ productInfo.idSubCatProds.push(recsubcateg._id);
+ }
+ }
+ }
+
+ if (!rec.hasOwnProperty('active')) {
+ product.active = true;
+ }
+
+ let esisteindb = await ProductInfo.findOne({ code: productInfo.code }).lean();
+
+ // Update ProductInfo
+ let risrecInfo = await ProductInfo.findOneAndUpdate({ code: productInfo.code }, { $set: productInfo }, { new: true, upsert: true });
+ if (risrecInfo) {
+ product.idProductInfo = risrecInfo._id;
+
+ recnewInfo = await ProductInfo.findOne({ code: productInfo.code }).lean();
+
+ if (risrecInfo._id) {
+ // Record existed, so it was updated
+ let arrfieldchange = tools.differentObjects(productInfo, recnewInfo);
+ if (arrfieldchange && arrfieldchange.length > 0) {
+ // updated++;
+ console.log('Changed: ', recnewInfo.name + ': ' + arrfieldchange);
+ }
+ }
+
+ // Cerca il GAS
+ let recGas = null;
+ if (rec.gas_name) {
+ // Cerca il GAS
+ recGas = await Gasordine.findOne({ idapp, name: rec.gas_name }).lean();
+ }
+
+ if (!recGas && !!rec.gas_name) {
+ recGas = new Gasordine({ idapp, name: rec.gas_name, active: true });
+ // Non esiste questo GAS, quindi lo creo !
+ ris = await recGas.save();
+ recGas = await Gasordine.findOne({ idapp, name: rec.gas_name }).lean();
+ }
+
+ let recProductExist = null;
+ let queryprod = { idProductInfo: product.idProductInfo };
+
+ if (recGas) {
+ queryprod = { ...queryprod, idGasordine: recGas._id };
+ }
+
+ recProductExist = await Product.findOne({ queryprod }).lean();
+
+ if (!recProductExist) {
+ isnuovo = true;
+ }
+
+ if (!options.aggiornaStockQty && esisteindb && !isnuovo) {
+ delete product.stockQty;
+ delete product.maxbookableGASQty;
+ }
+
+ // AGGIORNA PRODUCT
+ let risrec = await Product.findOneAndUpdate(queryprod, { $set: product }, { new: true, upsert: true });
+
+ let recnew = await Product.findOne(queryprod).lean();
+
+ if (risrec) {
+ if (risrec._id) {
+ // Record existed, so it was updated
+ let arrfieldchange = tools.differentObjects(product, recnew);
+ if (arrfieldchange.length > 0) {
+ updated++;
+ console.log('Changed: ', product.idProductInfo + ': ' + arrfieldchange);
+ }
+ } else {
+ // Record didn't exist, so it was created
+ imported++;
+ }
+ } else {
+ // risrec is null or undefined, indicating an error
+ console.error('Error: ', product.productInfo.name);
+ errors++;
+ }
+
+ await Product.singlerecconvert_AfterImport_AndSave(idapp, recnew, isnuovo);
+ } else {
+ console.error('Error ProductInfo: ', product.code);
+ errors++;
+ }
+
+ ind++;
+ }
// L'opzione ordered: false gestisce gli errori senza interrompere l'inserimento
/*return await Product.insertMany(dataObjects, { ordered: false })
diff --git a/src/server/router/users_router.js b/src/server/router/users_router.js
index 6515cfc..8f02db2 100755
--- a/src/server/router/users_router.js
+++ b/src/server/router/users_router.js
@@ -1245,6 +1245,8 @@ async function eseguiDbOp(idapp, mydata, locale, req, res) {
} else if (mydata.dbop === 'updateReactionsCounts') {
await Reaction.updateReactionsCounts();
+ } else if (mydata.dbop === 'removeRegulations') {
+ await Circuit.updateMany({}, { $set: { regulation: '' } });
} else if (mydata.dbop === 'newRecordsFav') {
// Passa le tabelle da users sulle nuove tabelle:
diff --git a/src/server/telegram/telegrambot.js b/src/server/telegram/telegrambot.js
index 9c525a5..998c675 100755
--- a/src/server/telegram/telegrambot.js
+++ b/src/server/telegram/telegrambot.js
@@ -711,15 +711,18 @@ const MyTelegramBot = {
} else {
arrTeleg = appTelegram;
}
- if (process.env.NODE_ENV === 'development')
+ if (process.env.NODE_ENV === 'development') {
arrTeleg = appTelegram_DEVELOP;
- else if (process.env.NODE_ENV === 'test')
+ } else if (process.env.NODE_ENV === 'test') {
arrTeleg = MyTelegramBot.getAppTelegramTest();
+ } else {
+ const arrTelegFromSite = tools.getArrTelegramFromSite();
+ if (arrTelegFromSite.length > 0) {
+ arrTeleg = arrTelegFromSite;
+ }
- const arrTelegFromSite = tools.getArrTelegramFromSite();
- if (arrTelegFromSite.length > 0) {
- arrTeleg = arrTelegFromSite;
}
+
return arrTeleg;
},
@@ -3927,7 +3930,7 @@ class Telegram {
user_profile.then(function (res) {
if (res.total_count === 0) {
// Non ho l'accesso oppure sono davvero senza foto !
-
+
}
if (res.photos[0]) {
var file_id = res.photos[0][2].file_id;
@@ -4100,7 +4103,7 @@ if (true) {
internetAvailable().then(() => {
// ..
- console.log('TELEGRAM STARTING.... ' + process.env.NODE_ENV);
+ console.log('TELEGRAM STARTING.... ', process.env.NODE_ENV);
for (const idapp of arrTeleg) {
diff --git a/src/server/tools/general.js b/src/server/tools/general.js
index 125cf60..66636ac 100755
--- a/src/server/tools/general.js
+++ b/src/server/tools/general.js
@@ -1841,11 +1841,11 @@ module.exports = {
for (const site of myapp) {
if (site.active) {
if (process.env.NODE_ENV === 'test') {
- if (myapp.load_process_telegram_test)
- arrteleg.push(myapp.idapp)
+ if (site.telegram_bot_name_test)
+ arrteleg.push(site.idapp)
} else {
- if (myapp.load_process_telegram)
- arrteleg.push(myapp.idapp)
+ if (site.telegram_bot_name)
+ arrteleg.push(site.idapp)
}
}
}
@@ -4305,7 +4305,7 @@ module.exports = {
async getDescrEstesaStrByEvent(myrec) {
let mystr = '';
- mystr = await this.firstchars(this.replaceStringAtEnd(myrec.note, '', ''), 400);
+ mystr = await this.firstchars(this.replaceStringAtEnd(myrec.note, '', ''), 800);
if (mystr)
mystr = 'ℹ️ ' + mystr
return mystr;
@@ -4328,6 +4328,32 @@ module.exports = {
if (contributo) {
newdescrtelegram += i18n.__('CONTRIB', contributo);
}
+ newdescrtelegram += i18n.__('EVENT_ADDED_FROM', userorig);
+
+ return { newdescr, newdescrtelegram }
+ } catch (e) {
+ console.error('Error', e);
+ }
+
+ },
+
+ async getAnnuncioForTelegram(myrec, mydescr, userorig) {
+ try {
+ let dovestr = this.getDoveStrByEvent(myrec);
+ let descrestesa = await this.getDescrEstesaStrByEvent(myrec);
+ let contributo = myrec.contribstr;
+
+ let newdescr = '';
+
+ if (myrec.adType === shared_consts.TypeNotifs.ID_BACHECA_NEW_GOOD) {
+ newdescr = i18n.__('NEW_GOOD', userorig, mydescr);
+ } else if (myrec.adType === shared_consts.TypeNotifs.ID_BACHECA_NEW_SERVICE) {
+ newdescr = i18n.__('NEW_SERVICE', userorig, mydescr);
+ } else if (myrec.adType === shared_consts.TypeNotifs.ID_BACHECA_NEW_HOSP) {
+ newdescr = i18n.__('NEW_HOSP', userorig, mydescr);
+ }
+ let newdescrtelegram = i18n.__('NEW_ANNUNCIO_TELEGRAM', mydescr, dovestr, descrestesa, userorig);
+
newdescrtelegram += i18n.__('ADDED_FROM', userorig);
return { newdescr, newdescrtelegram }
@@ -4336,6 +4362,7 @@ module.exports = {
}
},
+
generateVapiKey() {
const webpush = require('web-push');
@@ -4384,10 +4411,31 @@ module.exports = {
return unitrec ? unitrec.value : 0
},
+ getWeightAndUnitByText(text) {
+ const result = [];
+
+ text = text.replace(",", ".");
+ const regex = /^(\d+\.?\d*)\s*(ml|gr|l|kg)\s*$/; // Aggiunto un punto dopo \d+ per accettare anche i numeri con la virgola
+
+ const match = regex.exec(text);
+ if (match) {
+ let peso = parseFloat(match[1]); // Cambiato da parseInt a parseFloat per gestire i numeri con la virgola
+ let unita = match[2];
+ if (unita === 'gr')
+ unita = 'g'
+ const unit = this.getIdUnitsByText(unita);
+
+ return { weight: peso, unit };
+ }
+
+ return { weight: 0, unit: 0 };
+
+ },
+
async isManagerByReq(req) {
- try {
+ try {
var { User } = require('../models/user');
-
+
const idapp = req.body.idapp;
let userId = '';
if (req.body)
@@ -4406,5 +4454,32 @@ module.exports = {
}
},
+ addslashes(str) {
+ return (str + '').replace(/[\\"']/g, '\\$&').replace(/\u0000/g, '\\0')
+ },
+
+ removeescape(inputString) {
+ return inputString.replace('\\', '').replace(/"/g, '')
+ },
+
+ convertToNumeroVirgola(valstr) {
+
+ if (valstr === '' || valstr === undefined)
+ valstr = '0';
+
+ valstr = valstr + '';
+ valstr = valstr.replace(',', '.');
+
+ return parseFloat(valstr);
+ },
+
+ convertPriceEurToValue(inputString) {
+ inputString = this.removeescape(this.addslashes(inputString))
+ if (inputString === '')
+ return '0';
+ // Rimuovi il simbolo della valuta (€) e sostituisci la virgola con un punto
+ return inputString.replace(/[^\d.,]/g, '').replace(',', '.');
+ },
+
};
diff --git a/src/server/tools/shared_nodejs.js b/src/server/tools/shared_nodejs.js
index 0db9edd..bb543ce 100755
--- a/src/server/tools/shared_nodejs.js
+++ b/src/server/tools/shared_nodejs.js
@@ -246,8 +246,8 @@ module.exports = {
{ table: 'sectors', key: 'descr' },
{ table: 'skills', key: 'descr' },
{ table: 'statusSkills', key: 'descr' },
- // { table: 'catais', key: 'descr' },
- // { table: 'queryais', key: 'descr' },
+ // { table: 'catais', key: 'descr' },
+ // { table: 'queryais', key: 'descr' },
],
@@ -293,6 +293,7 @@ module.exports = {
CAT_NO_SPAZI: 5,
CAT_GOODS_TXT: 10,
PRODUCTS: 20,
+ PRODUCTS_V2: 22,
INVENTARIO: 30,
},
@@ -383,7 +384,7 @@ module.exports = {
},
{
label: 'Chili (kg)',
- short: 'Kg',
+ short: 'kg',
value: 2,
},
{
@@ -955,4 +956,62 @@ module.exports = {
NEXT_10: 1,
},
+ CAMPI_PRODUCTINFO_CONVERT: [
+ 'weight_and_unit',
+ 'weight_and_unit_lordo',
+ ],
+
+ PRODUCTINFO: {
+ CAMPI_FIRST_UPPERCASE: [
+ 'name',
+ ],
+ },
+
+ CAMPI_PRODUCTINFO: [
+ 'name',
+ 'code',
+ 'description',
+ 'link_scheda',
+ 'idCatProds',
+ 'idSubCatProds',
+ 'weight',
+ 'weight_lordo',
+ 'unit',
+ 'unit_lordo',
+ 'size',
+ 'vegan',
+ 'img',
+ 'link',
+ 'ingredienti',
+ 'valori_nutrizionali',
+ 'note',
+ ],
+
+ CAMPI_PRODUCT: [
+ 'active',
+ 'price',
+ 'stockQty',
+ 'perc_iva',
+ 'price_acquistato',
+ 'minBuyQty',
+ 'minStepQty',
+ 'cat_name',
+ 'subcat_name',
+ 'producer_name',
+ 'provider_name',
+ 'magazzino_name',
+ 'qtyToReachForGas',
+ 'maxbookableGASQty',
+ 'gas_name',
+ 'sconto1',
+ 'sconto2',
+ ],
+
+ CAMPI_EURO: [
+ 'price',
+ 'price_acquistato',
+ ],
+
+ MAX_QTA_PREORD: 5000,
+
};