- fix: se inserisco un username telegram di chi mi ha invitato, non facevo il controllo.
This commit is contained in:
@@ -876,6 +876,57 @@ UserSchema.statics.findByUsername = async function (idapp, username, alsoemail,
|
||||
return rec;
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Find a user by their Telegram username.
|
||||
*
|
||||
* @param {string} idapp - The application ID
|
||||
* @param {string} username - The Telegram username
|
||||
* @param {boolean} alsoemail - Flag to indicate if email should also be considered
|
||||
* @param {boolean} onlyifVerifiedByAportador - Flag to indicate if only verified users should be returned
|
||||
* @return {Promise} A Promise that resolves to the found user or null
|
||||
**/
|
||||
|
||||
UserSchema.statics.findByUsernameTelegram = async function (idapp, username, alsoemail, onlyifVerifiedByAportador) {
|
||||
const User = this;
|
||||
|
||||
if (username && username[0] === '@') {
|
||||
username = username.substring(1);
|
||||
}
|
||||
|
||||
const myreg = ['^', username, '$'].join('');
|
||||
let regexusername = new RegExp(myreg, 'i');
|
||||
|
||||
//++TODO: Set only the necessary fields to get in memory
|
||||
|
||||
return await User.findOne({
|
||||
idapp: idapp,
|
||||
'profile.username_telegram': { $regex: regexusername },
|
||||
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
|
||||
}).then(async (ris) => {
|
||||
if ((!ris) && (alsoemail)) {
|
||||
regexemail = new RegExp(['^', username.toLowerCase(), '$'].join(''), 'i');
|
||||
|
||||
return await User.findOne({
|
||||
'idapp': idapp,
|
||||
'email': { $regex: regexemail },
|
||||
$or: [
|
||||
{ deleted: { $exists: false } },
|
||||
{ deleted: { $exists: true, $eq: false } }],
|
||||
});
|
||||
}
|
||||
return ris;
|
||||
}).then((rec) => {
|
||||
if (rec && onlyifVerifiedByAportador) {
|
||||
if (tools.getAskToVerifyReg(idapp)) {
|
||||
if (!rec.verified_by_aportador)
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return rec;
|
||||
});
|
||||
};
|
||||
|
||||
UserSchema.statics.getProjectUser = function () {
|
||||
return {
|
||||
@@ -1728,6 +1779,20 @@ UserSchema.statics.getUserByUsername = function (idapp, username) {
|
||||
});
|
||||
};
|
||||
|
||||
UserSchema.statics.getUserByUsernameTelegram = function (idapp, username_telegram) {
|
||||
const User = this;
|
||||
|
||||
if (username_telegram[0] === '@'){
|
||||
username_telegram = username_telegram.substring(1);
|
||||
}
|
||||
|
||||
return User.findOne({
|
||||
idapp,
|
||||
'profile.username_telegram': username_telegram,
|
||||
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
|
||||
});
|
||||
};
|
||||
|
||||
UserSchema.statics.isMyFriend = async function (idapp, username, myusername) {
|
||||
|
||||
const myfriends = await User.getUsernameFriendsByUsername(idapp, myusername);
|
||||
|
||||
Reference in New Issue
Block a user