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) {
|
UserSchema.statics.getProjectUser = function() {
|
||||||
const User = this;
|
return {
|
||||||
|
|
||||||
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}}],
|
|
||||||
}, {
|
|
||||||
idapp: 1,
|
idapp: 1,
|
||||||
lang: 1,
|
lang: 1,
|
||||||
index: 1,
|
index: 1,
|
||||||
@@ -740,15 +732,45 @@ UserSchema.statics.getUserShortDataByUsername = async function(idapp, username)
|
|||||||
email: 1,
|
email: 1,
|
||||||
date_reg: 1,
|
date_reg: 1,
|
||||||
img: 1,
|
img: 1,
|
||||||
}).then((ris) => {
|
};
|
||||||
if (!!ris) {
|
|
||||||
// console.log('ris', ris);
|
};
|
||||||
if (!!ris._doc)
|
|
||||||
return ris._doc;
|
UserSchema.statics.getUserShortDataByUsername = async function(idapp, username) {
|
||||||
else
|
const User = this;
|
||||||
return null;
|
|
||||||
}
|
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) {
|
if (myrec) {
|
||||||
myrec.qualified = await User.isUserQualified7(idapp, myrec.username);
|
myrec.qualified = await User.isUserQualified7(idapp, myrec.username);
|
||||||
@@ -2643,13 +2665,13 @@ UserSchema.statics.SetTelegramIdSuccess = async function(idapp, id, teleg_id) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
UserSchema.statics.getUsernameTelegram = async function(idapp, username) {
|
UserSchema.statics.getUsernameTelegram = async function(idapp, username) {
|
||||||
const User = this;
|
const User = this;
|
||||||
return await User.findOne({idapp, username}, {'profile.username_telegram': 1}).lean().then((ris) => {
|
return await User.findOne({idapp, username}, {'profile.username_telegram': 1}).lean().then((ris) => {
|
||||||
if (ris)
|
if (ris)
|
||||||
return ris.profile.username_telegram
|
return ris.profile.username_telegram;
|
||||||
else
|
else
|
||||||
return '';
|
return '';
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
UserSchema.statics.setUsernameTelegram = async function(
|
UserSchema.statics.setUsernameTelegram = async function(
|
||||||
|
|||||||
@@ -2587,8 +2587,12 @@ class Telegram {
|
|||||||
let aportador_solidario = rec.aportador_solidario;
|
let aportador_solidario = rec.aportador_solidario;
|
||||||
if (!aportador_solidario) {
|
if (!aportador_solidario) {
|
||||||
aportador_solidario = msg.text.toString().trim().toLowerCase();
|
aportador_solidario = msg.text.toString().trim().toLowerCase();
|
||||||
tools.removeAtChar(aportador_solidario);
|
aportador_solidario = tools.removeAtChar(aportador_solidario);
|
||||||
const user = await User.getUserShortDataByUsername(this.idapp, 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)
|
if (user)
|
||||||
rec.aportador_solidario = user.username;
|
rec.aportador_solidario = user.username;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user