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(',', '.');
},
};

View File

@@ -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,
};