Ultimo aggiornamento Nuova versione del Sito !

This commit is contained in:
Paolo Arena
2020-05-14 17:23:17 +02:00
parent 2cb04f4f49
commit 1215d28777
9 changed files with 457 additions and 105 deletions

View File

@@ -43,6 +43,9 @@ const ListaIngressoSchema = new mongoose.Schema({
date_added: {
type: Date,
},
date_deleted: {
type: Date,
},
added: { // Added into Programmation (Nave)
type: Boolean,
default: false,
@@ -311,6 +314,50 @@ function getQueryProj(myfilter, myobjField, myfilter2, mygroup) {
return query;
}
function getQueryIndOrder(myfilter, myobjField, myfilter2, mygroup) {
const query = [
{ $match: myfilter },
{
$lookup: {
from: "users",
as: "user",
let: { ind_order: '$ind_order' },
pipeline: [
{
$match: {
$expr: {
$and: [
{ $eq: ['$ind_order', '$$ind_order'] },
{ $eq: ['$idapp', myfilter.idapp] },
]
}
}
}
]
}
},
{
$replaceRoot: { newRoot: { $mergeObjects: [{ $arrayElemAt: ["$user", 0] }, "$$ROOT"] } }
},
{ $match: myfilter2 },
];
if (!!mygroup) {
query.push(
{ $group: mygroup }
);
}
if (!!myobjField) {
query.push(
{ $project: myobjField }
);
}
return query;
}
ListaIngressoSchema.statics.getPosizioneInLista = async function (idapp, arrrec, ind_order, num_tess) {
@@ -338,9 +385,11 @@ ListaIngressoSchema.statics.showListaOrd = async function (idapp, solonuovi) {
let mystr = '';
let conta = 1;
for (const rec of arrrec) {
mystr += conta + ' - ' + ' [' + rec.numinvitatiattivi + '] - [' + rec.numinvitati + '] (' + rec.ind_order + ') ' + rec.username + ' ' + rec.name + ' ' + rec.surname;
mystr += conta + '- ' + ' [' + rec.numinvitatiattivi + '-' + rec.numinvitati + '] (' + rec.index + ') ';
mystr += ' [' + tools.getstrDateShort(rec.date_added, 'it') + '] ';
mystr += rec.username + ' ' + rec.name + ' ' + rec.surname;
mystr += ' inv = ' + rec.invitante_username;
mystr += ' num_tess = ' + rec.num_tess;
mystr += ' tess = ' + rec.num_tess;
if (rec.added)
mystr += ' (ADDED ++)';
@@ -388,6 +437,7 @@ ListaIngressoSchema.statics.getProssimiInLista = async function (idapp, solonuov
let myobjField = {
idapp: 1,
index: 1,
ind_order: 1,
name: 1,
surname: 1,
@@ -396,6 +446,7 @@ ListaIngressoSchema.statics.getProssimiInLista = async function (idapp, solonuov
email: 1,
lang: 1,
num_tess: 1,
date_added: 1,
added: 1,
deleted: 1,
sospeso: 1,
@@ -491,6 +542,14 @@ ListaIngressoSchema.statics.eliminaListeIngressoNascoste = async function (idapp
};
ListaIngressoSchema.statics.RendiVisibileIrecordNascosti = async function (idapp) {
const ListaIngresso = this;
const num = await ListaIngresso.updateMany({ idapp, deleted: true }, { $set: { deleted: false } });
};
ListaIngressoSchema.statics.creaTessituraeConv = async function (idapp) {
const ListaIngresso = this;
@@ -513,8 +572,6 @@ ListaIngressoSchema.statics.creaTessituraeConv = async function (idapp) {
idapp,
});
// Ricalcola il Campo Index
await User.ricalcolaIndex(idapp);
// Ricrea i record ListaIngresso (num_tess = 1), per ogni User
for (const user of arrusers) {
@@ -634,7 +691,7 @@ ListaIngressoSchema.statics.creaTessituraeConv = async function (idapp) {
await ListaIngresso.findByIdAndUpdate(findlistaingresso._id, {
$set: {
username,
invitante_username,
// invitante_username,
note: findlistaingresso.username,
}
}, { new: false });
@@ -652,7 +709,7 @@ ListaIngressoSchema.statics.creaTessituraeConv = async function (idapp) {
}
// poi imposta come cancellato questo record
await User.findByIdAndUpdate(myuser._id, { $set: { deleted: true } });
await User.findByIdAndUpdate(myuser._id, { $set: { deleted: true, date_deleted: new Date() } });
}
}
@@ -660,6 +717,13 @@ ListaIngressoSchema.statics.creaTessituraeConv = async function (idapp) {
index++;
}
// RIMUOVI IL CAMPO IND_ORDER SULLA USER!
await User.update({}, {$unset: {ind_order: 1}}, {multi: true});
// Ricalcola il Campo Index
await User.ricalcolaIndex(idapp);
return index;
} catch (e) {
@@ -684,6 +748,13 @@ ListaIngressoSchema.statics.getListaTessByUsername = function (idapp, username)
ListaIngressoSchema.statics.getarray = async function (idapp, filtri, myobjField) {
const ListaIngresso = this;
const { User } = require('./user');
if (!await User.NuovoSistema(idapp)) {
return await ListaIngresso.getarrayIndOrder(idapp, filtri, myobjField);
}
let myfilter2 = {
surname: { $exists: true },
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
@@ -699,6 +770,24 @@ ListaIngressoSchema.statics.getarray = async function (idapp, filtri, myobjField
};
ListaIngressoSchema.statics.getarrayIndOrder = async function (idapp, filtri, myobjField) {
const ListaIngresso = this;
let myfilter2 = {
surname: { $exists: true },
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
};
let myquery = getQueryIndOrder(
filtri,
myobjField,
myfilter2
);
return await ListaIngresso.aggregate(myquery);
};
ListaIngressoSchema.statics.getInvitati = async function (idapp, username, includemyself, myobjField) {
const ListaIngresso = this;
@@ -758,10 +847,10 @@ ListaIngressoSchema.statics.getnumInvitati = async function (idapp, username) {
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }]
});
/*for (const inv of arrinv) {
for (const inv of arrinv) {
if (!arrlistainv.find((rec) => rec.username === inv.username))
arrlistainv.push(inv);
}*/
}
if (!!arrlistainv)
return arrlistainv.length;
@@ -802,11 +891,11 @@ ListaIngressoSchema.statics.getnumInvitatiAttivi = async function (idapp, userna
$and: User.getQueryQualified()
});
/*
for (const inv of arrinv) {
if (!arrlistainv.find((rec) => rec.username === inv.username))
arrlistainv.push(inv);
}*/
}
if (!!arrlistainv)
return arrlistainv.length;

View File

@@ -485,6 +485,71 @@ function getQueryProj(myfilter) {
return query;
}
function getQueryInvitante(myfilter) {
myobjField = {
ind_order: 1,
name: 1,
surname: 1,
username: 1,
invitante_username: 1,
made_gift: 1,
sent_msg_howto_make_gift: 1,
date_made_gift: 1,
note: 1,
received_gift: 1,
date_received_gift: 1,
num_tess: 1,
parent_id: 1,
riga: 1,
col: 1,
created: 1,
};
const query = [
{ $match: myfilter },
{
$lookup: {
from: "listaingressos",
localField: "ind_order",
foreignField: "ind_order", // field in the user collection
as: "mylista"
}
},
{
$replaceRoot: { newRoot: { $mergeObjects: [{ $arrayElemAt: ["$mylista", 0] }, "$$ROOT"] } }
},
{
$lookup: {
from: "users",
as: "user",
let: { username: '$username' },
pipeline: [
{
$match: {
$expr: {
$and: [
{ $eq: ['$username', '$$username'] },
{ $eq: ['$idapp', myfilter.idapp] },
]
}
}
}
]
}
},
{
$replaceRoot: { newRoot: { $mergeObjects: [{ $arrayElemAt: ["$user", 0] }, "$$ROOT"] } }
// $replaceRoot: { newRoot: { $mergeObjects: [{ $arrayElemAt: ["$user", 0] },] } }
},
{ $match: { $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }] } },
{ $project: myobjField }
];
return query;
}
NaveSchema.statics.setRiga = function (idapp, riga) {
return Settings.setKeyNum(idapp, 'riga', riga);
@@ -848,11 +913,22 @@ NaveSchema.statics.getArrPosizioniByUsername = async function (idapp, username)
let arrposizioni = [];
for (const ind_order of arrrec_indorder) {
const myquery = getQueryInvitante({ idapp, ind_order });
const arr = await Nave.aggregate(myquery).sort({ riga: 1, col: 1 });
if (!!arr)
arrposizioni = [...arrposizioni, ...arr];
}
/*
for (const ind_order of arrrec_indorder) {
const arr = await Nave.find({ 'idapp': idapp, ind_order }).sort({ riga: 1, col: 1 });
if (!!arr)
arrposizioni = [...arrposizioni, ...arr];
}
*/
return arrposizioni;
} catch (e) {

View File

@@ -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) {