- Downline User
- Not registered if already exists. - Forgot Password
This commit is contained in:
@@ -332,6 +332,8 @@ UserSchema.statics.getUserShortDataByUsername = function (idapp, username) {
|
||||
name: 1,
|
||||
surname: 1,
|
||||
verified_email: 1,
|
||||
'profile.teleg_id': 1,
|
||||
'profile.saw_zoom_presentation': 1,
|
||||
made_gift: 1,
|
||||
email: 1,
|
||||
date_reg: 1,
|
||||
@@ -357,6 +359,8 @@ UserSchema.statics.getDownlineByUsername = function (idapp, username) {
|
||||
name: 1,
|
||||
surname: 1,
|
||||
verified_email: 1,
|
||||
'profile.teleg_id': 1,
|
||||
'profile.saw_zoom_presentation': 1,
|
||||
made_gift: 1,
|
||||
email: 1,
|
||||
date_reg: 1,
|
||||
@@ -366,17 +370,44 @@ UserSchema.statics.getDownlineByUsername = function (idapp, username) {
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
UserSchema.statics.getnumInvitatiAttivi = function (idapp, username) {
|
||||
const User = this;
|
||||
|
||||
return User.count({
|
||||
idapp,
|
||||
aportador_solidario: username,
|
||||
teleg_id: { $gt: 1 },
|
||||
saw_zoom_presentation: true,
|
||||
'profile.teleg_id': { $gt: 1 },
|
||||
'profile.saw_zoom_presentation': true,
|
||||
});
|
||||
};
|
||||
|
||||
UserSchema.statics.getUsersNationalityQuery = function (idapp) {
|
||||
const query = [
|
||||
{
|
||||
$match: { idapp }
|
||||
},
|
||||
{
|
||||
$group: { _id: "$profile.nationality", count: { $sum: 1 } }
|
||||
},
|
||||
{
|
||||
$sort: { count: -1 }
|
||||
}
|
||||
];
|
||||
return query
|
||||
};
|
||||
|
||||
|
||||
UserSchema.statics.getindOrderDuplicate = function (idapp) {
|
||||
const User = this;
|
||||
|
||||
return User.aggregate(User.getUsersNationalityQuery(idapp))
|
||||
.then(ris => {
|
||||
// console.table(ris);
|
||||
return JSON.stringify(ris);
|
||||
});
|
||||
};
|
||||
|
||||
UserSchema.statics.getnumInvitati = function (idapp, username) {
|
||||
const User = this;
|
||||
|
||||
@@ -462,6 +493,17 @@ UserSchema.statics.getEmailByUsername = async function (idapp, username) {
|
||||
});
|
||||
};
|
||||
|
||||
UserSchema.statics.getAportadorSolidarioByUsername = async function (idapp, username) {
|
||||
const User = this;
|
||||
|
||||
return await User.findOne({ idapp, username })
|
||||
.then((rec) => {
|
||||
return ((rec) ? rec.aportador_solidario : '');
|
||||
}).catch((e) => {
|
||||
console.error('getAportadorSolidarioByUsername', e);
|
||||
});
|
||||
};
|
||||
|
||||
UserSchema.statics.UserByIdTelegram = async function (idapp, teleg_id) {
|
||||
const User = this;
|
||||
|
||||
@@ -671,10 +713,18 @@ UserSchema.statics.getDashboard = async function (idapp, aportador_solidario, us
|
||||
dashboard.aportador = await User.getUserShortDataByUsername(idapp, aportador_solidario);
|
||||
|
||||
// Data of my Downline
|
||||
dashboard.downline = await User.getDownlineByUsername(idapp, username);
|
||||
const arrap = await User.getDownlineByUsername(idapp, aportador_solidario);
|
||||
dashboard.numpeople_aportador = arrap.length;
|
||||
|
||||
for (let index = 0; index < dashboard.downline.length; ++index) {
|
||||
dashboard.downline[index].downline = await User.getDownlineByUsername(idapp, dashboard.downline[index].username);
|
||||
dashboard.downline = await User.getDownlineByUsername(idapp, username);
|
||||
dashboard.downbyuser = {};
|
||||
|
||||
for (const down of dashboard.downline) {
|
||||
dashboard.downbyuser[down.username] = await User.getDownlineByUsername(idapp, down.username);
|
||||
|
||||
for (const down2 of dashboard.downbyuser[down.username]) {
|
||||
dashboard.downbyuser[down2.username] = await User.getDownlineByUsername(idapp, down2.username);
|
||||
}
|
||||
}
|
||||
return dashboard;
|
||||
} catch (e) {
|
||||
@@ -701,6 +751,18 @@ UserSchema.statics.fixUsername = async function (idapp, aportador_solidario_ind_
|
||||
|
||||
};
|
||||
|
||||
UserSchema.statics.findByCellAndNameSurname = function (idapp, cell, name, surname) {
|
||||
const User = this;
|
||||
|
||||
return User.findOne({
|
||||
'idapp': idapp,
|
||||
'profile.cell': cell,
|
||||
'name': name,
|
||||
'surname': surname,
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
UserSchema.statics.getUsersRegistered = async function (idapp) {
|
||||
const User = this;
|
||||
|
||||
@@ -788,7 +850,7 @@ UserSchema.statics.calculateStat = async function (idapp, username) {
|
||||
|
||||
};
|
||||
|
||||
UserSchema.statics.getUsersNationalityQuery = function (idapp) {
|
||||
UserSchema.statics.getDistinctNationalityQuery = function (idapp) {
|
||||
const query = [
|
||||
{
|
||||
$match: { idapp }
|
||||
@@ -807,7 +869,7 @@ UserSchema.statics.getUsersNationalityQuery = function (idapp) {
|
||||
UserSchema.statics.findAllDistinctNationality = async function (idapp) {
|
||||
const User = this;
|
||||
|
||||
return User.aggregate(User.getUsersNationalityQuery(idapp))
|
||||
return User.aggregate(User.getDistinctNationalityQuery(idapp))
|
||||
.then(ris => {
|
||||
// console.table(ris);
|
||||
return JSON.stringify(ris);
|
||||
@@ -852,6 +914,29 @@ if (tools.INITDB_FIRSTIME) {
|
||||
// UserSchema.index({ surname: 1 });
|
||||
}
|
||||
|
||||
UserSchema.statics.DbOp = async function (idapp, mydata) {
|
||||
const User = this;
|
||||
try {
|
||||
if (mydata.dbop === 'changeCellInt') {
|
||||
arrusers = await User.find({ 'idapp': idapp });
|
||||
let num = 0;
|
||||
for (const rec of arrusers) {
|
||||
let mycell = tools.removespaces(rec.profile.intcode_cell + rec.profile.cell);
|
||||
await User.findOneAndUpdate({ _id: rec._id }, { $set: { 'profile.cell': mycell } })
|
||||
num++;
|
||||
}
|
||||
|
||||
return { num };
|
||||
|
||||
// return await User.updateMany({ idapp }, { $set: { 'profile.cell': { $concat: ["$profile.intcode_cell", "$profile.cell"] } } })
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
const User = mongoose.model('User', UserSchema);
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user