import products dinamically

This commit is contained in:
Surya Paolo
2024-02-06 20:12:54 +01:00
parent 9fe81713e5
commit 64bd3cebb3
13 changed files with 577 additions and 32 deletions

View File

@@ -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, '</div>', ''), 400);
mystr = await this.firstchars(this.replaceStringAtEnd(myrec.note, '</div>', ''), 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(',', '.');
},
};