Modifiche ultimate: Grafica Navi , Prenota un Altro Viaggio.

This commit is contained in:
Paolo Arena
2020-05-13 01:32:27 +02:00
parent c6acadb3e6
commit 2cb04f4f49
8 changed files with 142 additions and 72 deletions

View File

@@ -171,6 +171,12 @@ ListaIngressoSchema.statics.deleteUserInListaIngresso = async function (idapp, u
};
ListaIngressoSchema.statics.getNumDaImbarcare = async function (idapp) {
const ListaIngresso = this;
return await ListaIngresso.count({ idapp, added: false, deleted: false })
};
ListaIngressoSchema.statics.addUserInListaIngresso = async function (idapp, username, invitante_username, lang, addednowreal, nuovo, dateins, note, added, opt) {
const ListaIngresso = this;
@@ -212,8 +218,19 @@ ListaIngressoSchema.statics.addUserInListaIngresso = async function (idapp, user
if (addednowreal) {
if (!!ris) {
const nome = await User.getNameSurnameByUsername(idapp, username);
msgtext = '🔵 ' + nome + ' (' + username + ') ' + tools.gettranslate('ADDED_TOLISTAINGRESSO', lang);
await telegrambot.sendMsgTelegram(idapp, username, msgtext, true); // Anche a STAFF
const numimbarcare = await ListaIngresso.getNumDaImbarcare(idapp);
let msgtext = '🛳 ';
msgtext += nome + ' (' + username + ') ' + tools.gettranslate('ADDED_TOLISTAINGRESSO', lang);
await telegrambot.sendMsgTelegram(idapp, username, msgtext, false);
msgtext = '🛳 ';
if (nuovo) {
msgtext += '🌠 ';
}
const msgadd = msgtext + ' [' + numimbarcare + '] Imbarcare ' + nome + ' (' + username + ') ';
await telegrambot.sendMsgTelegramToTheManagers(idapp, msgadd, false); // Anche a STAFF
if (!!opt) {
if (!!opt.sendmsgtoinvitante) {
@@ -458,6 +475,22 @@ ListaIngressoSchema.statics.getProssimiInLista = async function (idapp, solonuov
return arrrec;
};
ListaIngressoSchema.statics.eliminaListeIngressoNascoste = async function (idapp) {
const ListaIngresso = this;
const { User } = require('./user');
const arrIngr = await ListaIngresso.find({ idapp, deleted: true });
for (const ingr of arrIngr) {
const user = await User.findOne({ idapp, old_order: ingr.ind_order });
if (!user) {
await ListaIngresso.deleteOne({ _id: ingr._id })
}
}
};
ListaIngressoSchema.statics.creaTessituraeConv = async function (idapp) {
const ListaIngresso = this;
@@ -501,6 +534,7 @@ ListaIngressoSchema.statics.creaTessituraeConv = async function (idapp) {
.then((mynave) => {
if (!!mynave) {
ingr.date_added = mynave.created;
ingr.deleted = false;
ingr.added = true;
}
return !!mynave;
@@ -580,7 +614,7 @@ ListaIngressoSchema.statics.creaTessituraeConv = async function (idapp) {
for (const myuser of arrIdTelegramUsers) {
// Crea 1 record listaingresso per ogni record aggiuntivo ! escludendo il primo!
if (teleg_id !== myuser.profile.teleg_id) {
if (teleg_id !== myuser.profile.teleg_id && myuser.old_order > 0) {
index = 0;
teleg_id = myuser.profile.teleg_id;
username = myuser.username;
@@ -605,7 +639,7 @@ ListaIngressoSchema.statics.creaTessituraeConv = async function (idapp) {
}
}, { new: false });
await Nave.updateMany({idapp, ind_order}, {
await Nave.updateMany({ idapp, ind_order }, {
$set: {
note: findlistaingresso.username,
}
@@ -666,17 +700,21 @@ ListaIngressoSchema.statics.getarray = async function (idapp, filtri, myobjField
};
ListaIngressoSchema.statics.getInvitati = async function (idapp, username, myobjField) {
ListaIngressoSchema.statics.getInvitati = async function (idapp, username, includemyself, myobjField) {
const ListaIngresso = this;
return ListaIngresso.getarray(idapp,
{
idapp,
deleted: false,
invitante_username: username,
username: { $ne: username },
},
myobjField);
let myq = {
idapp,
deleted: false,
invitante_username: username,
};
if (!includemyself) {
myq = { ...myq, username: { $ne: username } }
}
return ListaIngresso.getarray(idapp, myq, myobjField);
};
@@ -708,7 +746,7 @@ ListaIngressoSchema.statics.getnumInvitati = async function (idapp, username) {
idapp,
invitante_username: username,
deleted: false,
username: { $ne: username },
// username: { $ne: username },
}, { username: 1 });
const { User } = require('./user');
@@ -720,10 +758,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;
@@ -745,7 +783,7 @@ ListaIngressoSchema.statics.getnumInvitatiAttivi = async function (idapp, userna
let myquery = getQueryProj({
idapp,
invitante_username: username,
username: { $ne: username },
// username: { $ne: username },
deleted: false,
},
{ username: 1, ind_order: 1 },
@@ -764,10 +802,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

@@ -160,7 +160,7 @@ NaveSchema.statics.findById = function (idapp, id) {
} else {
return null;
}
}catch (e) {
} catch (e) {
console.error(e.message);
}
});
@@ -453,13 +453,13 @@ function getQueryProj(myfilter) {
}
},
{
$replaceRoot: { newRoot: { $mergeObjects: [ { $arrayElemAt: [ "$mylista", 0 ] }, "$$ROOT" ] } }
$replaceRoot: { newRoot: { $mergeObjects: [{ $arrayElemAt: ["$mylista", 0] }, "$$ROOT"] } }
},
{
$lookup: {
from: "users",
as: "user",
let: {username: '$username' },
let: { username: '$username' },
pipeline: [
{
$match: {
@@ -723,13 +723,22 @@ NaveSchema.statics.getNavePos = async function (idapp, riga, col, solorecord, in
let recnavepersistente = await NavePersistente.findByRigaCol(idapp, riga, col, 0);
mystr = '🌈' + tools.get__('SOGNATORE', lang) + ': ';
for (let indsogn = 0; indsogn < recsognatori.length; indsogn++) {
mystr += 'A' + (3 - indsogn) + await getusertextbyrec(recsognatori[indsogn], '', '', riga, col, '') + tools.ACAPO;
mystr = '7⃣° 🌈 <strong>' + tools.get__('SOGNATORE', lang) + ': ';
mystr += '' + await getusertextbyrec(recsognatori[0], '', '', riga, col, '') + '</strong>' + tools.ACAPO;
for (let indsogn = 1; indsogn < recsognatori.length; indsogn++) {
if (indsogn === 1)
mystr += '6⃣°';
else
mystr += '5⃣°';
mystr += ' ' + tools.get__('INTERMEDIO', lang) + ': ';
mystr += await getusertextbyrec(recsognatori[indsogn], '', '', riga, col, '') + tools.ACAPO;
}
mystr += tools.ACAPO + '🌀 ' + tools.get__('MEDIATORE', lang) + ':' + await getusertextbyrec(recmediatore, '', '', riga, col, '') + tools.ACAPO + tools.ACAPO;
mystr += tools.ACAPO + '4⃣° 🌀 ' + tools.get__('MEDIATORE', lang) + ':' + await getusertextbyrec(recmediatore, '', '', riga, col, '') + tools.ACAPO + tools.ACAPO;
mystr += '3⃣° ' + tools.get__('INTERMEDIO', lang) +':' + tools.ACAPO;
for (let indterra = 1; indterra <= 2; indterra++) {
miacol = calcval(riga, col, 2) + (indterra);
miariga = riga + 1;
@@ -739,6 +748,7 @@ NaveSchema.statics.getNavePos = async function (idapp, riga, col, solorecord, in
mystr += tools.ACAPO;
mystr += '2⃣° ' + tools.get__('INTERMEDIO', lang) + ':' + tools.ACAPO;
for (let indaria = 1; indaria <= 4; indaria++) {
miacol = calcval(riga, col, 4) + (indaria);
miariga = riga + 2;
@@ -750,7 +760,7 @@ NaveSchema.statics.getNavePos = async function (idapp, riga, col, solorecord, in
let primofuoco = null;
mystr += '🎁 ' + tools.get__('DONATORI', lang) + ':' + tools.ACAPO;
mystr += '1⃣° 🎁 ' + tools.get__('DONATORI', lang) + ':' + tools.ACAPO;
let donitotali = 0;
let donifatti = 0;
@@ -794,7 +804,7 @@ NaveSchema.statics.getNavePos = async function (idapp, riga, col, solorecord, in
if (!!recnavepersistente.tutor_namesurname)
data += '👤 ' + tools.get__('Tutor che affianchèra il Mediatore', lang) + ': "' + recnavepersistente.tutor_namesurname + '"' + tools.ACAPO;
data += '💬 ' + printf(tools.get__('APERTURA_CHIUSURA_GIFT_CHAT', lang), tools.getstrDateLong(recnavepersistente.date_gift_chat_open, lang), tools.getstrDateLong(recnavepersistente.date_start, lang)) + tools.ACAPO;
data += '💬 ' + printf(tools.get__('APERTURA_CHIUSURA_GIFT_CHAT', lang), tools.getstrDateLong(recnavepersistente.date_gift_chat_open, lang), tools.getstrDateLong(recnavepersistente.date_start, lang)) + tools.ACAPO;
// data += '💬 ' + tools.get__('Giorno di Apertura GIFT CHAT', lang) + ': ' + tools.getstrDateLong(recnavepersistente.date_gift_chat_open, lang) + tools.ACAPO;
@@ -1398,7 +1408,7 @@ NaveSchema.statics.getnumNaviByUsername = async function (idapp, username) {
// Get array di ind_order
const arrind_order = await ListaIngresso.find({ idapp, username }).distinct('ind_order');
const arrrec = await Nave.find({ idapp, ind_order: arrind_order, num_tess: { $mod: [ 2 , 1] } }, {
const arrrec = await Nave.find({ idapp, ind_order: arrind_order, num_tess: { $mod: [2, 1] } }, {
riga: 1,
col: 1,
ind_order: 1
@@ -1409,7 +1419,7 @@ NaveSchema.statics.getnumNaviByUsername = async function (idapp, username) {
else
return 0;
}catch (e) {
} catch (e) {
console.error(e.message);
}
};
@@ -1435,7 +1445,6 @@ NaveSchema.statics.getSognatoreByRigaColMediatore = async function (idapp, navem
};
const Nave = mongoose.model('Nave', NaveSchema);
module.exports = { Nave };

View File

@@ -445,12 +445,12 @@ UserSchema.statics.getUserShortDataByUsername = async function (idapp, username)
return myrec
};
UserSchema.statics.getDownlineByUsername = async function (idapp, username) {
UserSchema.statics.getDownlineByUsername = async function (idapp, username, includemyself) {
if (username === undefined)
return null;
const arrrec = await ListaIngresso.getInvitati(idapp, username,
const arrrec = await ListaIngresso.getInvitati(idapp, username, includemyself,
{
index: 1,
lang: 1,
@@ -474,12 +474,18 @@ UserSchema.statics.getDownlineByUsername = async function (idapp, username) {
}
);
// Ottieni gli invitati che ancora non hanno un'imbarco
const arrinv = await User.find({
let myq = {
idapp,
aportador_solidario: username,
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }]
});
};
if (!includemyself) {
myq = { ...myq, username: {$ne: username} }
}
// Ottieni gli invitati che ancora non hanno un'imbarco
const arrinv = await User.find(myq);
for (const inv of arrinv) {
if (!arrrec.find((rec) => rec.username === inv.username))
@@ -1153,16 +1159,16 @@ UserSchema.statics.getDashboard = async function (idapp, aportador_solidario, us
if (!!arrap)
dashboard.numpeople_aportador = arrap.length;
dashboard.downline = await User.getDownlineByUsername(idapp, username);
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);
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);
dashboard.downbyuser[down2.username] = await User.getDownlineByUsername(idapp, down2.username, false);
}
}