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

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

View File

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

View File

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

View File

@@ -20,6 +20,10 @@ const searchSchema = new Schema({
userId: {
type: String,
},
date_created: {
type: Date,
default: Date.now,
},
text: {
type: String,
},

View File

@@ -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';

View File

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