Lista Navi

This commit is contained in:
Paolo Arena
2020-04-07 14:34:29 +02:00
parent 8c9a5f7518
commit 7c575c0687
14 changed files with 317 additions and 154 deletions

View File

@@ -187,7 +187,7 @@ ListaIngressoSchema.statics.addUserInListaIngresso = async function (idapp, ind_
};
function getQueryProj(myfilter) {
function getQueryProj(myfilter, myobjField, myfilter2) {
const query = [
{ $match: myfilter },
{
@@ -201,6 +201,8 @@ function getQueryProj(myfilter) {
{
$replaceRoot: { newRoot: { $mergeObjects: [{ $arrayElemAt: ["$user", 0] }, "$$ROOT"] } }
},
{ $match: myfilter2 },
{ $project: myobjField }
];
return query;
@@ -210,24 +212,13 @@ function getQueryProj(myfilter) {
ListaIngressoSchema.statics.showListaOrd = async function (idapp, solonuovi) {
const ListaIngresso = this;
const { User } = require('./user');
let myquery = '';
if (solonuovi)
myquery = getQueryProj({ idapp, added: false });
else
myquery = getQueryProj({ idapp });
arrrec = await ListaIngresso.aggregate(myquery).sort({ indprimario: 1 });
arrrec = await ListaIngresso.getProssimiInLista(idapp, solonuovi);
let mystr = '';
let conta = 1;
for (const rec of arrrec) {
rec.numinvitati = await User.getnumInvitati(idapp, rec.username);
rec.numinvitatiattivi = await User.getnumInvitatiAttivi(idapp, rec.username);
mystr += '[' + conta + '] ' + rec.ind_order + ' [' + rec.numinvitatiattivi + '] - [' + rec.numinvitati + '] (' + rec.ind_order + ') ' + rec.name + ' ' + rec.surname;
mystr += ' num_tess = ' + rec.num_tess;
if (rec.added)
mystr += ' (ADDED ++)';
@@ -260,19 +251,46 @@ ListaIngressoSchema.statics.findAllIdApp = function (idapp) {
function sortRec(rec) {
return rec.sort(function (reca, recb) {
return recb.numinvitatiattivi - reca.numinvitatiattivi
return Math.round((recb.numinvitatiattivi + recb.numinvitati) / recb.num_tess) - Math.round((reca.numinvitatiattivi + reca.numinvitati) / reca.num_tess);
});
}
ListaIngressoSchema.statics.getProssimiInLista = async function (idapp, tutti) {
ListaIngressoSchema.statics.getProssimiInLista = async function (idapp, solonuovi) {
const ListaIngresso = this;
const myquery = getQueryProj({
'idapp': idapp,
ind_order: { $gt: 0 },
added: false,
deleted: false,
});
let myquery = '';
let myobjField = {
idapp: 1,
ind_order: 1,
name: 1,
surname: 1,
username: 1,
email: 1,
lang: 1,
num_tess: 1,
added: 1,
deleted: 1,
};
let myfilter2 = {
username: { $exists: true },
};
if (solonuovi) {
myquery = getQueryProj({
'idapp': idapp,
ind_order: { $gte: 0 },
added: false,
deleted: false,
}, myobjField, myfilter2);
} else {
myquery = getQueryProj({
'idapp': idapp,
ind_order: { $gte: 0 },
deleted: false,
}, myobjField, myfilter2);
}
arrrec = await ListaIngresso.aggregate(myquery).sort({ indprimario: 1 })
.then(async (arrlista) => {
@@ -280,6 +298,7 @@ ListaIngressoSchema.statics.getProssimiInLista = async function (idapp, tutti) {
const { User } = require('../models/user');
for (const rec of arrlista) {
rec.numinvitati = await User.getnumInvitati(idapp, rec.username);
rec.numinvitatiattivi = await User.getnumInvitatiAttivi(idapp, rec.username);
if (rec.numinvitatiattivi > 2)
rec.numinvitatiattivi = 2;

View File

@@ -43,15 +43,6 @@ const NaveSchema = new mongoose.Schema({
parent_id: {
type: mongoose.Schema.Types.ObjectId,
},
/*date_start: {
type: Date
},
date_gift_chat_open: {
type: Date
},
link_chat: {
type: String,
},*/
sent_msg_howto_make_gift: {
type: Boolean,
default: false,
@@ -80,18 +71,6 @@ const NaveSchema = new mongoose.Schema({
note: {
type: String
},
/* provvisoria: {
type: Boolean
},
note_bot: {
type: String
},
note_interne: {
type: String
},
tutor: {
type: String
}*/
});
NaveSchema.statics.getTotInLista = async function (idapp) {
@@ -115,6 +94,20 @@ NaveSchema.statics.findByIndOrder = function (idapp, ind_order) {
}
};
NaveSchema.statics.findByIndOrderAndNumTess = function (idapp, ind_order, num_tess) {
const Nave = this;
try {
return Nave.findOne({
idapp,
ind_order,
num_tess,
});
} catch (e) {
}
};
NaveSchema.statics.findById = function (idapp, id) {
const Nave = this;
@@ -140,7 +133,9 @@ NaveSchema.statics.findByIndPrimario = function (idapp, indprimario) {
NaveSchema.statics.getFieldsForSearch = function () {
return [{ field: 'ind_order', type: tools.FieldType.number },
{ field: 'col', type: tools.FieldType.number }]
{ field: 'riga', type: tools.FieldType.number },
{ field: 'col', type: tools.FieldType.number },
{ field: '_id', type: tools.FieldType.exact }]
};
NaveSchema.statics.executeQueryTable = function (idapp, params) {
@@ -365,7 +360,7 @@ NaveSchema.statics.findGeneric = function (myrigacol) {
myarr = { ...newrec._doc, ...rec[0]._doc };
return myarr;
} else {
let myarr = null;
let myarr = rec[0];
if (!!newrec) {
if (rec[0]._doc === undefined)
myarr = { ...newrec._doc, ...rec[0] };
@@ -426,6 +421,7 @@ function getQueryProj(myfilter) {
username: 1,
'profile.paymenttypes': 1,
'profile.email_paypal': 1,
'profile.cell': 1,
made_gift: 1,
sent_msg_howto_make_gift: 1,
date_made_gift: 1,
@@ -741,17 +737,19 @@ NaveSchema.statics.getNavePos = async function (idapp, riga, col, solorecord, in
if (indfuoco === 1)
primofuoco = recfuoco;
let symbol = '';
if (recfuoco.made_gift) {
symbol = '🎁';
donifatti++;
}
if (!!recfuoco && recmediatore) {
if (recfuoco.ind_order === recmediatore.ind_order && recfuoco.num_tess === 2) {
mystr += await getusertextbyrec(recfuoco, '', tools.get__('RITESSITURA', lang), miariga, miacol, '') + tools.ACAPO;
} else {
mystr += await getusertextbyrec(recfuoco, symbol, 'D', miariga, miacol, indfuoco) + tools.ACAPO;
donitotali++;
if (!!recfuoco) {
let symbol = '';
if (recfuoco.made_gift) {
symbol = '🎁';
donifatti++;
}
if (!!recfuoco && recmediatore) {
if (recfuoco.ind_order === recmediatore.ind_order && recfuoco.num_tess === 2) {
mystr += await getusertextbyrec(recfuoco, '', tools.get__('RITESSITURA', lang), miariga, miacol, '') + tools.ACAPO;
} else {
mystr += await getusertextbyrec(recfuoco, symbol, 'D', miariga, miacol, indfuoco) + tools.ACAPO;
donitotali++;
}
}
}
}
@@ -769,7 +767,7 @@ NaveSchema.statics.getNavePos = async function (idapp, riga, col, solorecord, in
// tools.gettranslate('PLACCA_TUTOR', lang)
if (!!recnavepersistente.tutor_namesurname)
data += '👤 ' + tools.get__('Tutor che affianchèra il Mediatore', lang) + ': "' + recnavepersistente.tutor_namesurname + '"' + tools.ACAPO;
data += '👤 ' + tools.get__('Tutor che affianchèra il Mediatore', lang) + ': "' + recnavepersistente.tutor_namesurname + '"' + tools.ACAPO;
data += '💬 ' + tools.get__('Giorno di Apertura GIFT CHAT', lang) + ': ' + tools.getstrDateLong(recnavepersistente.date_gift_chat_open) + tools.ACAPO;
@@ -852,7 +850,9 @@ NaveSchema.statics.showListaOrd = async function (idapp) {
for (const rec of arrrec) {
let recnavepersistente = await NavePersistente.findByRigaColByDonatore(idapp, rec.riga, rec.col, 0);
if (!!recnavepersistente) {
mystr += '[' + conta + '] [' + rec.riga + '.' + rec.col + '] ' + rec.ind_order + ' ' + rec.name + ' ' + rec.surname + ' (' + tools.getstrDateShort(recnavepersistente.date_start) + ')\n';
mystr += '[' + conta + '] [' + rec.riga + '.' + rec.col + '] ' + rec.ind_order + ' ' + rec.name + ' ' + rec.surname + ' (' + tools.getstrDateShort(recnavepersistente.date_start) + ')';
mystr += ' num_tess = ' + rec.num_tess;
mystr += '\n';
}
conta++;
}
@@ -911,9 +911,13 @@ async function addRecordNaveByParams(params, siRitesse) {
});
myNave.created = new Date();
console.log('[' + params.riga + ',' + params.col + ']');
// console.log('[' + params.riga + ',' + params.col + ']');
// console.log('parent = [' + params.rigaparent + ',' + params.colparent + ']');
const recfindparent = await Nave.findByRigaCol(idapp, params.rigaparent, params.colparent, false);
// console.log('recfindparent = [' + recfindparent + ']');
// console.table(recfindparent);
if (!!recfindparent) {
myNave.parent_id = recfindparent._id;
} else {
@@ -978,7 +982,7 @@ NaveSchema.statics.checkifDeveRitessersi = async function (recuser) {
arrrec = await Nave.find({ idapp: recuser.idapp, ind_order: recuser.ind_order });
if (!!arrrec) {
if (arrrec.length > 2) {
if ((arrrec.length % 2) === 0) {
// deveritessersi = await User.deveRitessersi(recuser.idapp, recuser.ind_order)
deveritessersi = false;
}
@@ -1006,6 +1010,9 @@ NaveSchema.statics.addUserFromListaIngresso_IntoNave = async function (init, ida
params.colparent = Math.ceil(params.col / 2);
params.rigaparent = params.riga - 1;
if (params.rigaparent === 0)
params.colparent = 0;
myriga = params.riga;
mycol = params.col;
@@ -1013,25 +1020,16 @@ NaveSchema.statics.addUserFromListaIngresso_IntoNave = async function (init, ida
if (inserito) {
if (idapp === tools.AYNI) {
if (((params.col) % 8) === 0) {
// Trova se la persona di 3 livelli sopra, si deve ritessere
let recmediatore = await Nave.findMediatoreByFuoco(idapp, myriga, mycol, 0);
if (!!recmediatore) {
const ris = await Nave.checkifDeveRitessersi(recmediatore);
if (ris.num_tess >= 2) {
console.log('E\' arrivato alla TERZA RITESSITURA, PERTANTO LO METTIAMO IN CODA... [riga=', params.riga, 'col', params.col, '] indorder=' + recmediatore.ind_order);
// E' arrivato alla TERZA RITESSITURA, PERTANTO LO METTIAMO IN CODA...
//++Todo: TESSITURA????
//const risultato = await ListaIngresso.addUserInListaIngresso(idapp, recmediatore.ind_order, rec.lang, false, ris.num_tess);
} else {
console.log('Si deve ritessere: [riga=', params.riga, 'col', params.col, ']');
if (ris.deveritessersi) {
console.log('Si deve ritesere: [riga=', params.riga, 'col', params.col, ']');
if (ris.deveritessersi) {
params.indprimario = recmediatore.indprimario;
params.ind_order = recmediatore.ind_order;
params.id = recmediatore._id;
params.num_tess = ris.num_tess;
params.num_tess = ris.num_tess + 1;
await addRecordNaveByParams(params, true);
}
@@ -1130,12 +1128,10 @@ NaveSchema.statics.checkIfDevoAggiungereInNave = async function (idapp) {
const { ListaIngresso } = require('./listaingresso');
// Ottieni la lista Ordinata in base al numero d'invitati
arrlista = await ListaIngresso.getProssimiInLista(idapp, false);
arrlista = await ListaIngresso.getProssimiInLista(idapp, true);
for (const rec of arrlista) {
if (rec.numinvitatiattivi >= 2) {
await addUserToNave(idapp, rec);
}
await addUserToNave(idapp, rec);
}
};
@@ -1157,7 +1153,7 @@ NaveSchema.statics.pulisciNonPresenzeInNave = async function (idapp) {
arrrec = await ListaIngresso.aggregate(myquery)
.then(async (arrlista) => {
for (const rec of arrlista) {
const trovato = await Nave.findByIndOrder(idapp, rec.ind_order);
const trovato = await Nave.findByIndOrderAndNumTess(idapp, rec.ind_order, rec.num_tess);
if (!trovato) {
let fields_to_update = { added: false };
await ListaIngresso.findOneAndUpdate({ _id: rec._id }, { $set: fields_to_update }, { new: false });
@@ -1171,6 +1167,31 @@ NaveSchema.statics.pulisciNonPresenzeInNave = async function (idapp) {
};
NaveSchema.statics.visuNaviUtentiEliminati = async function (idapp) {
const Nave = this;
let numrec = 0;
const myquery = getQueryProj({ idapp });
arrrec = await Nave.aggregate(myquery).sort({ riga: 1, col: 1 });
let mystr = 'ELIMINATI: \n';
let conta = 0;
for (const rec of arrrec) {
if (!rec.username) {
let navepersistente = await NavePersistente.findByRigaColByDonatore(idapp, rec.riga, rec.col, 0);
mystr += '[' + conta + '] [NAVI ' + navepersistente.riga + '.' + navepersistente.col + '] [' + rec.riga + '.' + rec.col + '] ' + rec.ind_order;
mystr += ' num_tess = ' + rec.num_tess;
mystr += '\n';
conta++;
}
}
return { mystr, num: conta };
};
NaveSchema.statics.getNaveByUser = async function (idapp, ind_order, lang, fuoco) {
const Nave = this;
@@ -1195,19 +1216,17 @@ NaveSchema.statics.getNaveByUser = async function (idapp, ind_order, lang, fuoco
return mystr;
};
NaveSchema.statics.getNaveByRigaCol = async function (idapp, riganave, colnave) {
NaveSchema.statics.getNaveByRigaCol = async function (idapp, rigapos, colpos) {
const Nave = this;
const rigaprec = riganave;
rec = {};
rec = await Nave.getPlaccaPerMediatore(idapp, riganave, colnave, true, rec);
rec = await Nave.getPlaccaPerMediatore(idapp, rigapos, colpos, true, rec);
if (riganave < 4) {
riganave = 4;
colnave = 1;
if (rigapos < 4) {
rigapos = 4;
colpos = 1;
}
rec = await Nave.getPlaccaPerDonatore(idapp, riganave, colnave, true, rec);
rec = await Nave.getPlaccaPerDonatore(idapp, rigapos, colpos, true, rec);
return rec;
};
@@ -1215,8 +1234,8 @@ NaveSchema.statics.getNaveByRigaCol = async function (idapp, riganave, colnave)
NaveSchema.statics.getDonatoridelSognatore = async function (idapp, riganave, colnave) {
const Nave = this;
coldonatoreIni = calcval(riganave, colnave, 8) + (1);
coldonatoreFine = calcval(riganave, colnave, 8) + (64);
coldonatoreIni = ((colnave - 1) * 64) + (1);
coldonatoreFine = coldonatoreIni + (64);
const myquery = getQueryProj({
idapp,

View File

@@ -77,6 +77,62 @@ const NavePersistenteSchema = new mongoose.Schema({
}
});
function getQueryProj(myfilter) {
myobjField = {
_id: 1,
idapp: 1,
lang: 1,
ind_order: 1,
name: 1,
surname: 1,
username: 1,
'profile.paymenttypes': 1,
'profile.email_paypal': 1,
'profile.cell': 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,
indprimario: 1,
parent_id: 1,
riga: 1,
col: 1,
created: 1,
// date_start: 1,
// date_gift_chat_open: 1,
// link_chat: 1,
// provvisoria: 1,
// note_bot: 1,
// note_interne: 1,
// tutor: 1,
// tutor_namesurname: 1,
};
const query = [
{ $match: myfilter },
{
$lookup: {
from: "users",
localField: "ind_order",
foreignField: "ind_order", // field in the user collection
as: "user"
}
},
{
$replaceRoot: { newRoot: { $mergeObjects: [{ $arrayElemAt: ["$user", 0] }, "$$ROOT"] } }
// $replaceRoot: { newRoot: { $mergeObjects: [{ $arrayElemAt: ["$user", 0] },] } }
},
{ $project: myobjField }
];
return query;
}
NavePersistenteSchema.statics.findById = function (idapp, id) {
const NavePersistente = this;

View File

@@ -267,6 +267,14 @@ UserSchema.statics.isManager = function (perm) {
}
};
UserSchema.statics.isTutor = function (perm) {
try {
return ((perm & shared_consts.Permissions.Tutor) === shared_consts.Permissions.Tutor);
} catch (e) {
return false
}
};
UserSchema.statics.findByToken = function (token, typeaccess) {
const User = this;
let decoded;
@@ -962,8 +970,8 @@ UserSchema.statics.getUsersListByParams = function (params) {
UserSchema.statics.getFieldsForSearch = function () {
return [{field: 'username', type: tools.FieldType.string},
{filed: 'name', type: tools.FieldType.string },
{filed: 'ind_order', type: tools.FieldType.number },
{field: 'name', type: tools.FieldType.string },
{field: 'ind_order', type: tools.FieldType.number },
{field: 'surname', type: tools.FieldType.string },
{field: 'email', type: tools.FieldType.string },
{field: 'profile.cell', type: tools.FieldType.string},
@@ -1029,7 +1037,7 @@ UserSchema.statics.getDashboard = async function (idapp, aportador_solidario, us
}
}
dashboard.arrnavi = await Nave.getArrPosizioniByIndOrder(idapp, dashboard.myself.ind_order);
dashboard.arrposizioni = await Nave.getArrPosizioniByIndOrder(idapp, dashboard.myself.ind_order);
dashboard.navi_partenza = await NavePersistente.getListaNavi(idapp);
@@ -1037,9 +1045,8 @@ UserSchema.statics.getDashboard = async function (idapp, aportador_solidario, us
// dashboard.navi_partenza.push(await Nave.getPrimaNaveByRiga(idapp, indriga));
//}
for (let mynave of dashboard.arrnavi) {
mynave._doc.rec = await Nave.getNaveByRigaCol(idapp, mynave.riga, mynave.col);
mynave._doc.listadonatoridelsognatore = await Nave.getDonatoridelSognatore(idapp, mynave.riga, mynave.col);
for (let mypos of dashboard.arrposizioni) {
mypos._doc.rec = await Nave.getNaveByRigaCol(idapp, mypos.riga, mypos.col);
}
// console.table(dashboard.arrnavi);