Lista Amici

Richieste di Fiducia
Accettati
Rifiutati
This commit is contained in:
paoloar77
2022-01-07 01:18:01 +01:00
parent 181af3c895
commit 3b6218d2ba
11 changed files with 1254 additions and 663 deletions

View File

@@ -35,12 +35,18 @@ const SiteSchema = new Schema({
host: {
type: String,
},
host_test: {
type: String,
},
portapp: {
type: String,
},
dir: {
type: String,
},
dir_test: {
type: String,
},
email_from: {
type: String,
},
@@ -53,9 +59,18 @@ const SiteSchema = new Schema({
telegram_bot_name: {
type: String,
},
telegram_key_test: {
type: String,
},
telegram_bot_name_test: {
type: String,
},
pathreg_add: {
type: String,
},
ask_to_verify_reg: {
type: Boolean,
},
who: {
type: String
},

View File

@@ -137,7 +137,6 @@ const UserSchema = new mongoose.Schema({
},
verified_by_aportador: {
type: Boolean,
default: false,
},
aportador_iniziale: {
type: String,
@@ -158,6 +157,15 @@ const UserSchema = new mongoose.Schema({
sospeso: {
type: Boolean,
},
blocked: {
type: Boolean,
},
username_who_block: {
type: String,
},
date_blocked: {
type: Date,
},
non_voglio_imbarcarmi: {
type: Boolean,
},
@@ -303,6 +311,7 @@ const UserSchema = new mongoose.Schema({
description: {type: String},
rating: {type: Number},
}],
friends: [], // username
},
})
@@ -1193,6 +1202,109 @@ UserSchema.statics.getUserProfileByUsername = async function(idapp, username) {
};
UserSchema.statics.getUsernameFriendsByUsername = async function(
idapp, username) {
return User.findOne({
idapp, 'username': username,
$or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}],
}, {'profile.friends': 1}).then((rec) => rec ? rec._doc.profile.friends : []);
};
UserSchema.statics.setFriendsCmd = async function(idapp, usernameOrig, usernameDest, cmd, value) {
let ris = null;
let update = { };
if (cmd === shared_consts.FRIENDSCMD.SETTRUST) {
return User.updateOne({idapp, username: usernameDest},
{ $set: { verified_by_aportador: value } }, { new: false } );
} else if (cmd === shared_consts.FRIENDSCMD.SETFRIEND) {
// Aggiungo l'Amicizia a me
const foundIfAlreadyFriend = await User.findOne({
idapp,
members: {
$elemMatch: { 'profile.friends': usernameOrig }
}
});
update = { $push: { 'profile.friends': [usernameOrig] } };
if (!foundIfAlreadyFriend) {
ris = await User.updateOne({idapp, username: usernameOrig}, update);
}
// Controlla se lui aveva già la mia amicizia
const foundIfAlreadyFriend2 = await User.findOne({
members: {
$elemMatch: { 'profile.friends': usernameOrig }
}
});
update = { $push: { 'profile.friends': [usernameOrig] } };
if (!foundIfAlreadyFriend) {
ris = await User.updateOne({idapp, username: usernameOrig}, update);
}
} else if (cmd === shared_consts.FRIENDSCMD.REMOVE_FROM_MYFRIENDS) {
// Rimuovo l'Amicizia da lui
await User.updateOne({idapp, username: usernameDest}, { $pullAll: { 'profile.friends': [usernameOrig] } });
// Rimuovo l'Amicizia da me
ris = await User.updateOne({idapp, username: usernameOrig}, { $pullAll: { 'profile.friends': [usernameDest] } });
} else if (cmd === shared_consts.FRIENDSCMD.BLOCK_USER) {
// Rimuovo l'Amicizia da lui
await User.updateOne({idapp, username: usernameDest}, { $pullAll: { 'profile.friends': [usernameOrig] } });
// Rimuovo l'Amicizia da me
await User.updateOne({idapp, username: usernameOrig}, { $pullAll: { 'profile.friends': [usernameDest] } });
// Blocco la persona
ris = await User.updateOne({idapp, username: usernameDest}, { $set: { blocked: true, sospeso: true, username_who_block: usernameOrig, date_blocked: new Date() } });
}
return ris;
};
UserSchema.statics.getFriendsByUsername = async function(idapp, username) {
const whatToShow = {
username: 1,
aportador_solidario: 1,
name: 1,
surname: 1,
deleted: 1,
sospeso: 1,
verified_email: 1,
verified_by_aportador: 1,
'profile.nationality': 1,
'profile.biografia': 1,
'profile.username_telegram': 1,
'profile.img': 1,
'profile.sex': 1,
'profile.dateofbirth': 1,
'profile.born_city': 1,
'profile.born_province': 1,
'profile.born_country': 1,
email: 1,
date_reg: 1,
};
const arrUsernameFriends = await User.getUsernameFriendsByUsername(idapp, username);
const listFriends = await User.find({
idapp,
username: {$in: arrUsernameFriends},
$or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}],
}, whatToShow);
const listTrusted = await User.find({
idapp, aportador_solidario: username,
$or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}],
}, whatToShow);
return ({listFriends, listTrusted});
};
UserSchema.statics.getAportadorSolidarioByUsername = async function(
idapp, username) {
const User = this;