Aggiornamenti 2

This commit is contained in:
Paolo Arena
2020-05-04 19:34:41 +02:00
parent 2549d43447
commit 7d0538f7ae
29 changed files with 698 additions and 221 deletions

View File

@@ -25,9 +25,18 @@ const CalZoomSchema = new Schema({
typeconf: {
type: String,
},
icon: {
type: String,
},
color: {
type: String,
},
date_start: {
type: Date
},
benvenuto: {
type: Boolean
},
date_end: {
type: Date
},

View File

@@ -68,7 +68,7 @@ ListaIngressoSchema.statics.findByUsername = function (idapp, username) {
ListaIngressoSchema.statics.getTotInLista = async function (idapp) {
const ListaIngresso = this;
const myfind = { idapp };
const myfind = { idapp, added: false, deleted: false };
return await ListaIngresso.count(myfind);
};
@@ -100,6 +100,21 @@ ListaIngressoSchema.statics.findByIndOrderETess = function (idapp, ind_order, nu
}
};
ListaIngressoSchema.statics.findAllByIndOrder = function (idapp, ind_order) {
const ListaIngresso = this;
try {
return ListaIngresso.find({
'idapp': idapp,
'ind_order': ind_order,
added: false,
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
});
} catch (e) {
}
};
ListaIngressoSchema.statics.deleteUserInListaIngresso = async function (idapp, ind_order) {
const ListaIngresso = this;
@@ -131,8 +146,8 @@ ListaIngressoSchema.statics.addUserInListaIngresso = async function (idapp, ind_
return await listaingresso.save().then(async (ris) => {
if (addednowreal) {
if (!!ris) {
msgtext = tools.gettranslate('ADDED_TOLISTAINGRESSO', lang);
const username = await User.getUsernameByIndOrder(idapp, ind_order);
msgtext = '🔵 ' + username + ' ' + tools.gettranslate('ADDED_TOLISTAINGRESSO', lang);
await telegrambot.sendMsgTelegram(idapp, username, msgtext, true); // Anche a STAFF
}
}
@@ -153,7 +168,7 @@ ListaIngressoSchema.statics.addUserInListaIngresso = async function (idapp, ind_
return null;
} catch (e) {
console.error(e);
console.error(e.message);
}
return null;
};
@@ -180,6 +195,22 @@ function getQueryProj(myfilter, myobjField, myfilter2) {
return query;
}
ListaIngressoSchema.statics.getPosizioneInLista = async function (idapp, ind_order, num_tess) {
arrrec = await ListaIngresso.getProssimiInLista(idapp, true);
let posiz = 0;
let totposiz = arrrec.length;
for (let ind = 0; ind < arrrec.length; ind++) {
if (arrrec[ind].ind_order === ind_order && arrrec[ind].num_tess === num_tess) {
posiz = ind;
}
}
return { posiz: posiz + 1, totposiz, num_tess }
};
ListaIngressoSchema.statics.showListaOrd = async function (idapp, solonuovi) {
const ListaIngresso = this;
@@ -274,6 +305,18 @@ ListaIngressoSchema.statics.getProssimiInLista = async function (idapp, solonuov
for (const rec of arrlista) {
rec.numinvitati = await User.getnumInvitati(idapp, rec.username);
rec.numinvitatiattivi = await User.getnumInvitatiAttivi(idapp, rec.username);
if (rec.num_tess > 2) {
rec.numinvitati = rec.numinvitati - (rec.num_tess - 1);
rec.numinvitatiattivi = rec.numinvitatiattivi - (rec.num_tess - 1);
}
if (rec.numinvitati < 0) {
rec.numinvitati = 0;
}
if (rec.numinvitatiattivi < 0) {
rec.numinvitatiattivi = 0;
}
if (rec.numinvitatiattivi > 2)
rec.numinvitatiattivi = 2;
}
@@ -285,7 +328,7 @@ ListaIngressoSchema.statics.getProssimiInLista = async function (idapp, solonuov
return arrlista;
}).catch((e) => {
console.error(e);
console.error(e.message);
return null
});

View File

@@ -362,7 +362,7 @@ NaveSchema.statics.findGeneric = function (myrigacol) {
}
return null;
}).catch((e) => {
console.error(e);
console.error(e.message);
});
}
@@ -591,7 +591,7 @@ NaveSchema.statics.getPlaccaGenerica = async function (idapp, riga, col, offset,
}
} catch (e) {
console.error(e);
console.error(e.message);
}
};
@@ -755,9 +755,9 @@ 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 += '💬 ' + tools.get__('Giorno di Apertura GIFT CHAT', lang) + ': ' + tools.getstrDateLong(recnavepersistente.date_gift_chat_open) + tools.ACAPO;
data += '💬 ' + tools.get__('Giorno di Apertura GIFT CHAT', lang) + ': ' + tools.getstrDateLong(recnavepersistente.date_gift_chat_open, lang) + tools.ACAPO;
data += '🎁 ' + tools.get__('Giorno in cui Inviare il DONO', lang) + ' : ' + tools.getstrDateLong(recnavepersistente.date_start) + tools.ACAPO;
data += '🎁 ' + tools.get__('Giorno in cui Inviare il DONO', lang) + ' : ' + tools.getstrDateLong(recnavepersistente.date_start, lang) + tools.ACAPO;
if (!!recnavepersistente.note_bot)
data += tools.get__('Note', lang) + ": " + recnavepersistente.note_bot + tools.ACAPO;
@@ -771,7 +771,7 @@ NaveSchema.statics.getNavePos = async function (idapp, riga, col, solorecord, in
return mystr;
} catch (e) {
console.error(e);
console.error(e.message);
return '';
}
@@ -955,7 +955,7 @@ async function addRecordNaveByParams(params, siRitesse) {
return false;
}).catch((e) => {
console.error(e);
console.error(e.message);
});
}
@@ -964,7 +964,7 @@ NaveSchema.statics.checkifDeveRitessersi = async function (recuser) {
let deveritessersi = true;
arrrec = await Nave.find({ idapp: recuser.idapp, ind_order: recuser.ind_order });
arrrec = await Nave.find({ idapp: recuser.idapp, ind_order: recuser.ind_order, num_tess: recuser.num_tess });
if (!!arrrec) {
if ((arrrec.length % 2) === 0) {
@@ -1009,11 +1009,11 @@ NaveSchema.statics.addUserFromListaIngresso_IntoNave = async function (init, ida
if (!!recmediatore) {
const ris = await Nave.checkifDeveRitessersi(recmediatore);
if (ris.deveritessersi) {
console.log('Si deve ritesere: [riga=', params.riga, 'col', params.col, ']');
console.log('Si deve ritessere: [riga=', params.riga, 'col', params.col, ']');
if (ris.deveritessersi) {
params.ind_order = recmediatore.ind_order;
params.id = recmediatore._id;
params.num_tess = ris.num_tess + 1;
params.num_tess = recmediatore.num_tess + 1;
await addRecordNaveByParams(params, true);
}
@@ -1189,7 +1189,14 @@ NaveSchema.statics.getNaveByUser = async function (idapp, ind_order, lang, fuoco
};
tools.getRigaColByPosUp(mypos);
mystr += await Nave.getNavePos(idapp, mypos.riga, mypos.col, false, ind_order);
let persistente = await NavePersistente.findByRigaColByDonatore(idapp, pos.riga, pos.col, 0);
if (!!persistente) {
if (persistente.provvisoria) {
mystr += tools.ACAPO + tools.get__('NAVE', lang) + ' ' + '[' + mypos.riga + '.' + mypos.col + '] - ' + tools.get__('TEMPORANEA', lang) + tools.ACAPO+ tools.ACAPO;
} else {
mystr += await Nave.getNavePos(idapp, mypos.riga, mypos.col, false, ind_order);
}
}
// mystr += await Nave.getPlaccaPerDonatore(idapp, pos.riga, pos.col, false, rec);
// mystr += await Nave.getPlaccaPerMediatore(idapp, pos.riga, pos.col, false, rec);
}
@@ -1299,13 +1306,32 @@ NaveSchema.statics.ricalcolaNave = async function (idapp, nave, riga1don, col1do
nave._doc.rec = nave.rec;
}
}catch (e) {
} catch (e) {
console.error(e.message);
}
return nave;
}
};
NaveSchema.statics.getNextNumTess = async function (idapp, ind_order) {
const Nave = this;
const rec = await Nave.findOne({ idapp, ind_order }, { num_tess: 1 }).sort({ num_tess: -1 });
if (!!rec) {
if (rec.num_tess % 2 === 0) {
rec.num_tess++;
} else {
rec.num_tess += 2;
}
return rec.num_tess
} else {
return 1;
}
};
const Nave = mongoose.model('Nave', NaveSchema);

View File

@@ -183,6 +183,27 @@ NavePersistenteSchema.statics.getListaNavi = function (idapp) {
).sort({ riga: 1, col: 1 });
};
NavePersistenteSchema.statics.getLastNave = function (idapp) {
const NavePersistente = this;
const myfind = { idapp, date_start: { $lte: tools.IncDateNow(0) }, provvisoria: false };
return NavePersistente.findOne(myfind,
{
index: 1,
riga: 1,
col: 1,
riga1don: 1,
col1don: 1,
date_start: 1,
provvisoria: 1,
DoniConfermati: 1,
DoniTotali: 1,
DoniMancanti: 1,
}
).sort({ riga: -1, col: -1 }).limit(1);
};
NavePersistenteSchema.statics.findByRigaColByDonatore = function (idapp, riga, col, offset) {
const NavePersistente = this;

View File

@@ -279,6 +279,14 @@ UserSchema.statics.isManager = function (perm) {
}
};
UserSchema.statics.isTraduttrici = function (perm) {
try {
return ((perm & shared_consts.Permissions.Traduttrici) === shared_consts.Permissions.Traduttrici);
} catch (e) {
return false
}
};
UserSchema.statics.isTutor = function (perm) {
try {
return ((perm & shared_consts.Permissions.Tutor) === shared_consts.Permissions.Tutor);
@@ -324,10 +332,16 @@ UserSchema.statics.findByCredentials = function (idapp, username, password) {
const User = this;
let pwd = "";
return User.findOne({ idapp, username: username }).then((user) => {
return User.findOne({
idapp, username: username,
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }]
}).then((user) => {
if (!user) {
// Check if with email:
return User.findOne({ idapp, email: username.toLowerCase() })
return User.findOne({
idapp, email: username.toLowerCase(),
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }]
})
} else {
return !user.deleted ? user : null
}
@@ -361,6 +375,7 @@ UserSchema.statics.findByUsername = async function (idapp, username, alsoemail)
return await User.findOne({
'idapp': idapp,
'username': regexusername,
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
}).then(async (ris) => {
if ((!ris) && (alsoemail)) {
regexemail = new RegExp(["^", username.toLowerCase(), "$"].join(""), "i");
@@ -368,6 +383,7 @@ UserSchema.statics.findByUsername = async function (idapp, username, alsoemail)
return User.findOne({
'idapp': idapp,
'email': regexemail,
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
});
}
return ris;
@@ -380,6 +396,7 @@ UserSchema.statics.getUserShortDataByUsername = async function (idapp, username)
const myrec = await User.findOne({
'idapp': idapp,
'username': username,
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
}, {
lang: 1,
ind_order: 1,
@@ -427,6 +444,7 @@ UserSchema.statics.getDownlineByUsername = async function (idapp, username) {
const arrrec = await User.find({
'idapp': idapp,
'aportador_solidario': username,
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }]
}, {
lang: 1,
aportador_solidario: 1,
@@ -473,24 +491,38 @@ UserSchema.statics.getnumInvitatiAttivi = function (idapp, username) {
return User.countDocuments({
idapp,
aportador_solidario: username,
$or: [
$and: [
{
'profile.special_req': true
$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: [
{ "$expr": { "$gt": [{ "$strLenCP": "$profile.my_dream" }, 10] } },
{ "$expr": { "$gt": [{ "$strLenCP": "$profile.email_paypal" }, 6] } }
],
}]
});
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) {
@@ -502,23 +534,29 @@ UserSchema.statics.isUserQualified7 = async function (idapp, username) {
const myquery = {
'idapp': idapp,
'username': username,
$or: [
$and: [
{
'profile.special_req': true
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
},
{
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",
$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",
}]
}]
};
@@ -545,6 +583,7 @@ UserSchema.statics.getnumPaymentOk = function (idapp) {
return User.count({
idapp,
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
'profile.paymenttypes': { "$in": ['paypal'] },
$where: "this.profile.paymenttypes.length >= 1",
'profile.email_paypal': { $exists: true },
@@ -554,7 +593,7 @@ UserSchema.statics.getnumPaymentOk = function (idapp) {
UserSchema.statics.getUsersNationalityQuery = function (idapp) {
const query = [
{
$match: { idapp }
$match: { idapp, $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }], }
},
{
$group: { _id: "$profile.nationality", count: { $sum: 1 } }
@@ -583,6 +622,7 @@ UserSchema.statics.getnumInvitati = function (idapp, username) {
return User.count({
idapp,
aportador_solidario: username,
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
});
};
@@ -628,13 +668,17 @@ UserSchema.statics.findByEmail = function (idapp, email) {
return User.findOne({
'idapp': idapp,
'email': email,
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
});
};
UserSchema.statics.getLastUser = function (idapp) {
const User = this;
return User.findOne({ idapp }).sort({ ind_order: -1 })
return User.findOne({
idapp,
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
}).sort({ ind_order: -1 })
};
UserSchema.statics.findByIndOrder = function (idapp, ind_order) {
@@ -645,9 +689,10 @@ UserSchema.statics.findByIndOrder = function (idapp, ind_order) {
return User.findOne({
idapp,
ind_order,
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
});
} catch (e) {
console.error(e);
console.error(e.message);
}
};
@@ -684,7 +729,10 @@ UserSchema.methods.removeToken = function (token) {
UserSchema.statics.getEmailByUsername = async function (idapp, username) {
const User = this;
return await User.findOne({ idapp, username })
return await User.findOne({
idapp, username,
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }]
})
.then((arrrec) => {
return ((arrrec) ? arrrec.email : '');
}).catch((e) => {
@@ -695,7 +743,10 @@ UserSchema.statics.getEmailByUsername = async function (idapp, username) {
UserSchema.statics.getUsernameById = async function (idapp, id) {
const User = this;
return await User.findOne({ idapp, _id: id }, { username: 1 })
return await User.findOne({
idapp, _id: id,
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }]
}, { username: 1 })
.then((myuser) => {
return ((myuser) ? myuser.username : '');
}).catch((e) => {
@@ -706,19 +757,28 @@ UserSchema.statics.getUsernameById = async function (idapp, id) {
UserSchema.statics.getUserById = function (idapp, id) {
const User = this;
return User.findOne({ idapp, _id: id })
return User.findOne({
idapp, _id: id,
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }]
})
};
UserSchema.statics.getUserByAportador = function (idapp, aportador_solidario) {
const User = this;
return User.findOne({ idapp, aportador_solidario })
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;
return await User.findOne({ idapp, username })
return await User.findOne({
idapp, username,
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }]
})
.then((rec) => {
return ((rec) ? rec.aportador_solidario : '');
}).catch((e) => {
@@ -729,7 +789,10 @@ UserSchema.statics.getAportadorSolidarioByUsername = async function (idapp, user
UserSchema.statics.UserByIdTelegram = async function (idapp, teleg_id) {
const User = this;
return await User.findOne({ idapp, 'profile.teleg_id': teleg_id })
return await User.findOne({
idapp, 'profile.teleg_id': teleg_id,
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
})
.then((rec) => {
return (!!rec) ? rec._doc : null;
}).catch((e) => {
@@ -740,7 +803,10 @@ UserSchema.statics.UserByIdTelegram = async function (idapp, teleg_id) {
UserSchema.statics.UsersByIdTelegram = async function (idapp, teleg_id) {
const User = this;
return await User.find({ idapp, 'profile.teleg_id': teleg_id })
return await User.find({
idapp, 'profile.teleg_id': teleg_id,
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }]
})
.then((rec) => {
return (!!rec) ? rec._doc : null;
}).catch((e) => {
@@ -751,7 +817,10 @@ UserSchema.statics.UsersByIdTelegram = async function (idapp, teleg_id) {
UserSchema.statics.TelegIdByUsername = async function (idapp, username) {
const User = this;
return await User.findOne({ idapp, username }, { 'profile.teleg_id': 1 })
return await User.findOne({
idapp, username,
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }]
}, { 'profile.teleg_id': 1 })
.then((rec) => {
return (!!rec) ? rec.profile.teleg_id : null;
}).catch((e) => {
@@ -839,7 +908,10 @@ UserSchema.statics.SetTelegramWasBlocked = async function (idapp, teleg_id) {
UserSchema.statics.getNameSurnameByUsername = async function (idapp, username) {
const User = this;
return await User.findOne({ idapp, username }, { name: 1, surname: 1 })
return await User.findOne({
idapp, username,
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }]
}, { name: 1, surname: 1 })
.then((rec) => {
return (!!rec) ? `${rec.name} ${rec.surname}` : '';
}).catch((e) => {
@@ -850,7 +922,10 @@ 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 },
return await User.findOne({
idapp, ind_order,
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }]
},
{
idapp: 1,
ind_order: 1,
@@ -1005,7 +1080,10 @@ UserSchema.statics.executeQueryTable = function (idapp, params) {
UserSchema.statics.findAllIdApp = function (idapp) {
const User = this;
const myfind = { idapp };
const myfind = {
idapp,
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }]
};
return User.find(myfind, (err, arrrec) => {
return arrrec
@@ -1054,23 +1132,76 @@ UserSchema.statics.getDashboard = async function (idapp, aportador_solidario, us
}
}
dashboard.arrposizioni = await Nave.getArrPosizioniByIndOrder(idapp, dashboard.myself.ind_order);
if (!!dashboard.myself.ind_order)
dashboard.arrposizioni = await Nave.getArrPosizioniByIndOrder(idapp, dashboard.myself.ind_order);
else
dashboard.arrposizioni = [];
if (!!dashboard.myself.ind_order)
dashboard.arrimbarchi = await ListaIngresso.findAllByIndOrder(idapp, dashboard.myself.ind_order);
else
dashboard.arrimbarchi = [];
for (let myimbarco of dashboard.arrimbarchi) {
myimbarco._doc.posiz = await ListaIngresso.getPosizioneInLista(idapp, 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);
}
// console.table(dashboard.arrnavi);
const arrnew = [];
for (let mypos of dashboard.arrposizioni) {
// Controlla se è presente la Nave con il num_tess pari
let trovato = false;
if (mypos.num_tess % 2 !== 0) {
for (let myrec of dashboard.arrposizioni) {
if (myrec.num_tess === mypos.num_tess + 1) {
trovato = true
}
}
} 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);
}
}
}
dashboard.arrposizioni = [...dashboard.arrposizioni, ...arrnew];
// console.table(dashboard.arrnavi);
return dashboard;
} catch (e) {
console.error(e);
console.error(e.message);
return false;
}
};
@@ -1101,6 +1232,7 @@ UserSchema.statics.findByCellAndNameSurname = function (idapp, cell, name, surna
'profile.cell': cell,
'name': name,
'surname': surname,
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }]
});
};
@@ -1121,21 +1253,25 @@ UserSchema.statics.getUsersQualified = async function (idapp, numinvitati) {
const arrusers = await User.find({
idapp,
$or: [
$and: [
{ $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }] },
{
'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] } }
],
$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] } }
],
}]
}]
}, {
@@ -1164,21 +1300,25 @@ UserSchema.statics.visuUtentiNonInNavi = async function (idapp) {
const arrusers = await User.find({
idapp,
$or: [
$and: [
{ $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }] },
{
'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] } }
],
$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] } }
],
}]
}]
}, {
@@ -1202,24 +1342,60 @@ UserSchema.statics.visuUtentiNonInNavi = async function (idapp) {
let numnoinlista = 0;
let numeliminati = 0;
let numsospesi = 0;
let strnavidoppie = '';
let esiste = false;
for (const user of arrusers) {
if (user.deleted) {
numeliminati++;
} else {
esiste = true;
if (!!user.deleted) {
if (user.deleted) {
numeliminati++;
esiste = false;
}
}
if (esiste) {
let visualizza = false;
// Controlla se ho un doppione nelle Navi !
let mienavi = await Nave.find({ idapp, ind_order: user.ind_order }, { num_tess: 1 });
let strnavidoppie = [];
if (!!mienavi) {
strnavidoppie = mienavi.reduce((acc, currentValue, index, array) => {
if (array.indexOf(currentValue.num_tess) > -1 && !acc.includes(currentValue.num_tess))
acc.push(currentValue.num_tess);
return acc;
}, []);
}
if (strnavidoppie.length > 1) {
visualizza = true;
}
user.numinvitati = await User.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 });
let trovato = false;
if (!mianave) {
if (!mianave)
visualizza = true;
if (visualizza) {
mystr += user.username + ' ' + user.name + ' ' + user.surname + ' [' + user.ind_order + '] [inv=' + user.numinvitati + ']'
noninnave++;
trovato = true;
} else {
innave++;
}
if (strnavidoppie.length > 1) {
mystr += ' NAVI DUPLICATE! ' + strnavidoppie.join(',');
}
if (!mianave)
noninnave++;
else
innave++;
if (user.sospeso) {
numsospesi++;
}
@@ -1422,7 +1598,10 @@ UserSchema.statics.getUsersRegDaily = function (idapp, nrec) {
const query = [
{
$match: { idapp, date_reg: { $gte: tools.IncDateNow(-(1000 * 60 * 60 * 24 * nrec)) } }
$match: {
idapp, date_reg: { $gte: tools.IncDateNow(-(1000 * 60 * 60 * 24 * nrec)) },
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }]
}
},
{
$group: { _id: { $dateToString: { format: "%Y-%m-%d", date: "$date_reg" } }, count: { $sum: 1 } }
@@ -1434,12 +1613,35 @@ UserSchema.statics.getUsersRegDaily = function (idapp, nrec) {
return query
};
UserSchema.statics.getUsersRegWeekly = function (idapp, nrec) {
const query = [
{
$match: {
idapp, date_reg: { $gte: tools.IncDateNow(-(1000 * 60 * 60 * 24 * nrec)) },
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }]
}
},
{
$group: { _id: { $dateToString: { format: "%Y-%U", date: "$date_reg" } }, count: { $sum: 1 } }
},
{
$sort: { _id: 1 }
}
];
return query
};
UserSchema.statics.getnumRegNDays = function (idapp, nrec) {
const query = [
{
$match: { idapp, date_reg: { $lt: tools.IncDateNow(-(1000 * 60 * 60 * 24 * nrec)) } }
$match: {
idapp,
date_reg: { $lt: tools.IncDateNow(-(1000 * 60 * 60 * 24 * nrec)) },
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }]
}
},
{
$group: { _id: { $dateToString: { format: "%Y-%m-%d", date: "$date_reg" } }, count: { $sum: 1 } }
@@ -1471,6 +1673,16 @@ UserSchema.statics.calcRegDaily = async function (idapp) {
});
};
UserSchema.statics.calcRegWeekly = async function (idapp) {
const User = this;
return User.aggregate(User.getUsersRegWeekly(idapp, 20 * 7))
.then(ris => {
// console.table(ris);
return JSON.stringify(ris.slice(0, -1));
});
};
if (tools.INITDB_FIRSTIME) {
console.log(' createIndex User Index...');
@@ -1573,7 +1785,10 @@ UserSchema.statics.DbOp = async function (idapp, mydata) {
await ListaIngresso.deleteMany({ idapp, added: false });
arrusers = await User.find({ 'idapp': idapp }).sort({ ind_order: 1 });
arrusers = await User.find({
'idapp': idapp,
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }]
}).sort({ ind_order: 1 });
let num = 0;
num += await addUtentiInLista(idapp, 1, arrusers);
@@ -1588,7 +1803,7 @@ UserSchema.statics.DbOp = async function (idapp, mydata) {
}
} catch (e) {
console.error(e);
console.error(e.message);
}