SubAccounts
This commit is contained in:
@@ -10,7 +10,7 @@ const { Settings } = require('../models/settings');
|
||||
const { ListaIngresso } = require('../models/listaingresso');
|
||||
const { Nave } = require('../models/nave');
|
||||
const { NavePersistente } = require('../models/navepersistente');
|
||||
const { ExtraList } = require('../models/extralist');
|
||||
// const { ExtraList } = require('../models/extralist');
|
||||
|
||||
const { ObjectID } = require('mongodb');
|
||||
|
||||
@@ -46,9 +46,15 @@ const UserSchema = new mongoose.Schema({
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
index: {
|
||||
type: Number
|
||||
},
|
||||
ind_order: {
|
||||
type: Number
|
||||
},
|
||||
old_order: {
|
||||
type: Number
|
||||
},
|
||||
username: {
|
||||
type: String,
|
||||
required: true,
|
||||
@@ -121,7 +127,7 @@ const UserSchema = new mongoose.Schema({
|
||||
news_on: {
|
||||
type: Boolean
|
||||
},
|
||||
aportador_solidario: {
|
||||
aportador_solidario: { // da cancellare
|
||||
type: String,
|
||||
},
|
||||
aportador_iniziale: {
|
||||
@@ -401,6 +407,7 @@ UserSchema.statics.getUserShortDataByUsername = async function (idapp, username)
|
||||
lang: 1,
|
||||
ind_order: 1,
|
||||
username: 1,
|
||||
aportador_solidario: 1,
|
||||
name: 1,
|
||||
surname: 1,
|
||||
deleted: 1,
|
||||
@@ -429,101 +436,96 @@ UserSchema.statics.getUserShortDataByUsername = async function (idapp, username)
|
||||
|
||||
if (myrec) {
|
||||
myrec.qualified = await User.isUserQualified7(idapp, myrec.username);
|
||||
myrec.numinvitati = await User.getnumInvitati(idapp, myrec.username);
|
||||
myrec.numinvitatiattivi = await User.getnumInvitatiAttivi(idapp, myrec.username);
|
||||
myrec.numNaviEntrato = await Nave.getnumNaviByUsername(idapp, myrec.username);
|
||||
myrec.numinvitati = await ListaIngresso.getnumInvitati(idapp, myrec.username);
|
||||
myrec.numinvitatiattivi = await ListaIngresso.getnumInvitatiAttivi(idapp, myrec.username);
|
||||
}
|
||||
|
||||
return myrec
|
||||
};
|
||||
|
||||
UserSchema.statics.getDownlineByUsername = async function (idapp, username) {
|
||||
|
||||
if (username === undefined)
|
||||
return null;
|
||||
|
||||
const User = this;
|
||||
const arrrec = await User.find({
|
||||
'idapp': idapp,
|
||||
'aportador_solidario': username,
|
||||
const arrrec = await ListaIngresso.getInvitati(idapp, username,
|
||||
{
|
||||
index: 1,
|
||||
lang: 1,
|
||||
invitante_username: 1,
|
||||
ind_order: 1,
|
||||
username: 1,
|
||||
name: 1,
|
||||
surname: 1,
|
||||
verified_email: 1,
|
||||
'profile.teleg_id': 1,
|
||||
'profile.saw_zoom_presentation': 1,
|
||||
'profile.saw_and_accepted': 1,
|
||||
'profile.email_paypal': 1,
|
||||
'profile.my_dream': 1,
|
||||
'profile.paymenttypes': 1,
|
||||
'profile.cell': 1,
|
||||
made_gift: 1,
|
||||
email: 1,
|
||||
date_reg: 1,
|
||||
img: 1
|
||||
}
|
||||
);
|
||||
|
||||
// Ottieni gli invitati che ancora non hanno un'imbarco
|
||||
const arrinv = await User.find({
|
||||
idapp,
|
||||
aportador_solidario: username,
|
||||
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }]
|
||||
}, {
|
||||
lang: 1,
|
||||
aportador_solidario: 1,
|
||||
ind_order: 1,
|
||||
username: 1,
|
||||
name: 1,
|
||||
surname: 1,
|
||||
verified_email: 1,
|
||||
'profile.teleg_id': 1,
|
||||
'profile.saw_zoom_presentation': 1,
|
||||
'profile.saw_and_accepted': 1,
|
||||
'profile.email_paypal': 1,
|
||||
'profile.my_dream': 1,
|
||||
'profile.paymenttypes': 1,
|
||||
'profile.cell': 1,
|
||||
made_gift: 1,
|
||||
email: 1,
|
||||
date_reg: 1,
|
||||
img: 1
|
||||
}, (err, arrrec) => {
|
||||
return arrrec;
|
||||
});
|
||||
|
||||
for (const inv of arrinv) {
|
||||
if (!arrrec.find((rec) => rec.username === inv.username))
|
||||
arrrec.push(inv);
|
||||
}
|
||||
|
||||
|
||||
if (!!arrrec) {
|
||||
for (const rec of arrrec) {
|
||||
rec._doc.qualified = await User.isUserQualified7(idapp, rec.username);
|
||||
rec._doc.numinvitati = await User.getnumInvitati(idapp, rec.username);
|
||||
rec._doc.numinvitatiattivi = await User.getnumInvitatiAttivi(idapp, rec.username);
|
||||
rec.qualified = await User.isUserQualified7(idapp, rec.username);
|
||||
rec.numNaviEntrato = await Nave.getnumNaviByUsername(idapp, rec.username);
|
||||
rec.numinvitati = await ListaIngresso.getnumInvitati(idapp, rec.username);
|
||||
rec.numinvitatiattivi = await ListaIngresso.getnumInvitatiAttivi(idapp, rec.username);
|
||||
}
|
||||
}
|
||||
|
||||
return arrrec
|
||||
return arrrec;
|
||||
|
||||
};
|
||||
|
||||
UserSchema.statics.getQueryQualified = function () {
|
||||
return [
|
||||
{
|
||||
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
|
||||
},
|
||||
{
|
||||
$or: [
|
||||
{
|
||||
'profile.special_req': true
|
||||
},
|
||||
{
|
||||
verified_email: true,
|
||||
'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 },
|
||||
'profile.email_paypal': { $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",
|
||||
}]
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
UserSchema.statics.getnumInvitatiAttivi = function (idapp, username) {
|
||||
const User = this;
|
||||
|
||||
if (username === undefined)
|
||||
return 0;
|
||||
|
||||
// return User.count({
|
||||
return User.countDocuments({
|
||||
idapp,
|
||||
aportador_solidario: username,
|
||||
$and: [
|
||||
{
|
||||
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
|
||||
},
|
||||
{
|
||||
$or: [
|
||||
{
|
||||
'profile.special_req': true
|
||||
},
|
||||
{
|
||||
|
||||
verified_email: true,
|
||||
'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 },
|
||||
'profile.paymenttypes': { "$in": ['paypal'] },
|
||||
$and: [
|
||||
{ 'profile.my_dream': { $exists: true } },
|
||||
{ "$expr": { "$gt": [{ "$strLenCP": "$profile.my_dream" }, 10] } },
|
||||
{
|
||||
$and: [
|
||||
{ 'profile.email_paypal': { $exists: true } },
|
||||
{ "$expr": { "$gt": [{ "$strLenCP": "$profile.email_paypal" }, 6] } }
|
||||
],
|
||||
}
|
||||
],
|
||||
}]
|
||||
}
|
||||
]
|
||||
})
|
||||
;
|
||||
};
|
||||
|
||||
UserSchema.statics.isUserQualified7 = async function (idapp, username) {
|
||||
const User = this;
|
||||
@@ -534,30 +536,7 @@ UserSchema.statics.isUserQualified7 = async function (idapp, username) {
|
||||
const myquery = {
|
||||
'idapp': idapp,
|
||||
'username': username,
|
||||
$and: [
|
||||
{
|
||||
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
|
||||
},
|
||||
{
|
||||
$or: [
|
||||
{
|
||||
'profile.special_req': true
|
||||
},
|
||||
{
|
||||
verified_email: true,
|
||||
'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 },
|
||||
'profile.email_paypal': { $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",
|
||||
}]
|
||||
}]
|
||||
$and: User.getQueryQualified(),
|
||||
};
|
||||
|
||||
const myrec = await User.findOne(myquery);
|
||||
@@ -572,7 +551,7 @@ UserSchema.statics.isUserQualified9 = async function (idapp, username) {
|
||||
return false;
|
||||
|
||||
qualified = await User.isUserQualified7(idapp, username);
|
||||
numinvitatiattivi = await User.getnumInvitatiAttivi(idapp, username);
|
||||
numinvitatiattivi = await ListaIngresso.getnumInvitatiAttivi(idapp, username);
|
||||
|
||||
return qualified && (numinvitatiattivi >= 2);
|
||||
|
||||
@@ -616,16 +595,6 @@ UserSchema.statics.getindOrderDuplicate = function (idapp) {
|
||||
});
|
||||
};
|
||||
|
||||
UserSchema.statics.getnumInvitati = function (idapp, username) {
|
||||
const User = this;
|
||||
|
||||
return User.count({
|
||||
idapp,
|
||||
aportador_solidario: username,
|
||||
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
|
||||
});
|
||||
};
|
||||
|
||||
UserSchema.statics.findByLinkreg = function (idapp, linkreg) {
|
||||
const User = this;
|
||||
|
||||
@@ -696,24 +665,55 @@ UserSchema.statics.findByIndOrder = function (idapp, ind_order) {
|
||||
}
|
||||
};
|
||||
|
||||
UserSchema.statics.findByOldOrder = function (idapp, old_order) {
|
||||
const User = this;
|
||||
|
||||
UserSchema.pre('save', function (next) {
|
||||
const user = this;
|
||||
|
||||
|
||||
/*
|
||||
if (user.isModified('password')) {
|
||||
bcrypt.genSalt(10, (err, salt) => {
|
||||
bcrypt.hash(user.password, salt, (err, hash) => {
|
||||
user.password = hash;
|
||||
next();
|
||||
});
|
||||
try {
|
||||
return User.findOne({
|
||||
idapp,
|
||||
old_order,
|
||||
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
|
||||
});
|
||||
} else {
|
||||
next();
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
UserSchema.pre('save', async function (next) {
|
||||
|
||||
try {
|
||||
if (this.isNew) {
|
||||
try {
|
||||
const myrec = await User.findOne({ idapp: this.idapp }).limit(1).sort({ index: -1 });
|
||||
|
||||
if (!!myrec) {
|
||||
this.index = myrec._doc.index + 1;
|
||||
} else {
|
||||
this.index = 1;
|
||||
}
|
||||
} catch (e) {
|
||||
this.index = 2;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
if (user.isModified('password')) {
|
||||
bcrypt.genSalt(10, (err, salt) => {
|
||||
bcrypt.hash(user.password, salt, (err, hash) => {
|
||||
user.password = hash;
|
||||
next();
|
||||
});
|
||||
});
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
*/
|
||||
|
||||
next();
|
||||
}catch (e) {
|
||||
console.error(e.message);
|
||||
}
|
||||
*/
|
||||
next();
|
||||
});
|
||||
|
||||
UserSchema.methods.removeToken = function (token) {
|
||||
@@ -763,15 +763,6 @@ UserSchema.statics.getUserById = function (idapp, id) {
|
||||
})
|
||||
};
|
||||
|
||||
UserSchema.statics.getUserByAportador = function (idapp, aportador_solidario) {
|
||||
const User = this;
|
||||
|
||||
return User.findOne({
|
||||
idapp, aportador_solidario,
|
||||
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
|
||||
})
|
||||
};
|
||||
|
||||
UserSchema.statics.getAportadorSolidarioByUsername = async function (idapp, username) {
|
||||
const User = this;
|
||||
|
||||
@@ -920,25 +911,31 @@ UserSchema.statics.getNameSurnameByUsername = async function (idapp, username) {
|
||||
};
|
||||
|
||||
UserSchema.statics.getSmallRecByIndOrder = async function (idapp, ind_order) {
|
||||
const User = this;
|
||||
|
||||
return await User.findOne({
|
||||
idapp, ind_order,
|
||||
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }]
|
||||
},
|
||||
{
|
||||
idapp: 1,
|
||||
ind_order: 1,
|
||||
username: 1,
|
||||
name: 1,
|
||||
surname: 1
|
||||
}
|
||||
)
|
||||
.then((rec) => {
|
||||
return rec;
|
||||
}).catch((e) => {
|
||||
console.error('getSmallRecByIndOrder', e);
|
||||
});
|
||||
try {
|
||||
const rec = await ListaIngresso.getarray(idapp,
|
||||
{
|
||||
idapp,
|
||||
ind_order,
|
||||
deleted: false,
|
||||
},
|
||||
{
|
||||
idapp: 1,
|
||||
ind_order: 1,
|
||||
username: 1,
|
||||
name: 1,
|
||||
surname: 1
|
||||
});
|
||||
|
||||
if (!!rec)
|
||||
return rec[0];
|
||||
|
||||
return null;
|
||||
|
||||
} catch (e) {
|
||||
console.error('getSmallRecByIndOrder', e);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -995,7 +992,7 @@ UserSchema.statics.isAdminByIdTeleg = async function (idapp, idtelegram) {
|
||||
|
||||
return await User.findOne({
|
||||
idapp,
|
||||
'username': 'paoloar77',
|
||||
username: 'paoloar77',
|
||||
'profile.manage_telegram': true,
|
||||
'profile.teleg_id': idtelegram
|
||||
}, { 'profile.teleg_id': 1 })
|
||||
@@ -1061,13 +1058,17 @@ UserSchema.statics.getUsersListByParams = function (params) {
|
||||
*/
|
||||
|
||||
UserSchema.statics.getFieldsForSearch = function () {
|
||||
return [{ field: 'username', type: tools.FieldType.string },
|
||||
return [
|
||||
{ field: 'username', type: tools.FieldType.string },
|
||||
{ field: 'name', type: tools.FieldType.string },
|
||||
{ field: 'index', type: tools.FieldType.number },
|
||||
{ field: 'ind_order', type: tools.FieldType.number },
|
||||
{ field: 'old_order', type: tools.FieldType.number },
|
||||
{ field: 'surname', type: tools.FieldType.string },
|
||||
{ field: 'email', type: tools.FieldType.string },
|
||||
{ field: 'profile.cell', type: tools.FieldType.string },
|
||||
{ field: 'profile.email_paypal', type: tools.FieldType.string },
|
||||
{ field: 'profile.teleg_id', type: tools.FieldType.number },
|
||||
{ field: 'profile.username_telegram', type: tools.FieldType.string },
|
||||
{ field: 'aportador_solidario', type: tools.FieldType.string }]
|
||||
};
|
||||
@@ -1102,20 +1103,23 @@ UserSchema.statics.getDashboard = async function (idapp, aportador_solidario, us
|
||||
// DATA: username, name, surname, email, intcode_cell, cell
|
||||
const dashboard = {
|
||||
aportador: {},
|
||||
downline: []
|
||||
downline: [],
|
||||
arrposizioni: [],
|
||||
arrimbarchi: [],
|
||||
arrusers: {},
|
||||
};
|
||||
|
||||
dashboard.myself = await User.getUserShortDataByUsername(idapp, username);
|
||||
// Data of my Aportador
|
||||
dashboard.aportador = await User.getUserShortDataByUsername(idapp, aportador_solidario);
|
||||
if (dashboard.aportador === undefined) {
|
||||
dashboard.aportador = await ExtraList.getUserNotRegisteredByNameSurname(idapp, aportador_solidario_nome_completo);
|
||||
}
|
||||
// if (dashboard.aportador === undefined) {
|
||||
// dashboard.aportador = await ExtraList.getUserNotRegisteredByNameSurname(idapp, aportador_solidario_nome_completo);
|
||||
// }
|
||||
|
||||
dashboard.downline = [];
|
||||
|
||||
// Data of my Downline
|
||||
const arrap = await User.getDownlineByUsername(idapp, aportador_solidario);
|
||||
const arrap = await User.getDownlineByUsername(idapp, username);
|
||||
if (!!arrap)
|
||||
dashboard.numpeople_aportador = arrap.length;
|
||||
|
||||
@@ -1132,32 +1136,33 @@ UserSchema.statics.getDashboard = async function (idapp, aportador_solidario, us
|
||||
}
|
||||
}
|
||||
|
||||
if (!!dashboard.myself.ind_order)
|
||||
dashboard.arrposizioni = await Nave.getArrPosizioniByIndOrder(idapp, dashboard.myself.ind_order);
|
||||
else
|
||||
dashboard.arrposizioni = [];
|
||||
dashboard.arrimbarchi = await ListaIngresso.findAllByUsername(idapp, username);
|
||||
|
||||
if (!!dashboard.myself.ind_order)
|
||||
dashboard.arrimbarchi = await ListaIngresso.findAllByIndOrder(idapp, dashboard.myself.ind_order);
|
||||
else
|
||||
dashboard.arrimbarchi = [];
|
||||
// dashboard.arrprofili = await Nave.getArrProfiliByIndOrder(idapp, dashboard.myself.ind_order);
|
||||
|
||||
dashboard.arrposizioni = await Nave.getArrPosizioniByUsername(idapp, username);
|
||||
|
||||
const arrrec = await ListaIngresso.getProssimiInLista(idapp, true);
|
||||
|
||||
for (let myimbarco of dashboard.arrimbarchi) {
|
||||
myimbarco._doc.posiz = await ListaIngresso.getPosizioneInLista(idapp, myimbarco.ind_order, myimbarco.num_tess);
|
||||
if (!!myimbarco.invitante_username)
|
||||
dashboard.arrusers[myimbarco.invitante_username] = await User.getUserShortDataByUsername(idapp, myimbarco.invitante_username);
|
||||
myimbarco._doc.posiz = await ListaIngresso.getPosizioneInLista(idapp, arrrec, myimbarco.ind_order, myimbarco.num_tess);
|
||||
}
|
||||
dashboard.navi_partenza = await NavePersistente.getListaNavi(idapp);
|
||||
|
||||
dashboard.lastnave = await NavePersistente.getLastNave(idapp);
|
||||
|
||||
//for (let indriga = 0; indriga < 10; indriga++) {
|
||||
// dashboard.navi_partenza.push(await Nave.getPrimaNaveByRiga(idapp, indriga));
|
||||
//}
|
||||
|
||||
for (let mypos of dashboard.arrposizioni) {
|
||||
mypos._doc.rec = await Nave.getNaveByRigaCol(idapp, mypos.riga, mypos.col);
|
||||
mypos._doc.nave_partenza = await NavePersistente.findByRigaColByDonatore(idapp, mypos.riga, mypos.col, 0);
|
||||
}
|
||||
|
||||
//for (let indriga = 0; indriga < 10; indriga++) {
|
||||
// dashboard.navi_partenza.push(await Nave.getPrimaNaveByRiga(idapp, indriga));
|
||||
//}
|
||||
|
||||
|
||||
const arrnew = [];
|
||||
|
||||
for (let mypos of dashboard.arrposizioni) {
|
||||
@@ -1167,7 +1172,8 @@ UserSchema.statics.getDashboard = async function (idapp, aportador_solidario, us
|
||||
|
||||
if (mypos.num_tess % 2 !== 0) {
|
||||
for (let myrec of dashboard.arrposizioni) {
|
||||
if (myrec.num_tess === mypos.num_tess + 1) {
|
||||
if (myrec.num_tess === mypos.num_tess + 1 && (myrec.ind_order === mypos.ind_order)) {
|
||||
// La Nave di Ritorno (numtess = 2) esiste nella lista !
|
||||
trovato = true
|
||||
}
|
||||
}
|
||||
@@ -1190,14 +1196,14 @@ UserSchema.statics.getDashboard = async function (idapp, aportador_solidario, us
|
||||
|
||||
myrec.nave_partenza = await NavePersistente.findByRigaColByDonatore(idapp, myrec.riga, myrec.col, 0);
|
||||
|
||||
arrnew.push(myrec);
|
||||
arrnew.push(myrec);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dashboard.arrposizioni = [...dashboard.arrposizioni, ...arrnew];
|
||||
|
||||
// console.table(dashboard.arrnavi);
|
||||
// console.table(dashboard.arrnavi);
|
||||
|
||||
return dashboard;
|
||||
} catch (e) {
|
||||
@@ -1248,6 +1254,7 @@ UserSchema.statics.getUsersRegistered = async function (idapp) {
|
||||
return await User.count(myfind);
|
||||
};
|
||||
|
||||
/*
|
||||
UserSchema.statics.getUsersQualified = async function (idapp, numinvitati) {
|
||||
const User = this;
|
||||
|
||||
@@ -1285,7 +1292,7 @@ UserSchema.statics.getUsersQualified = async function (idapp, numinvitati) {
|
||||
let arrris = [];
|
||||
|
||||
for (const rec of arrusers) {
|
||||
rec.numinvitatiattivi = await User.getnumInvitatiAttivi(idapp, rec.username);
|
||||
rec.numinvitatiattivi = await ListaIngresso.getnumInvitatiAttivi(idapp, rec.username);
|
||||
if (rec.numinvitatiattivi >= numinvitati) {
|
||||
arrris.push(rec);
|
||||
}
|
||||
@@ -1294,33 +1301,14 @@ UserSchema.statics.getUsersQualified = async function (idapp, numinvitati) {
|
||||
return arrris
|
||||
|
||||
};
|
||||
*/
|
||||
|
||||
UserSchema.statics.visuUtentiNonInNavi = async function (idapp) {
|
||||
const User = this;
|
||||
|
||||
const arrusers = await User.find({
|
||||
idapp,
|
||||
$and: [
|
||||
{ $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }] },
|
||||
{
|
||||
$or: [
|
||||
{
|
||||
'profile.special_req': true
|
||||
},
|
||||
{
|
||||
verified_email: true,
|
||||
'profile.teleg_id': { $gt: 0 },
|
||||
'profile.paymenttypes': { "$in": ['paypal'] },
|
||||
'profile.saw_and_accepted': shared_consts.ALL_SAW_AND_ACCEPTED,
|
||||
'profile.saw_zoom_presentation': true,
|
||||
'profile.my_dream': { $exists: true },
|
||||
$and: [
|
||||
{ "$expr": { "$gt": [{ "$strLenCP": "$profile.my_dream" }, 10] } },
|
||||
{ "$expr": { "$gt": [{ "$strLenCP": "$profile.email_paypal" }, 6] } }
|
||||
],
|
||||
}]
|
||||
}]
|
||||
|
||||
$and: User.getQueryQualified()
|
||||
}, {
|
||||
name: 1,
|
||||
surname: 1,
|
||||
@@ -1373,7 +1361,7 @@ UserSchema.statics.visuUtentiNonInNavi = async function (idapp) {
|
||||
visualizza = true;
|
||||
}
|
||||
|
||||
user.numinvitati = await User.getnumInvitati(idapp, user.username);
|
||||
user.numinvitati = await ListaIngresso.getnumInvitati(idapp, user.username);
|
||||
reg++;
|
||||
let mianave = await Nave.findOne({ idapp, ind_order: user.ind_order });
|
||||
let mialistaingresso = await ListaIngresso.findOne({ idapp, ind_order: user.ind_order });
|
||||
@@ -1439,13 +1427,13 @@ UserSchema.statics.visuUtentiNonInNavi = async function (idapp) {
|
||||
return { num, mystr };
|
||||
};
|
||||
|
||||
UserSchema.statics.getNumUsersQualified = async function (idapp, numinvitati) {
|
||||
|
||||
arrrec = await this.getUsersQualified(idapp, numinvitati);
|
||||
|
||||
return arrrec.length
|
||||
|
||||
};
|
||||
// UserSchema.statics.getNumUsersQualified = async function (idapp, numinvitati) {
|
||||
//
|
||||
// arrrec = await this.getUsersQualified(idapp, numinvitati);
|
||||
//
|
||||
// return arrrec.length
|
||||
//
|
||||
// };
|
||||
|
||||
|
||||
UserSchema.statics.getEmailNotVerified = async function (idapp) {
|
||||
@@ -1562,8 +1550,8 @@ UserSchema.statics.calculateStat = async function (idapp, username) {
|
||||
const User = this;
|
||||
|
||||
return calcstat = {
|
||||
numinvitati: await User.getnumInvitati(idapp, username),
|
||||
numinvitati_attivi: await User.getnumInvitatiAttivi(idapp, username),
|
||||
numinvitati: await ListaIngresso.getnumInvitati(idapp, username),
|
||||
numinvitati_attivi: await ListaIngresso.getnumInvitatiAttivi(idapp, username),
|
||||
};
|
||||
|
||||
};
|
||||
@@ -1693,12 +1681,13 @@ if (tools.INITDB_FIRSTIME) {
|
||||
}
|
||||
|
||||
async function addUtentiInLista(idapp, mode, arrusers) {
|
||||
|
||||
let num = 0;
|
||||
for (const rec of arrusers) {
|
||||
let ok = false;
|
||||
let qualified = await User.isUserQualified7(idapp, rec.username);
|
||||
let numinvitatiattivi = await User.getnumInvitatiAttivi(idapp, rec.username);
|
||||
let numinvitati = await User.getnumInvitati(idapp, rec.username);
|
||||
let numinvitatiattivi = await ListaIngresso.getnumInvitatiAttivi(idapp, rec.username);
|
||||
let numinvitati = await ListaIngresso.getnumInvitati(idapp, rec.username);
|
||||
|
||||
if (rec.profile.special_req) {
|
||||
numinvitatiattivi = 2;
|
||||
@@ -1719,12 +1708,13 @@ async function addUtentiInLista(idapp, mode, arrusers) {
|
||||
}
|
||||
|
||||
if (ok) {
|
||||
ris = await ListaIngresso.addUserInListaIngresso(idapp, rec.ind_order, rec.lang, false, 1);
|
||||
ris = await ListaIngresso.addUserInListaIngresso(idapp, rec.username, rec.aportador_solidario, rec.lang, false, true);
|
||||
if (!!ris)
|
||||
num++;
|
||||
}
|
||||
}
|
||||
return num;
|
||||
|
||||
}
|
||||
|
||||
UserSchema.statics.deveRitessersi = async function (idapp, ind_order) {
|
||||
@@ -1750,6 +1740,72 @@ UserSchema.statics.getUsernameByIndOrder = async function (idapp, ind_order) {
|
||||
|
||||
};
|
||||
|
||||
UserSchema.statics.getUsernameByIndex = async function (idapp, index) {
|
||||
|
||||
const myrec = await User.findOne({
|
||||
idapp,
|
||||
index,
|
||||
}, { username: 1 });
|
||||
|
||||
return (!!myrec) ? myrec.username : ''
|
||||
|
||||
};
|
||||
|
||||
UserSchema.statics.ricalcolaIndex = async function (idapp) {
|
||||
const User = this;
|
||||
|
||||
const arrusers = await User.find({ idapp }).sort({ ind_order: 1 });
|
||||
let index = 1;
|
||||
try {
|
||||
for (const user of arrusers) {
|
||||
let field = {
|
||||
index
|
||||
};
|
||||
|
||||
index++;
|
||||
|
||||
const ris = await User.findOneAndUpdate({ _id: user._id }, { $set: field }, { new: false });
|
||||
}
|
||||
}catch (e) {
|
||||
console.error(e.message);
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
UserSchema.statics.changeInvitante = async function (idapp, username, invitante_username, ind_order_ingr) {
|
||||
const User = this;
|
||||
|
||||
const rec_ind_order_prima = await ListaIngresso.findOne({ idapp, username });
|
||||
|
||||
let modif_aportador = false;
|
||||
// cambia aportador_solidario solo se è la prima nave!
|
||||
|
||||
// Oppure se ancora non sono in Lista!
|
||||
if (!rec_ind_order_prima) {
|
||||
modif_aportador = true;
|
||||
} else {
|
||||
if (rec_ind_order_prima.ind_order === ind_order_ingr) {
|
||||
modif_aportador = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (modif_aportador) {
|
||||
await User.findOneAndUpdate({ idapp, username }, { $set: { aportador_solidario: invitante_username } });
|
||||
}
|
||||
|
||||
// **
|
||||
// ** Cambia invitante_username e ind_order di LISTAINGRESSO
|
||||
// **
|
||||
const rec_ingr = await ListaIngresso.findOne({ idapp, username: username });
|
||||
if (!!rec_ingr) {
|
||||
await ListaIngresso.findByIdAndUpdate(rec_ingr._id, { $set: { invitante_username, ind_order: ind_order_ingr } });
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
UserSchema.statics.DbOp = async function (idapp, mydata) {
|
||||
const User = this;
|
||||
try {
|
||||
@@ -1788,7 +1844,7 @@ UserSchema.statics.DbOp = async function (idapp, mydata) {
|
||||
arrusers = await User.find({
|
||||
'idapp': idapp,
|
||||
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }]
|
||||
}).sort({ ind_order: 1 });
|
||||
}).sort({ date_added: 1 });
|
||||
let num = 0;
|
||||
|
||||
num += await addUtentiInLista(idapp, 1, arrusers);
|
||||
|
||||
Reference in New Issue
Block a user