- Aggiungere numero di persone registrate, e num di competenze, e numGruppi

This commit is contained in:
paoloar77
2022-02-11 01:08:03 +01:00
parent e1eaf10e9b
commit 077d9933c3
6 changed files with 69 additions and 80 deletions

View File

@@ -1158,10 +1158,10 @@ UserSchema.statics.isMyFriend = async function(idapp, username, myusername) {
return false;
}
};
UserSchema.statics.getUserProfileByUsername = async function(idapp, username, myusername, usaSuperPower, myperm = '') {
UserSchema.statics.getUserProfileByUsername = async function(
idapp, username, myusername, usaSuperPower, myperm = '') {
const User = this;
// If is my Friend, then can show all
@@ -1285,11 +1285,11 @@ UserSchema.statics.getArrUsernameFromFieldByUsername = async function(
UserSchema.statics.getUsernameReqFriendsByUsername = async function(
idapp, username) {
return this.getArrUsernameFromFieldByUsername(idapp, username, 'profile', 'req_friends');
return this.getArrUsernameFromFieldByUsername(idapp, username, 'profile',
'req_friends');
};
UserSchema.statics.getUsernameFriendsByUsername = async function(
idapp, username) {
@@ -1301,24 +1301,28 @@ UserSchema.statics.getUsernameFriendsByUsername = async function(
UserSchema.statics.getUsernameGroupsByUsername = async function(
idapp, username) {
return this.getArrUsernameFromFieldByUsername(idapp, username, 'profile', 'groups');
return this.getArrUsernameFromFieldByUsername(idapp, username, 'profile',
'groups');
};
// Rimuovo l'Amicizia
UserSchema.statics.removeFriend = async function(idapp, username, usernameDest) {
UserSchema.statics.removeFriend = async function(
idapp, username, usernameDest) {
return User.updateOne({idapp, username},
{$pull: {'profile.friends': {username: {$in: [usernameDest]}}}});
};
// Rimuovo il Gruppo
UserSchema.statics.removeFromMyGroups = async function(idapp, username, groupnameDest) {
UserSchema.statics.removeFromMyGroups = async function(
idapp, username, groupnameDest) {
return User.updateOne({idapp, username},
{$pull: {'profile.mygroups': {groupname: {$in: [groupnameDest]}}}});
};
// Rimuovo la Richiesta di Amicizia
UserSchema.statics.removeReqFriend = async function(idapp, username, usernameDest) {
UserSchema.statics.removeReqFriend = async function(
idapp, username, usernameDest) {
return User.updateOne({idapp, username: username},
{$pull: {'profile.req_friends': {username: {$in: [usernameDest]}}}});
};
@@ -1395,7 +1399,7 @@ UserSchema.statics.setFriendsCmd = async function(
idapp,
username: usernameDest,
'profile.req_friends': {
$elemMatch: { username: {$eq: usernameOrig}},
$elemMatch: {username: {$eq: usernameOrig}},
},
});
@@ -1457,7 +1461,8 @@ UserSchema.statics.setFriendsCmd = async function(
return ris;
};
UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameDest, cmd, value) {
UserSchema.statics.setGroupsCmd = async function(
idapp, usernameOrig, groupnameDest, cmd, value) {
let ris = null;
let update = {};
@@ -1485,7 +1490,8 @@ UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameD
// Elimina la richiesta:
update = {$pull: {req_users: {username: {$in: [usernameOrig]}}}};
ris = await MyGroup.updateOne({idapp, groupname: groupnameDest}, update);
ris = await MyGroup.updateOne({idapp, groupname: groupnameDest},
update);
} else {
ris = false;
}
@@ -1499,7 +1505,7 @@ UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameD
idapp,
groupname: groupnameDest,
'req_users': {
$elemMatch: { username: {$eq: usernameOrig}},
$elemMatch: {username: {$eq: usernameOrig}},
},
});
@@ -1513,7 +1519,8 @@ UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameD
},
},
};
ris = await MyGroup.updateOne({idapp, groupname: groupnameDest}, update);
ris = await MyGroup.updateOne({idapp, groupname: groupnameDest},
update);
}
if (ris) {
// Invia una notifica alla persona
@@ -1521,11 +1528,11 @@ UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameD
}
} else {
if (foundIfAlreadyAskGroup) {
ris = await this.removeFromMyGroups(idapp, usernameOrig, groupnameDest); // Rimuovo il Gruppo da me
ris = await this.removeFromMyGroups(idapp, usernameOrig,
groupnameDest); // Rimuovo il Gruppo da me
}
}
if (ris) {
ris = await MyGroup.getInfoGroupByGroupname(idapp, groupnameDest);
}
@@ -1835,7 +1842,8 @@ UserSchema.statics.SetTelegramIdSuccess = async function(idapp, id, teleg_id) {
};
UserSchema.statics.setUsernameTelegram = async function(idapp, id, username_telegram, firstname_telegram, lastname_telegram) {
UserSchema.statics.setUsernameTelegram = async function(
idapp, id, username_telegram, firstname_telegram, lastname_telegram) {
const User = this;
const fields_to_update = {
@@ -1896,7 +1904,8 @@ UserSchema.statics.SetTelegramWasBlocked = async function(idapp, teleg_id) {
};
UserSchema.statics.getNameSurnameByUsername = async function(idapp, username, reale = false) {
UserSchema.statics.getNameSurnameByUsername = async function(
idapp, username, reale = false) {
const User = this;
return User.findOne({
@@ -1907,12 +1916,12 @@ UserSchema.statics.getNameSurnameByUsername = async function(idapp, username, re
if (!!rec) {
if (reale) {
if (!rec.name)
return ''
return '';
ris = `${rec.name} ${rec.surname}`
ris = `${rec.name} ${rec.surname}`;
} else {
if (rec.name) {
ris = `${rec.name} ${rec.surname}`
ris = `${rec.name} ${rec.surname}`;
}
}
}
@@ -2401,7 +2410,6 @@ UserSchema.statics.getUsersQualified = async function (idapp, numinvitati) {
};
*/
// UserSchema.statics.getNumUsersQualified = async function (idapp, numinvitati) {
//
// arrrec = await this.getUsersQualified(idapp, numinvitati);
@@ -2549,14 +2557,17 @@ UserSchema.statics.checkUser = async function(idapp, username) {
UserSchema.statics.calculateStat = async function(idapp, username) {
const User = this;
/*
return calcstat = {
numinvitati: await ListaIngresso.getnumInvitati(idapp, username),
numinvitati_attivi: await ListaIngresso.getnumInvitatiAttivi(idapp,
username),
};
const {MySkill} = require('../models/myskill');
const {MyGroup} = require('../models/mygroup');
*/
const numUsersReg = await User.count({
idapp,
$or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}],
});
const numMySkills = await MySkill.count({idapp});
const numGroups = await MyGroup.count({idapp});
return {numMySkills, numUsersReg, numGroups};
};
@@ -2717,7 +2728,6 @@ if (tools.INITDB_FIRSTIME) {
// UserSchema.index({ surname: 1 });
}
UserSchema.statics.getUsernameByIndOrder = async function(idapp, ind_order) {
const myrec = await User.getSmallRecByIndOrder(idapp, ind_order);
@@ -2996,7 +3006,9 @@ UserSchema.statics.addExtraInfo = async function(idapp, recUser) {
{deleted: {$exists: true, $eq: false}}],
}, {username: 1});
recUser._doc.profile.asked_friends = listSentMyRequestFriends ? listSentMyRequestFriends : [];
recUser._doc.profile.asked_friends = listSentMyRequestFriends
? listSentMyRequestFriends
: [];
const listSentMyRequestGroups = await MyGroup.find({
idapp,
@@ -3008,7 +3020,9 @@ UserSchema.statics.addExtraInfo = async function(idapp, recUser) {
{deleted: {$exists: true, $eq: false}}],
}, MyGroup.getWhatToShow_Unknown());
recUser._doc.profile.asked_groups = listSentMyRequestGroups ? listSentMyRequestGroups : [];
recUser._doc.profile.asked_groups = listSentMyRequestGroups
? listSentMyRequestGroups
: [];
const listManageGroups = await MyGroup.find({
idapp,
@@ -3020,11 +3034,11 @@ UserSchema.statics.addExtraInfo = async function(idapp, recUser) {
{deleted: {$exists: true, $eq: false}}],
});
recUser._doc.profile.manage_mygroups = listManageGroups ? listManageGroups : [];
recUser._doc.profile.manage_mygroups = listManageGroups
? listManageGroups
: [];
}catch (e){
} catch (e) {
console.error('Err', e);
}