Add in RISO registration a username_telegram for your invited
This commit is contained in:
@@ -693,16 +693,8 @@ UserSchema.statics.findByUsername = async function(idapp, username, alsoemail, o
|
||||
});
|
||||
};
|
||||
|
||||
UserSchema.statics.getUserShortDataByUsername = async function(idapp, username) {
|
||||
const User = this;
|
||||
|
||||
let regexp = new RegExp(`^${username}$`, 'i');
|
||||
|
||||
const myrec = await User.findOne({
|
||||
'idapp': idapp,
|
||||
username: {$regex: regexp},
|
||||
$or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}],
|
||||
}, {
|
||||
UserSchema.statics.getProjectUser = function() {
|
||||
return {
|
||||
idapp: 1,
|
||||
lang: 1,
|
||||
index: 1,
|
||||
@@ -740,15 +732,45 @@ UserSchema.statics.getUserShortDataByUsername = async function(idapp, username)
|
||||
email: 1,
|
||||
date_reg: 1,
|
||||
img: 1,
|
||||
}).then((ris) => {
|
||||
if (!!ris) {
|
||||
// console.log('ris', ris);
|
||||
if (!!ris._doc)
|
||||
return ris._doc;
|
||||
else
|
||||
return null;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
UserSchema.statics.getUserShortDataByUsername = async function(idapp, username) {
|
||||
const User = this;
|
||||
|
||||
let regexp = new RegExp(`^${username}$`, 'i');
|
||||
|
||||
const myrec = await User.findOne({
|
||||
'idapp': idapp,
|
||||
username: {$regex: regexp},
|
||||
$or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}],
|
||||
},
|
||||
this.getProjectUser(),
|
||||
).lean();
|
||||
|
||||
if (myrec) {
|
||||
myrec.qualified = await User.isUserQualified7(idapp, myrec.username);
|
||||
myrec.numNaviEntrato = 0;
|
||||
// myrec.numinvitati = await ListaIngresso.getnumInvitati(idapp, myrec.username);
|
||||
// myrec.numinvitatiattivi = await ListaIngresso.getnumInvitatiAttivi(idapp, myrec.username);
|
||||
}
|
||||
});
|
||||
|
||||
return myrec;
|
||||
};
|
||||
|
||||
UserSchema.statics.getUserShortDataByUsernameTelegram = async function(idapp, username_telegram) {
|
||||
const User = this;
|
||||
|
||||
let regexp = new RegExp(`^${username_telegram}$`, 'i');
|
||||
|
||||
const myrec = await User.findOne({
|
||||
'idapp': idapp,
|
||||
'profile.username_telegram': {$regex: regexp},
|
||||
$or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}],
|
||||
},
|
||||
this.getProjectUser(),
|
||||
).lean();
|
||||
|
||||
if (myrec) {
|
||||
myrec.qualified = await User.isUserQualified7(idapp, myrec.username);
|
||||
@@ -2646,7 +2668,7 @@ UserSchema.statics.getUsernameTelegram = async function(idapp, username) {
|
||||
const User = this;
|
||||
return await User.findOne({idapp, username}, {'profile.username_telegram': 1}).lean().then((ris) => {
|
||||
if (ris)
|
||||
return ris.profile.username_telegram
|
||||
return ris.profile.username_telegram;
|
||||
else
|
||||
return '';
|
||||
});
|
||||
|
||||
@@ -2587,8 +2587,12 @@ class Telegram {
|
||||
let aportador_solidario = rec.aportador_solidario;
|
||||
if (!aportador_solidario) {
|
||||
aportador_solidario = msg.text.toString().trim().toLowerCase();
|
||||
tools.removeAtChar(aportador_solidario);
|
||||
const user = await User.getUserShortDataByUsername(this.idapp, aportador_solidario);
|
||||
aportador_solidario = tools.removeAtChar(aportador_solidario);
|
||||
let user = await User.getUserShortDataByUsername(this.idapp, aportador_solidario);
|
||||
if (!user) {
|
||||
// check if is username telegram inserted
|
||||
user = await User.getUserShortDataByUsernameTelegram(this.idapp, aportador_solidario);
|
||||
}
|
||||
if (user)
|
||||
rec.aportador_solidario = user.username;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user