Ultimo aggiornamento Nuova versione del Sito !
This commit is contained in:
@@ -115,6 +115,9 @@ const UserSchema = new mongoose.Schema({
|
||||
date_reg: {
|
||||
type: Date,
|
||||
},
|
||||
date_deleted: {
|
||||
type: Date,
|
||||
},
|
||||
date_tokenforgot: {
|
||||
type: Date
|
||||
},
|
||||
@@ -143,7 +146,8 @@ const UserSchema = new mongoose.Schema({
|
||||
type: String,
|
||||
},
|
||||
deleted: {
|
||||
type: Boolean
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
sospeso: {
|
||||
type: Boolean
|
||||
@@ -445,12 +449,12 @@ UserSchema.statics.getUserShortDataByUsername = async function (idapp, username)
|
||||
return myrec
|
||||
};
|
||||
|
||||
UserSchema.statics.getDownlineByUsername = async function (idapp, username, includemyself) {
|
||||
UserSchema.statics.getDownlineByUsername = async function (idapp, username, includemyself, onlynumber) {
|
||||
|
||||
if (username === undefined)
|
||||
return null;
|
||||
|
||||
const arrrec = await ListaIngresso.getInvitati(idapp, username, includemyself,
|
||||
let arrrec = await ListaIngresso.getInvitati(idapp, username, includemyself,
|
||||
{
|
||||
index: 1,
|
||||
lang: 1,
|
||||
@@ -481,7 +485,7 @@ UserSchema.statics.getDownlineByUsername = async function (idapp, username, incl
|
||||
};
|
||||
|
||||
if (!includemyself) {
|
||||
myq = { ...myq, username: {$ne: username} }
|
||||
myq = { ...myq, username: { $ne: username } }
|
||||
}
|
||||
|
||||
// Ottieni gli invitati che ancora non hanno un'imbarco
|
||||
@@ -489,16 +493,35 @@ UserSchema.statics.getDownlineByUsername = async function (idapp, username, incl
|
||||
|
||||
for (const inv of arrinv) {
|
||||
if (!arrrec.find((rec) => rec.username === inv.username))
|
||||
arrrec.push(inv);
|
||||
arrrec.push(inv._doc);
|
||||
}
|
||||
|
||||
const arrusername = [];
|
||||
|
||||
if (!!arrrec) {
|
||||
for (const rec of arrrec) {
|
||||
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);
|
||||
for (const inv of arrrec) {
|
||||
|
||||
const rectrovato = arrusername.find((rec) => inv.username === rec.username);
|
||||
if (!!rectrovato) {
|
||||
rectrovato.quanti++;
|
||||
} else {
|
||||
const myrec = { ...inv };
|
||||
myrec.quanti = 1;
|
||||
arrusername.push(myrec)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
arrrec = arrusername;
|
||||
|
||||
|
||||
if (!onlynumber) {
|
||||
if (!!arrrec) {
|
||||
for (const rec of arrrec) {
|
||||
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;
|
||||
@@ -928,7 +951,7 @@ UserSchema.statics.getSmallRecByIndOrder = async function (idapp, ind_order) {
|
||||
{
|
||||
idapp,
|
||||
ind_order,
|
||||
deleted: false,
|
||||
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }]
|
||||
},
|
||||
{
|
||||
idapp: 1,
|
||||
@@ -953,15 +976,44 @@ UserSchema.statics.getSmallRecByIndOrder = async function (idapp, ind_order) {
|
||||
|
||||
};
|
||||
|
||||
UserSchema.statics.getRecByIndOrder = async function (idapp, ind_order) {
|
||||
UserSchema.statics.NuovoSistema = function (idapp) {
|
||||
const User = this;
|
||||
|
||||
try {
|
||||
return User.findOne({ idapp, old_order: { $exists: true } })
|
||||
.then((ris) => {
|
||||
return !!ris;
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('NuovoSistema', e.message);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
UserSchema.statics.getRecByIndOrder = async function (idapp, ind_order) {
|
||||
const User = this;
|
||||
|
||||
try {
|
||||
|
||||
let filters = {
|
||||
idapp: 1,
|
||||
index: 1,
|
||||
ind_order: 1,
|
||||
old_order: 1,
|
||||
username: 1,
|
||||
name: 1,
|
||||
lang: 1,
|
||||
surname: 1,
|
||||
'profile.teleg_id': 1,
|
||||
};
|
||||
|
||||
const rec = await ListaIngresso.getarray(idapp,
|
||||
{
|
||||
idapp,
|
||||
ind_order,
|
||||
deleted: false,
|
||||
});
|
||||
},
|
||||
filters);
|
||||
|
||||
if (!!rec)
|
||||
return rec[0];
|
||||
@@ -1139,7 +1191,6 @@ UserSchema.statics.getDashboard = async function (idapp, aportador_solidario, us
|
||||
// DATA: username, name, surname, email, intcode_cell, cell
|
||||
const dashboard = {
|
||||
aportador: {},
|
||||
downline: [],
|
||||
arrposizioni: [],
|
||||
arrimbarchi: [],
|
||||
arrusers: {},
|
||||
@@ -1152,26 +1203,10 @@ UserSchema.statics.getDashboard = async function (idapp, aportador_solidario, us
|
||||
// dashboard.aportador = await ExtraList.getUserNotRegisteredByNameSurname(idapp, aportador_solidario_nome_completo);
|
||||
// }
|
||||
|
||||
dashboard.downline = [];
|
||||
|
||||
// Data of my Downline
|
||||
const arrap = await User.getDownlineByUsername(idapp, username);
|
||||
const arrap = await User.getDownlineByUsername(idapp, username, false, true);
|
||||
if (!!arrap)
|
||||
dashboard.numpeople_aportador = arrap.length;
|
||||
|
||||
dashboard.downline = await User.getDownlineByUsername(idapp, username, true);
|
||||
// dashboard.downnotreg = await ExtraList.getDownlineNotRegisteredByNameSurname(idapp, dashboard.myself.name + ' ' + dashboard.myself.surname);
|
||||
|
||||
dashboard.downbyuser = {};
|
||||
|
||||
for (const down of dashboard.downline) {
|
||||
dashboard.downbyuser[down.username] = await User.getDownlineByUsername(idapp, down.username, false);
|
||||
|
||||
for (const down2 of dashboard.downbyuser[down.username]) {
|
||||
dashboard.downbyuser[down2.username] = await User.getDownlineByUsername(idapp, down2.username, false);
|
||||
}
|
||||
}
|
||||
|
||||
dashboard.arrimbarchi = await ListaIngresso.findAllByUsername(idapp, username);
|
||||
|
||||
// dashboard.arrprofili = await Nave.getArrProfiliByIndOrder(idapp, dashboard.myself.ind_order);
|
||||
@@ -1193,8 +1228,8 @@ UserSchema.statics.getDashboard = async function (idapp, aportador_solidario, us
|
||||
dashboard.lastnave = await NavePersistente.getLastNave(idapp);
|
||||
|
||||
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);
|
||||
mypos.rec = await Nave.getNaveByRigaCol(idapp, mypos.riga, mypos.col);
|
||||
mypos.nave_partenza = await NavePersistente.findByRigaColByDonatore(idapp, mypos.riga, mypos.col, 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -1205,40 +1240,53 @@ UserSchema.statics.getDashboard = async function (idapp, aportador_solidario, us
|
||||
|
||||
const arrnew = [];
|
||||
|
||||
for (let mypos of dashboard.arrposizioni) {
|
||||
// Controlla se è presente la Nave con il num_tess pari
|
||||
try {
|
||||
for (let mypos of dashboard.arrposizioni) {
|
||||
// Controlla se è presente la Nave con il num_tess pari
|
||||
|
||||
let trovato = false;
|
||||
let trovato = false;
|
||||
|
||||
if (mypos.num_tess % 2 !== 0) {
|
||||
for (let myrec of dashboard.arrposizioni) {
|
||||
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
|
||||
if (mypos.num_tess % 2 !== 0) {
|
||||
for (let myrec of dashboard.arrposizioni) {
|
||||
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;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
trovato = true;
|
||||
}
|
||||
if (!trovato) {
|
||||
let myr = null;
|
||||
if (!!mypos._doc)
|
||||
myr = mypos._doc;
|
||||
else
|
||||
myr = mypos;
|
||||
|
||||
if (!!myr && !!myr.rec.mediatore) {
|
||||
const mymediatore = myr.rec.mediatore.arrdonatori[7];
|
||||
if (!!mymediatore) {
|
||||
const myrec = {
|
||||
riga: mymediatore.riga,
|
||||
col: mymediatore.col,
|
||||
name: myr.rec.mediatore.recmediatore.name,
|
||||
surname: myr.rec.mediatore.recmediatore.surname,
|
||||
username: myr.rec.mediatore.recmediatore.username,
|
||||
num_tess: myr.rec.mediatore.recmediatore.num_tess + 1,
|
||||
rec: await Nave.getNaveByRigaCol(idapp, mymediatore.riga, mymediatore.col),
|
||||
nave_partenza: {},
|
||||
};
|
||||
|
||||
myrec.nave_partenza = await NavePersistente.findByRigaColByDonatore(idapp, myrec.riga, myrec.col, 0);
|
||||
|
||||
arrnew.push(myrec);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
trovato = true;
|
||||
}
|
||||
if (!trovato) {
|
||||
const mymediatore = mypos._doc.rec.mediatore.arrdonatori[7];
|
||||
if (!!mymediatore) {
|
||||
const myrec = {
|
||||
riga: mymediatore.riga,
|
||||
col: mymediatore.col,
|
||||
name: mypos._doc.rec.mediatore.recmediatore.name,
|
||||
surname: mypos._doc.rec.mediatore.recmediatore.surname,
|
||||
username: mypos._doc.rec.mediatore.recmediatore.username,
|
||||
num_tess: mypos._doc.rec.mediatore.recmediatore.num_tess + 1,
|
||||
rec: await Nave.getNaveByRigaCol(idapp, mymediatore.riga, mymediatore.col),
|
||||
nave_partenza: {},
|
||||
};
|
||||
|
||||
myrec.nave_partenza = await NavePersistente.findByRigaColByDonatore(idapp, myrec.riga, myrec.col, 0);
|
||||
|
||||
arrnew.push(myrec);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
}
|
||||
|
||||
dashboard.arrposizioni = [...dashboard.arrposizioni, ...arrnew];
|
||||
@@ -1252,6 +1300,38 @@ UserSchema.statics.getDashboard = async function (idapp, aportador_solidario, us
|
||||
}
|
||||
};
|
||||
|
||||
UserSchema.statics.getDownline = async function (idapp, aportador_solidario, username) {
|
||||
try {
|
||||
|
||||
// DATA: username, name, surname, email, intcode_cell, cell
|
||||
let downline = {};
|
||||
|
||||
downline.downline = [];
|
||||
|
||||
// Data of my Downline
|
||||
const arrap = await User.getDownlineByUsername(idapp, username);
|
||||
if (!!arrap)
|
||||
downline.numpeople_aportador = arrap.length;
|
||||
|
||||
downline.downline = await User.getDownlineByUsername(idapp, username, true);
|
||||
|
||||
downline.downbyuser = {};
|
||||
|
||||
for (const down of downline.downline) {
|
||||
downline.downbyuser[down.username] = await User.getDownlineByUsername(idapp, down.username, false);
|
||||
|
||||
for (const down2 of downline.downbyuser[down.username]) {
|
||||
downline.downbyuser[down2.username] = await User.getDownlineByUsername(idapp, down2.username, false);
|
||||
}
|
||||
}
|
||||
|
||||
return downline;
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
UserSchema.statics.fixUsername = async function (idapp, aportador_solidario_ind_order, username) {
|
||||
const User = this;
|
||||
@@ -1780,7 +1860,10 @@ UserSchema.statics.getUsernameByIndex = async function (idapp, index) {
|
||||
UserSchema.statics.ricalcolaIndex = async function (idapp) {
|
||||
const User = this;
|
||||
|
||||
const arrusers = await User.find({ idapp }).sort({ ind_order: 1 });
|
||||
const arrusers = await User.find({
|
||||
idapp,
|
||||
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }]
|
||||
}).sort({ old_order: 1 });
|
||||
let index = 0;
|
||||
try {
|
||||
for (const user of arrusers) {
|
||||
|
||||
Reference in New Issue
Block a user