import products dinamically
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
DATABASE=test_FreePlanet
|
DATABASE=test_PiuCheBuono
|
||||||
UDB=paofreeplanet
|
UDB=paofreeplanet
|
||||||
PDB=mypassword@1A
|
PDB=mypassword@1A
|
||||||
SEND_EMAIL=0
|
SEND_EMAIL=0
|
||||||
|
|||||||
@@ -8,7 +8,9 @@
|
|||||||
"NEW_HOSP": "❇️ <strong>%s</strong> ha aggiunto una nuova Ospitalità: \n<strong>%s</strong>",
|
"NEW_HOSP": "❇️ <strong>%s</strong> ha aggiunto una nuova Ospitalità: \n<strong>%s</strong>",
|
||||||
"NEW_EVENT": "❇️ <strong>%s</strong> ha aggiunto un nuovo Evento: \n%s\n<strong>%s</strong>\n%s",
|
"NEW_EVENT": "❇️ <strong>%s</strong> ha aggiunto un nuovo Evento: \n%s\n<strong>%s</strong>\n%s",
|
||||||
"NEW_EVENT_TELEGRAM": "%s\n\n❇️ <strong>%s</strong>\n\n%s\n\n%s",
|
"NEW_EVENT_TELEGRAM": "%s\n\n❇️ <strong>%s</strong>\n\n%s\n\n%s",
|
||||||
"ADDED_FROM": "\n\n<i>(Evento aggiunto da <strong>%s</strong>)</i>",
|
"NEW_ANNUNCIO_TELEGRAM": "❇️ <strong>%s</strong>\n\n%s\n\n%s",
|
||||||
|
"EVENT_ADDED_FROM": "\n\n<i>(Evento aggiunto da <strong>%s</strong>)</i>",
|
||||||
|
"ADDED_FROM": "\n\n<i>(Aggiunto da <strong>%s</strong>)</i>",
|
||||||
"CONTRIB": "\n💠 Contributo richiesto: %s",
|
"CONTRIB": "\n💠 Contributo richiesto: %s",
|
||||||
"ORGANIZED_BY": "\n<i>Organizzato da <strong>%s</strong></i>",
|
"ORGANIZED_BY": "\n<i>Organizzato da <strong>%s</strong></i>",
|
||||||
"SHOW_POST": "👉🏻 vedi post su RISO",
|
"SHOW_POST": "👉🏻 vedi post su RISO",
|
||||||
|
|||||||
@@ -593,6 +593,7 @@ CircuitSchema.statics.getUsersSingleCircuit = async function (idapp, username, c
|
|||||||
{
|
{
|
||||||
$project: {
|
$project: {
|
||||||
username: 1,
|
username: 1,
|
||||||
|
verified_by_aportador: 1,
|
||||||
name: 1,
|
name: 1,
|
||||||
surname: 1,
|
surname: 1,
|
||||||
profile: 1,
|
profile: 1,
|
||||||
|
|||||||
@@ -366,16 +366,20 @@ MovementSchema.statics.getQueryMovsByCircuitId = async function (idapp, username
|
|||||||
notifId: 1,
|
notifId: 1,
|
||||||
'circuitfrom.symbol': 1,
|
'circuitfrom.symbol': 1,
|
||||||
'circuitto.symbol': 1,
|
'circuitto.symbol': 1,
|
||||||
|
'userfrom.verified_by_aportador': 1,
|
||||||
'userfrom.username': 1,
|
'userfrom.username': 1,
|
||||||
'userfrom.profile.img': 1,
|
'userfrom.profile.img': 1,
|
||||||
'userto.username': 1,
|
'userto.username': 1,
|
||||||
'userto.profile.img': 1,
|
'userto.profile.img': 1,
|
||||||
|
'userto.verified_by_aportador': 1,
|
||||||
'groupfrom.groupname': 1,
|
'groupfrom.groupname': 1,
|
||||||
|
'groupfrom.verified_by_aportador': 1,
|
||||||
'groupfrom.title': 1,
|
'groupfrom.title': 1,
|
||||||
'groupfrom.photos': 1,
|
'groupfrom.photos': 1,
|
||||||
'groupto.groupname': 1,
|
'groupto.groupname': 1,
|
||||||
'groupto.title': 1,
|
'groupto.title': 1,
|
||||||
'groupto.photos': 1,
|
'groupto.photos': 1,
|
||||||
|
'groupto.verified_by_aportador': 1,
|
||||||
'contocomfrom.path': 1,
|
'contocomfrom.path': 1,
|
||||||
'contocomfrom.name': 1,
|
'contocomfrom.name': 1,
|
||||||
'contocomto.path': 1,
|
'contocomto.path': 1,
|
||||||
|
|||||||
@@ -42,24 +42,34 @@ const productInfoSchema = new Schema({
|
|||||||
type: String
|
type: String
|
||||||
},
|
},
|
||||||
size: {
|
size: {
|
||||||
type: String
|
type: String // 11x4x3
|
||||||
},
|
},
|
||||||
weight: {
|
weight: {
|
||||||
type: Number
|
type: Number
|
||||||
},
|
},
|
||||||
vegan: {
|
weight_lordo: {
|
||||||
type: Boolean
|
type: Number
|
||||||
},
|
},
|
||||||
unit: {
|
unit: {
|
||||||
type: Number,
|
type: Number,
|
||||||
default: 0,
|
default: 0,
|
||||||
},
|
},
|
||||||
|
unit_lordo: {
|
||||||
|
type: Number,
|
||||||
|
default: 0,
|
||||||
|
},
|
||||||
|
vegan: {
|
||||||
|
type: Boolean
|
||||||
|
},
|
||||||
icon: {
|
icon: {
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
img: {
|
img: {
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
|
link_scheda: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
link: {
|
link: {
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -20,6 +20,10 @@ const searchSchema = new Schema({
|
|||||||
userId: {
|
userId: {
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
|
date_created: {
|
||||||
|
type: Date,
|
||||||
|
default: Date.now,
|
||||||
|
},
|
||||||
text: {
|
text: {
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -217,7 +217,10 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function (recnotif, us
|
|||||||
recnotif.openUrl = shared_consts.getDirectoryByTable(shared_consts.TABLES_MYHOSPS, true) + myidrec;
|
recnotif.openUrl = shared_consts.getDirectoryByTable(shared_consts.TABLES_MYHOSPS, true) + myidrec;
|
||||||
tag = 'newhosp';
|
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) {
|
} else if (recnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_EVENTS) {
|
||||||
recnotif.openUrl = shared_consts.getDirectoryByTable(shared_consts.TABLES_MYBACHECAS, true) + myidrec;
|
recnotif.openUrl = shared_consts.getDirectoryByTable(shared_consts.TABLES_MYBACHECAS, true) + myidrec;
|
||||||
tag = 'newevent';
|
tag = 'newevent';
|
||||||
|
|||||||
@@ -4191,6 +4191,7 @@ UserSchema.statics.getLastOnlineUsers = async function (idapp) {
|
|||||||
surname: 1,
|
surname: 1,
|
||||||
lasttimeonline: 1,
|
lasttimeonline: 1,
|
||||||
date_reg: 1,
|
date_reg: 1,
|
||||||
|
verified_by_aportador: 1,
|
||||||
'profile.img': 1,
|
'profile.img': 1,
|
||||||
index: 1,
|
index: 1,
|
||||||
}).sort({ lasttimeonline: -1 }).limit(lastn).then((arr) => {
|
}).sort({ lasttimeonline: -1 }).limit(lastn).then((arr) => {
|
||||||
@@ -4217,6 +4218,7 @@ UserSchema.statics.getLastSharedLink = async function (idapp) {
|
|||||||
name: 1,
|
name: 1,
|
||||||
surname: 1,
|
surname: 1,
|
||||||
lasttimeonline: 1,
|
lasttimeonline: 1,
|
||||||
|
verified_by_aportador: 1,
|
||||||
date_reg: 1,
|
date_reg: 1,
|
||||||
'profile.img': 1,
|
'profile.img': 1,
|
||||||
index: 1,
|
index: 1,
|
||||||
@@ -4370,6 +4372,47 @@ UserSchema.statics.getUsersRegDaily = function (idapp, nrec) {
|
|||||||
return query;
|
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) {
|
UserSchema.statics.getQueryUsersDiffusori = function (idapp) {
|
||||||
|
|
||||||
const query = [
|
const query = [
|
||||||
@@ -4461,6 +4504,7 @@ UserSchema.statics.getQueryUsersDiffusori = function (idapp) {
|
|||||||
idapp: 1,
|
idapp: 1,
|
||||||
"profile.img": 1,
|
"profile.img": 1,
|
||||||
'profile.mycircuits': 1,
|
'profile.mycircuits': 1,
|
||||||
|
'profile.handshake': 1,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
@@ -4668,6 +4712,19 @@ UserSchema.statics.getUsersRegWeekly = function (idapp, nrec) {
|
|||||||
count: { $sum: 1 },
|
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 },
|
$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) {
|
UserSchema.statics.calcRegDaily = async function (idapp) {
|
||||||
const User = this;
|
const User = this;
|
||||||
|
|
||||||
@@ -4724,12 +4811,14 @@ UserSchema.statics.calcRegDaily = async function (idapp) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
UserSchema.statics.calcRegWeekly = async function (idapp) {
|
UserSchema.statics.calcRegWeekly = async function (idapp) {
|
||||||
const User = this;
|
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);
|
// console.table(ris);
|
||||||
return ris.slice(0, -1);
|
return calculate30DayAverage(ris);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -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) => {
|
router.post('/import', authenticate, async (req, res) => {
|
||||||
const cmd = req.body.cmd;
|
const cmd = req.body.cmd;
|
||||||
const idapp = req.body.idapp;
|
const idapp = req.body.idapp;
|
||||||
@@ -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
|
// L'opzione ordered: false gestisce gli errori senza interrompere l'inserimento
|
||||||
/*return await Product.insertMany(dataObjects, { ordered: false })
|
/*return await Product.insertMany(dataObjects, { ordered: false })
|
||||||
|
|||||||
@@ -1245,6 +1245,8 @@ async function eseguiDbOp(idapp, mydata, locale, req, res) {
|
|||||||
|
|
||||||
} else if (mydata.dbop === 'updateReactionsCounts') {
|
} else if (mydata.dbop === 'updateReactionsCounts') {
|
||||||
await Reaction.updateReactionsCounts();
|
await Reaction.updateReactionsCounts();
|
||||||
|
} else if (mydata.dbop === 'removeRegulations') {
|
||||||
|
await Circuit.updateMany({}, { $set: { regulation: '' } });
|
||||||
|
|
||||||
} else if (mydata.dbop === 'newRecordsFav') {
|
} else if (mydata.dbop === 'newRecordsFav') {
|
||||||
// Passa le tabelle da users sulle nuove tabelle:
|
// Passa le tabelle da users sulle nuove tabelle:
|
||||||
|
|||||||
@@ -711,15 +711,18 @@ const MyTelegramBot = {
|
|||||||
} else {
|
} else {
|
||||||
arrTeleg = appTelegram;
|
arrTeleg = appTelegram;
|
||||||
}
|
}
|
||||||
if (process.env.NODE_ENV === 'development')
|
if (process.env.NODE_ENV === 'development') {
|
||||||
arrTeleg = appTelegram_DEVELOP;
|
arrTeleg = appTelegram_DEVELOP;
|
||||||
else if (process.env.NODE_ENV === 'test')
|
} else if (process.env.NODE_ENV === 'test') {
|
||||||
arrTeleg = MyTelegramBot.getAppTelegramTest();
|
arrTeleg = MyTelegramBot.getAppTelegramTest();
|
||||||
|
} else {
|
||||||
const arrTelegFromSite = tools.getArrTelegramFromSite();
|
const arrTelegFromSite = tools.getArrTelegramFromSite();
|
||||||
if (arrTelegFromSite.length > 0) {
|
if (arrTelegFromSite.length > 0) {
|
||||||
arrTeleg = arrTelegFromSite;
|
arrTeleg = arrTelegFromSite;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return arrTeleg;
|
return arrTeleg;
|
||||||
|
|
||||||
},
|
},
|
||||||
@@ -4100,7 +4103,7 @@ if (true) {
|
|||||||
|
|
||||||
internetAvailable().then(() => {
|
internetAvailable().then(() => {
|
||||||
// ..
|
// ..
|
||||||
console.log('TELEGRAM STARTING.... ' + process.env.NODE_ENV);
|
console.log('TELEGRAM STARTING.... ', process.env.NODE_ENV);
|
||||||
|
|
||||||
for (const idapp of arrTeleg) {
|
for (const idapp of arrTeleg) {
|
||||||
|
|
||||||
|
|||||||
@@ -1841,11 +1841,11 @@ module.exports = {
|
|||||||
for (const site of myapp) {
|
for (const site of myapp) {
|
||||||
if (site.active) {
|
if (site.active) {
|
||||||
if (process.env.NODE_ENV === 'test') {
|
if (process.env.NODE_ENV === 'test') {
|
||||||
if (myapp.load_process_telegram_test)
|
if (site.telegram_bot_name_test)
|
||||||
arrteleg.push(myapp.idapp)
|
arrteleg.push(site.idapp)
|
||||||
} else {
|
} else {
|
||||||
if (myapp.load_process_telegram)
|
if (site.telegram_bot_name)
|
||||||
arrteleg.push(myapp.idapp)
|
arrteleg.push(site.idapp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4305,7 +4305,7 @@ module.exports = {
|
|||||||
async getDescrEstesaStrByEvent(myrec) {
|
async getDescrEstesaStrByEvent(myrec) {
|
||||||
let mystr = '';
|
let mystr = '';
|
||||||
|
|
||||||
mystr = await this.firstchars(this.replaceStringAtEnd(myrec.note, '</div>', ''), 400);
|
mystr = await this.firstchars(this.replaceStringAtEnd(myrec.note, '</div>', ''), 800);
|
||||||
if (mystr)
|
if (mystr)
|
||||||
mystr = 'ℹ️ ' + mystr
|
mystr = 'ℹ️ ' + mystr
|
||||||
return mystr;
|
return mystr;
|
||||||
@@ -4328,6 +4328,32 @@ module.exports = {
|
|||||||
if (contributo) {
|
if (contributo) {
|
||||||
newdescrtelegram += i18n.__('CONTRIB', 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);
|
newdescrtelegram += i18n.__('ADDED_FROM', userorig);
|
||||||
|
|
||||||
return { newdescr, newdescrtelegram }
|
return { newdescr, newdescrtelegram }
|
||||||
@@ -4336,6 +4362,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
generateVapiKey() {
|
generateVapiKey() {
|
||||||
const webpush = require('web-push');
|
const webpush = require('web-push');
|
||||||
|
|
||||||
@@ -4384,6 +4411,27 @@ module.exports = {
|
|||||||
return unitrec ? unitrec.value : 0
|
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) {
|
async isManagerByReq(req) {
|
||||||
try {
|
try {
|
||||||
var { User } = require('../models/user');
|
var { User } = require('../models/user');
|
||||||
@@ -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(',', '.');
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -293,6 +293,7 @@ module.exports = {
|
|||||||
CAT_NO_SPAZI: 5,
|
CAT_NO_SPAZI: 5,
|
||||||
CAT_GOODS_TXT: 10,
|
CAT_GOODS_TXT: 10,
|
||||||
PRODUCTS: 20,
|
PRODUCTS: 20,
|
||||||
|
PRODUCTS_V2: 22,
|
||||||
INVENTARIO: 30,
|
INVENTARIO: 30,
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -383,7 +384,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Chili (kg)',
|
label: 'Chili (kg)',
|
||||||
short: 'Kg',
|
short: 'kg',
|
||||||
value: 2,
|
value: 2,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -955,4 +956,62 @@ module.exports = {
|
|||||||
NEXT_10: 1,
|
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,
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user