fix: ordinamento membri (namecomplete (concat: name, surname, username)

This commit is contained in:
Surya Paolo
2023-04-12 15:37:54 +02:00
parent 5bb6611384
commit f13786fca1
10 changed files with 500 additions and 86 deletions

View File

@@ -13,6 +13,8 @@ const { Graduatoria } = require('../models/graduatoria');
// const {NavePersistente} = require('../models/navepersistente');
// const { ExtraList } = require('../models/extralist');
const { MyGroup } = require('../models/mygroup');
const { Circuit } = require('../models/circuit');
@@ -464,6 +466,7 @@ const UserSchema = new mongoose.Schema({
tab: { type: Number },
},
],
version: { type: Number },
},
});
@@ -1911,9 +1914,24 @@ UserSchema.statics.removeFavorite = async function (
// Aggiungo il Favorite
UserSchema.statics.addFavorite = async function (
idapp, username, id, tab) {
return await User.updateOne({ idapp, username },
req, idapp, username, id, tab) {
const ris = await User.updateOne({ idapp, username },
{ $push: { 'profile.favorite': { id, tab } } });
const { SendNotif } = require('../models/sendnotif');
const globalTables = require('../tools/globalTables');
// Invia una Notifica al Destinatario
const recObjCreator = await globalTables.getUserCreatorByNumTabAndId(idapp, id, tab);
if (recObjCreator) {
await SendNotif.createNewNotifToSingleUser(req, null, { usernameDest: recObjCreator.username, recObjCreator, username_action: req.user.username }, false, shared_consts.TypeNotifs.TYPEDIR_FAVORITE,
shared_consts.TypeNotifs.ID_FAVORITE_ADDED);
}
return ris;
};
// Rimuovo il Bookmark
UserSchema.statics.removeBookmark = async function (
@@ -2782,7 +2800,7 @@ function getWhatToShow(idapp, username) {
'profile.handshake': 1,
'profile.favorite': 1,
'profile.bookmark': 1,
};
};
}
@@ -2807,7 +2825,7 @@ function getWhatToShow_Unknown(idapp, username) {
'profile.friends': 1,
'profile.favorite': 1,
'profile.bookmark': 1,
}
}
}
UserSchema.statics.getWhatToShow_IfFriends = async function (idapp, username) {
@@ -2835,7 +2853,7 @@ UserSchema.statics.getWhatToShow_IfFriends = async function (idapp, username) {
'profile.friends': 1,
'profile.favorite': 1,
'profile.bookmark': 1,
};
};
};
@@ -3946,6 +3964,7 @@ UserSchema.statics.calculateStat = async function (idapp, username) {
const { MyGood } = require('../models/mygood');
const { MyBacheca } = require('../models/mybacheca');
const { MyGroup } = require('../models/mygroup');
const globalTables = require('../tools/globalTables');
const numUsersReg = await User.countDocuments(
{
@@ -3957,8 +3976,6 @@ UserSchema.statics.calculateStat = async function (idapp, username) {
let numByTab = {};
const globalTables = require('../tools/globalTables');
for (let table of shared_consts.TABLES_VISU_STAT_IN_HOME) {
let mytable = globalTables.getTableByTableName(table);
if (mytable) {
@@ -4675,7 +4692,7 @@ UserSchema.statics.getExtraInfoByUsername = async function (idapp, username) {
return myuser.profile;
};
UserSchema.statics.addExtraInfo = async function (idapp, recUser, recUserSave) {
UserSchema.statics.addExtraInfo = async function (idapp, recUser, recUserSave, version) {
try {
@@ -4764,6 +4781,22 @@ UserSchema.statics.addExtraInfo = async function (idapp, recUser, recUserSave) {
recUser.profile.calc = await User.calcOtherByUser(idapp, recUser._id);
if (version) {
let versattualeuser = 0;
if (!recUser.profile.version) {
recUser.version = 0;
versattualeuser = 0;
} else {
versattualeuser = recUser.profile.version;
}
if (versattualeuser < version) {
// Aggiornamento versione
recUser = await User.updateVersion(versattualeuser, recUser);
await User.findOneAndUpdate({_id: recUser._id}, {$set: { 'profile.version' : version }});
}
}
return recUser;
@@ -4774,6 +4807,17 @@ UserSchema.statics.addExtraInfo = async function (idapp, recUser, recUserSave) {
return recUser;
};
UserSchema.statics.updateVersion = async function (userversion, recUser) {
if (userversion < 063) {
recUser.profile.notifs.push( { dir: 11, value: 1 })
await User.findOneAndUpdate({_id: recUser._id}, {$set: { 'profile.notifs': recUser.profile.notifs }});
}
return recUser;
};
UserSchema.statics.calcOtherByUser = async function (idapp, userId) {
const { MySkill } = require('../models/myskill');