|
|
|
|
@@ -19,6 +19,8 @@ const { ObjectID } = require('mongodb');
|
|
|
|
|
const shared_consts = require('../tools/shared_nodejs');
|
|
|
|
|
const queryclass = require('../classes/queryclass');
|
|
|
|
|
|
|
|
|
|
const telegrambot = require('../telegram/telegrambot');
|
|
|
|
|
|
|
|
|
|
mongoose.Promise = global.Promise;
|
|
|
|
|
|
|
|
|
|
mongoose.level = "F";
|
|
|
|
|
@@ -185,6 +187,12 @@ const UserSchema = new mongoose.Schema({
|
|
|
|
|
email_paypal: {
|
|
|
|
|
type: String
|
|
|
|
|
},
|
|
|
|
|
payeer_id: {
|
|
|
|
|
type: String
|
|
|
|
|
},
|
|
|
|
|
advcash_id: {
|
|
|
|
|
type: String
|
|
|
|
|
},
|
|
|
|
|
revolut: {
|
|
|
|
|
type: String
|
|
|
|
|
},
|
|
|
|
|
@@ -222,6 +230,9 @@ const UserSchema = new mongoose.Schema({
|
|
|
|
|
saw_zoom_presentation: {
|
|
|
|
|
type: Boolean
|
|
|
|
|
},
|
|
|
|
|
ask_zoom_partecipato: {
|
|
|
|
|
type: Boolean
|
|
|
|
|
},
|
|
|
|
|
qualified: {
|
|
|
|
|
type: Boolean
|
|
|
|
|
},
|
|
|
|
|
@@ -296,6 +307,36 @@ UserSchema.statics.setPermissionsById = function (id, perm) {
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
UserSchema.statics.setZoomPresenza = async function (idapp, id, presenza) {
|
|
|
|
|
const User = this;
|
|
|
|
|
|
|
|
|
|
const telegrambot = require('../telegram/telegrambot');
|
|
|
|
|
|
|
|
|
|
let allData = {};
|
|
|
|
|
allData.myuser = await User.getUserById(idapp, id);
|
|
|
|
|
if (!!allData.myuser)
|
|
|
|
|
allData.precDataUser = await User.getInfoUser(idapp, allData.myuser.username);
|
|
|
|
|
|
|
|
|
|
return await User.findByIdAndUpdate(id, { $set: { 'profile.saw_zoom_presentation': presenza } })
|
|
|
|
|
.then((rec) => {
|
|
|
|
|
if (presenza) {
|
|
|
|
|
const messaggio = tools.get__('ZOOM_CONFERMATO');
|
|
|
|
|
telegrambot.sendMsgTelegram(rec.idapp, rec.username, messaggio);
|
|
|
|
|
telegrambot.sendMsgTelegramToTheManagersAndZoomeri(idapp, `L\'utente ${rec.name} ${rec.surname} (${rec.username}) è stato confermato per aver visto lo Zoom di Benvenuto`);
|
|
|
|
|
} else {
|
|
|
|
|
telegrambot.sendMsgTelegramToTheManagersAndZoomeri(idapp, `L\'utente ${rec.name} ${rec.surname} (${rec.username}) è stato annullata la sua richiesta per aver visto lo Zoom di Benvenuto! (Non ci risulta)`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return User.findByIdAndUpdate(id, { $set: { 'profile.ask_zoom_partecipato': false } })
|
|
|
|
|
.then((user) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
User.checkIfSbloccatiRequisiti(idapp, allData, id);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
UserSchema.statics.isAdmin = function (perm) {
|
|
|
|
|
try {
|
|
|
|
|
return ((perm & shared_consts.Permissions.Admin) === shared_consts.Permissions.Admin);
|
|
|
|
|
@@ -320,6 +361,14 @@ UserSchema.statics.isTraduttrici = function (perm) {
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
UserSchema.statics.isZoomeri = function (perm) {
|
|
|
|
|
try {
|
|
|
|
|
return ((perm & shared_consts.Permissions.Zoomeri) === shared_consts.Permissions.Zoomeri);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
UserSchema.statics.isTutor = function (perm) {
|
|
|
|
|
try {
|
|
|
|
|
return ((perm & shared_consts.Permissions.Tutor) === shared_consts.Permissions.Tutor);
|
|
|
|
|
@@ -454,10 +503,13 @@ UserSchema.statics.getUserShortDataByUsername = async function (idapp, username)
|
|
|
|
|
verified_email: 1,
|
|
|
|
|
'profile.teleg_id': 1,
|
|
|
|
|
'profile.saw_zoom_presentation': 1,
|
|
|
|
|
'profile.ask_zoom_partecipato': 1,
|
|
|
|
|
'profile.qualified': 1,
|
|
|
|
|
'profile.qualified_2invitati': 1,
|
|
|
|
|
'profile.saw_and_accepted': 1,
|
|
|
|
|
'profile.email_paypal': 1,
|
|
|
|
|
'profile.payeer_id': 1,
|
|
|
|
|
'profile.advcash_id': 1,
|
|
|
|
|
'profile.revolut': 1,
|
|
|
|
|
'profile.link_payment': 1,
|
|
|
|
|
'profile.note_payment': 1,
|
|
|
|
|
@@ -505,10 +557,13 @@ UserSchema.statics.getDownlineByUsername = async function (idapp, username, incl
|
|
|
|
|
verified_email: 1,
|
|
|
|
|
'profile.teleg_id': 1,
|
|
|
|
|
'profile.saw_zoom_presentation': 1,
|
|
|
|
|
'profile.ask_zoom_partecipato': 1,
|
|
|
|
|
'profile.qualified': 1,
|
|
|
|
|
'profile.qualified_2invitati': 1,
|
|
|
|
|
'profile.saw_and_accepted': 1,
|
|
|
|
|
'profile.email_paypal': 1,
|
|
|
|
|
'profile.payeer_id': 1,
|
|
|
|
|
'profile.advcash_id': 1,
|
|
|
|
|
'profile.revolut': 1,
|
|
|
|
|
'profile.link_payment': 1,
|
|
|
|
|
'profile.note_payment': 1,
|
|
|
|
|
@@ -587,16 +642,14 @@ UserSchema.statics.getQueryQualified = function () {
|
|
|
|
|
'profile.teleg_id': { $gt: 1 },
|
|
|
|
|
'profile.saw_and_accepted': shared_consts.ALL_SAW_AND_ACCEPTED,
|
|
|
|
|
'profile.saw_zoom_presentation': true,
|
|
|
|
|
'profile.my_dream': { $exists: true },
|
|
|
|
|
$or: [
|
|
|
|
|
{ 'profile.link_payment': { $exists: true } },
|
|
|
|
|
{ 'profile.email_paypal': { $exists: true } },
|
|
|
|
|
{ 'profile.payeer_id': { $exists: true } },
|
|
|
|
|
{ 'profile.advcash_id': { $exists: true } },
|
|
|
|
|
{ 'profile.revolut': { $exists: true } },
|
|
|
|
|
],
|
|
|
|
|
// 'profile.paymenttypes': { "$in": ['paypal'] },
|
|
|
|
|
$and: [
|
|
|
|
|
{ "$expr": { "$gt": [{ "$strLenCP": "$profile.my_dream" }, 10] } },
|
|
|
|
|
// { "$expr": { "$gt": [{ "$strLenCP": "$profile.email_paypal" }, 6] } }
|
|
|
|
|
],
|
|
|
|
|
// $where: "this.profile.paymenttypes.length >= 1",
|
|
|
|
|
}]
|
|
|
|
|
}
|
|
|
|
|
@@ -700,6 +753,7 @@ UserSchema.statics.isUserQualified9 = async function (idapp, username) {
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
UserSchema.statics.getnumPaymentOk = function (idapp) {
|
|
|
|
|
const User = this;
|
|
|
|
|
|
|
|
|
|
@@ -719,6 +773,7 @@ UserSchema.statics.getnumPaymentOk = function (idapp) {
|
|
|
|
|
]
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
UserSchema.statics.getUsersNationalityQuery = function (idapp) {
|
|
|
|
|
const query = [
|
|
|
|
|
@@ -1148,6 +1203,8 @@ UserSchema.statics.getRecByIndOrder = async function (idapp, ind_order) {
|
|
|
|
|
surname: 1,
|
|
|
|
|
'profile.teleg_id': 1,
|
|
|
|
|
'profile.email_paypal': 1,
|
|
|
|
|
'profile.payeer_id': 1,
|
|
|
|
|
'profile.advcash_id': 1,
|
|
|
|
|
'profile.revolut': 1,
|
|
|
|
|
'profile.link_payment': 1,
|
|
|
|
|
'profile.note_payment': 1,
|
|
|
|
|
@@ -1184,6 +1241,33 @@ UserSchema.statics.getusersManagers = async function (idapp) {
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
UserSchema.statics.getusersManagersAndZoomeri = async function (idapp) {
|
|
|
|
|
const User = this;
|
|
|
|
|
|
|
|
|
|
return await User.find(
|
|
|
|
|
{
|
|
|
|
|
idapp,
|
|
|
|
|
or: [
|
|
|
|
|
{ 'profile.manage_telegram': true },
|
|
|
|
|
{
|
|
|
|
|
perm:
|
|
|
|
|
{
|
|
|
|
|
$bit:
|
|
|
|
|
|
|
|
|
|
Number(shared_consts.Permissions.Zoomeri)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{ 'profile.teleg_id': 1 })
|
|
|
|
|
.then((arrrec) => {
|
|
|
|
|
return (!!arrrec) ? arrrec : null;
|
|
|
|
|
}).catch((e) => {
|
|
|
|
|
console.error('getusersManagers', e);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
UserSchema.statics.getUsersTelegALL = async function (idapp, username) {
|
|
|
|
|
const User = this;
|
|
|
|
|
|
|
|
|
|
@@ -1302,6 +1386,8 @@ UserSchema.statics.getFieldsForSearch = function () {
|
|
|
|
|
{ field: 'email', type: tools.FieldType.string },
|
|
|
|
|
{ field: 'profile.cell', type: tools.FieldType.string },
|
|
|
|
|
{ field: 'profile.email_paypal', type: tools.FieldType.string },
|
|
|
|
|
{ field: 'profile.payeer_id', type: tools.FieldType.string },
|
|
|
|
|
{ field: 'profile.advcash_id', type: tools.FieldType.string },
|
|
|
|
|
{ field: 'profile.revolut', type: tools.FieldType.string },
|
|
|
|
|
{ field: 'profile.link_payment', type: tools.FieldType.string },
|
|
|
|
|
{ field: 'profile.teleg_id', type: tools.FieldType.number },
|
|
|
|
|
@@ -2105,6 +2191,143 @@ UserSchema.statics.NessunaNavePresenteByUsername = async function (idapp, userna
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
UserSchema.statics.getInfoUser = async function (idapp, username) {
|
|
|
|
|
return {
|
|
|
|
|
username,
|
|
|
|
|
is7req: await User.isUserQualified7(idapp, username),
|
|
|
|
|
is9req: await User.isUserQualified9(idapp, username),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UserSchema.statics.checkIfSbloccatiRequisiti = async function (idapp, allData, id) {
|
|
|
|
|
const User = this;
|
|
|
|
|
|
|
|
|
|
const telegrambot = require('../telegram/telegrambot');
|
|
|
|
|
|
|
|
|
|
if (!allData.myuser)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (await Nave.checkIfNaveExist(idapp, allData.myuser.username)) {
|
|
|
|
|
// Se già sei dentro la Nave, allora sei OK
|
|
|
|
|
return true; //TOGLEREE
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Controlla se Sblocca i 7 requisiti
|
|
|
|
|
const is7req = await User.isUserQualified7(idapp, allData.myuser.username);
|
|
|
|
|
const is9req = await User.isUserQualified9(idapp, allData.myuser.username);
|
|
|
|
|
|
|
|
|
|
const userlista = await ListaIngresso.getListaTessByUsername(idapp, allData.myuser.username);
|
|
|
|
|
//if (userlista.length > 0) { //TOGLIERE
|
|
|
|
|
if (userlista.length === 0) {
|
|
|
|
|
// Se non sono ancora dentro alla lista, allora controllo
|
|
|
|
|
|
|
|
|
|
if (!!allData.precDataUser) {
|
|
|
|
|
if ((!allData.precDataUser.is7req && is7req) && !await User.isUserAlreadyQualified(idapp, allData.myuser.username)) {
|
|
|
|
|
|
|
|
|
|
await User.setUserQualified(idapp, allData.myuser.username);
|
|
|
|
|
// ORA HAI I 7 REQUISITI !
|
|
|
|
|
// const msgtext = telegrambot.getCiao(idapp, allData.myuser.username, allData.myuser.lang) + tools.gettranslate('HAI_I_7_REQUISITI', allData.myuser.lang);
|
|
|
|
|
// telegrambot.sendMsgTelegram(idapp, allData.myuser.username, msgtext, true); // Anche a STAFF
|
|
|
|
|
|
|
|
|
|
// Aggiungilo alla ListaIngresso
|
|
|
|
|
risingr = await ListaIngresso.addUserInListaIngresso(idapp, allData.myuser.username, allData.myuser.aportador_iniziale, allData.myuser.lang, true, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!!allData.precDataUser) {
|
|
|
|
|
if ((!allData.precDataUser.is9req && is9req) && !await User.isUserAlreadyQualified_2Invitati(idapp, allData.myuser.username)) {
|
|
|
|
|
await User.setUserQualified_2Invitati(idapp, allData.myuser.username);
|
|
|
|
|
// ORA HAI I 9 REQUISITI !
|
|
|
|
|
const msgtext = telegrambot.getCiao(idapp, allData.myuser.username, allData.myuser.lang) + tools.gettranslate('HAI_I_9_REQUISITI', allData.myuser.lang);
|
|
|
|
|
telegrambot.sendMsgTelegram(idapp, allData.myuser.username, msgtext, false); // Anche a STAFF
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CHECK APORTADOR SOLIDARIO:
|
|
|
|
|
if (!!allData.useraportador) {
|
|
|
|
|
/*
|
|
|
|
|
const is9reqAportador = await User.isUserQualified9(idapp, allData.myuser.aportador_solidario);
|
|
|
|
|
|
|
|
|
|
if (!allData.precDataAportador.is9req && is9reqAportador) {
|
|
|
|
|
// ORA HAI I 9 REQUISITI !
|
|
|
|
|
const msgtext = telegrambot.getCiao(idapp, allData.myuser.aportador_solidario, allData.useraportador.lang) + tools.gettranslate('HAI_I_9_REQUISITI', allData.useraportador.lang);
|
|
|
|
|
telegrambot.sendMsgTelegram(idapp, allData.myuser.aportador_solidario, msgtext, true); // Anche a STAFF
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UserSchema.statics.mettiSognoePaypal = async function (idapp, modifica) {
|
|
|
|
|
const User = this;
|
|
|
|
|
|
|
|
|
|
let num = 0;
|
|
|
|
|
|
|
|
|
|
arrusers = await User.find({
|
|
|
|
|
'idapp': idapp,
|
|
|
|
|
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } },
|
|
|
|
|
{ subaccount: { $exists: false } }, { subaccount: { $exists: true, $eq: false } }]
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
for (const rec of arrusers) {
|
|
|
|
|
|
|
|
|
|
if (rec.profile.saw_zoom_presentation) {
|
|
|
|
|
aggiornato = false;
|
|
|
|
|
my_dream_ok = !!rec.profile.my_dream;
|
|
|
|
|
if (my_dream_ok)
|
|
|
|
|
my_dream_ok = rec.profile.my_dream.length >= 8;
|
|
|
|
|
|
|
|
|
|
if (!my_dream_ok) {
|
|
|
|
|
if (modifica) {
|
|
|
|
|
rec.profile.my_dream = '............';
|
|
|
|
|
aggiornato = true;
|
|
|
|
|
}
|
|
|
|
|
num++;
|
|
|
|
|
}
|
|
|
|
|
revolut_ok = !!rec.profile.revolut;
|
|
|
|
|
paypal_ok = !!rec.profile.email_paypal;
|
|
|
|
|
|
|
|
|
|
if (paypal_ok)
|
|
|
|
|
paypal_ok = rec.profile.email_paypal.length > 8;
|
|
|
|
|
|
|
|
|
|
if ((!revolut_ok) && (!paypal_ok)) {
|
|
|
|
|
if (modifica) {
|
|
|
|
|
rec.profile.email_paypal = rec.email;
|
|
|
|
|
aggiornato = true;
|
|
|
|
|
}
|
|
|
|
|
num++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (aggiornato && modifica) {
|
|
|
|
|
|
|
|
|
|
let allData = {};
|
|
|
|
|
allData.myuser = await User.getUserById(idapp, rec.id);
|
|
|
|
|
if (!!allData.myuser)
|
|
|
|
|
allData.precDataUser = await User.getInfoUser(idapp, allData.myuser.username);
|
|
|
|
|
else
|
|
|
|
|
allData.precDataUser = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const risupd = await User.findByIdAndUpdate(rec._id, {
|
|
|
|
|
'profile.email_paypal': rec.profile.email_paypal,
|
|
|
|
|
'profile.my_dream': rec.profile.my_dream
|
|
|
|
|
}, { new: false });
|
|
|
|
|
|
|
|
|
|
if (risupd) {
|
|
|
|
|
await User.checkIfSbloccatiRequisiti(idapp, allData, rec.id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return { num };
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
UserSchema.statics.flagUtentiNaviNonPresenti = async function (idapp) {
|
|
|
|
|
const User = this;
|
|
|
|
|
|
|
|
|
|
|