- sistemato anche il users/profile ed aggiunto /users/activities
This commit is contained in:
@@ -1727,8 +1727,8 @@ UserSchema.statics.getUserProfileByUsername = async function (
|
||||
'profile.username_telegram': 1,
|
||||
'profile.firstname_telegram': 1,
|
||||
'profile.lastname_telegram': 1,
|
||||
'profile.intcode_cell': 1,
|
||||
'profile.cell': 1,
|
||||
// 'profile.intcode_cell': 1,
|
||||
// 'profile.cell': 1,
|
||||
'profile.website': 1,
|
||||
'profile.img': 1,
|
||||
'profile.sex': 1,
|
||||
@@ -2061,7 +2061,7 @@ UserSchema.statics.addCircuitToUser = async function (idapp, usernameOrig, circu
|
||||
} else {
|
||||
|
||||
// prima di aggiungerlo controlla se esiste già !
|
||||
|
||||
|
||||
let update = {
|
||||
$addToSet: { // Utilizziamo $addToSet invece di $push per garantire che l'elemento venga aggiunto solo se non esiste già
|
||||
'profile.mycircuits': {
|
||||
@@ -2072,7 +2072,7 @@ UserSchema.statics.addCircuitToUser = async function (idapp, usernameOrig, circu
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
ris = await User.updateOne({ idapp, username: usernameOrig, 'profile.mycircuits': { $not: { $elemMatch: { circuitname } } } }, update);
|
||||
|
||||
if (confido) {
|
||||
@@ -4870,27 +4870,27 @@ 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;
|
||||
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));
|
||||
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;
|
||||
}
|
||||
if (diffInDays <= 30) {
|
||||
sum += data[j].count;
|
||||
count++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
averages.push({
|
||||
_id: data[i]._id,
|
||||
dailyAverage: sum / count
|
||||
});
|
||||
averages.push({
|
||||
_id: data[i]._id,
|
||||
dailyAverage: sum / count
|
||||
});
|
||||
}
|
||||
|
||||
return averages;
|
||||
@@ -5202,6 +5202,24 @@ UserSchema.statics.getExtraInfoByUsername = async function (idapp, username) {
|
||||
return null;
|
||||
|
||||
};
|
||||
UserSchema.statics.getProfilePerActivitiesByUsername = async function (idapp, username) {
|
||||
const User = this;
|
||||
|
||||
try {
|
||||
let myuser = await User.findOne({ idapp, username }).lean();
|
||||
if (myuser) {
|
||||
return {
|
||||
mygroups: myuser.profile.mygroups,
|
||||
mycircuits: myuser.profile.mycircuits };
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('e', e);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
};
|
||||
|
||||
UserSchema.statics.addExtraInfo = async function (idapp, recUser, recUserSave, version) {
|
||||
|
||||
try {
|
||||
@@ -5566,7 +5584,7 @@ UserSchema.statics.addNewSite = async function (idappPass, body) {
|
||||
// cerca un IdApp Libero
|
||||
let idapp = await Site.generateNewSite_IdApp(idappPass, body, true);
|
||||
|
||||
|
||||
|
||||
if (idapp) {
|
||||
let arrSite = await Site.find({ idapp }).lean();
|
||||
let numutenti = 0;
|
||||
@@ -5576,7 +5594,7 @@ UserSchema.statics.addNewSite = async function (idappPass, body) {
|
||||
|
||||
if (arrSite && arrSite.length === 1 && numutenti < 2) {
|
||||
const MyTelegramBot = require('../telegram/telegrambot');
|
||||
|
||||
|
||||
// Nessun Sito Installato e Nessun Utente installato !
|
||||
let myuser = new User();
|
||||
myuser._id = new ObjectID();
|
||||
|
||||
Reference in New Issue
Block a user