SubAccounts
This commit is contained in:
@@ -170,46 +170,47 @@ ExtraListSchema.statics.getUsersList = function (idapp) {
|
||||
|
||||
};
|
||||
|
||||
ExtraListSchema.statics.getDownlineNotRegisteredByNameSurname = function (idapp, nameandsurname) {
|
||||
const ExtraList = this;
|
||||
|
||||
return ExtraList.find({
|
||||
'aportador_solidario_name_surname': nameandsurname,
|
||||
registered: false,
|
||||
}, {
|
||||
ind_order: 1,
|
||||
name: 1,
|
||||
surname: 1,
|
||||
cell_complete: 1,
|
||||
num_invitati: 1,
|
||||
nationality: 1,
|
||||
}, (err, arrrec) => {
|
||||
return arrrec
|
||||
});
|
||||
};
|
||||
|
||||
ExtraListSchema.statics.getUserNotRegisteredByNameSurname = function (idapp, nameandsurname) {
|
||||
const ExtraList = this;
|
||||
|
||||
return ExtraList.findOne({
|
||||
name_complete: nameandsurname,
|
||||
registered: false,
|
||||
}, {
|
||||
lang: 1,
|
||||
ind_order: 1,
|
||||
name: 1,
|
||||
surname: 1,
|
||||
cell_complete: 1,
|
||||
num_invitati: 1,
|
||||
nationality: 1,
|
||||
}, (err, arrrec) => {
|
||||
return arrrec
|
||||
});
|
||||
};
|
||||
// ExtraListSchema.statics.getDownlineNotRegisteredByNameSurname = function (idapp, nameandsurname) {
|
||||
// const ExtraList = this;
|
||||
//
|
||||
// return ExtraList.find({
|
||||
// 'aportador_solidario_name_surname': nameandsurname,
|
||||
// registered: false,
|
||||
// }, {
|
||||
// ind_order: 1,
|
||||
// name: 1,
|
||||
// surname: 1,
|
||||
// cell_complete: 1,
|
||||
// num_invitati: 1,
|
||||
// nationality: 1,
|
||||
// }, (err, arrrec) => {
|
||||
// return arrrec
|
||||
// });
|
||||
// };
|
||||
|
||||
// ExtraListSchema.statics.getUserNotRegisteredByNameSurname = function (idapp, nameandsurname) {
|
||||
// const ExtraList = this;
|
||||
//
|
||||
// return ExtraList.findOne({
|
||||
// name_complete: nameandsurname,
|
||||
// registered: false,
|
||||
// }, {
|
||||
// lang: 1,
|
||||
// ind_order: 1,
|
||||
// name: 1,
|
||||
// surname: 1,
|
||||
// cell_complete: 1,
|
||||
// num_invitati: 1,
|
||||
// nationality: 1,
|
||||
// }, (err, arrrec) => {
|
||||
// return arrrec
|
||||
// });
|
||||
// };
|
||||
//
|
||||
|
||||
ExtraListSchema.statics.getFieldsForSearch = function () {
|
||||
return [{ field: 'username', type: tools.FieldType.string },
|
||||
return [
|
||||
{ field: 'username', type: tools.FieldType.string },
|
||||
{ field: 'name', type: tools.FieldType.string },
|
||||
{ field: 'surname', type: tools.FieldType.string },
|
||||
{ field: 'cell_complete', type: tools.FieldType.string },
|
||||
@@ -239,6 +240,7 @@ ExtraListSchema.statics.DuplicateAllRecords = async function (idapporig, idappde
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
ExtraListSchema.statics.ImportData = async function (locale, idapp, strdata) {
|
||||
|
||||
const ExtraList = this;
|
||||
@@ -325,6 +327,7 @@ ExtraListSchema.statics.ImportData = async function (locale, idapp, strdata) {
|
||||
console.err(e);
|
||||
}
|
||||
};
|
||||
*/
|
||||
|
||||
|
||||
const ExtraList = mongoose.model('ExtraList', ExtraListSchema);
|
||||
|
||||
@@ -10,7 +10,6 @@ const { ObjectID } = require('mongodb');
|
||||
|
||||
const { Nave } = require('./nave');
|
||||
|
||||
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
const queryclass = require('../classes/queryclass');
|
||||
|
||||
@@ -29,9 +28,18 @@ const ListaIngressoSchema = new mongoose.Schema({
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
username: {
|
||||
type: String,
|
||||
},
|
||||
ind_order: {
|
||||
type: Number,
|
||||
},
|
||||
index: {
|
||||
type: Number,
|
||||
},
|
||||
invitante_username: {
|
||||
type: String,
|
||||
},
|
||||
date_added: {
|
||||
type: Date,
|
||||
},
|
||||
@@ -42,6 +50,9 @@ const ListaIngressoSchema = new mongoose.Schema({
|
||||
num_tess: {
|
||||
type: Number,
|
||||
},
|
||||
note: {
|
||||
type: String,
|
||||
},
|
||||
deleted: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
@@ -49,6 +60,27 @@ const ListaIngressoSchema = new mongoose.Schema({
|
||||
|
||||
});
|
||||
|
||||
ListaIngressoSchema.pre('save', async function (next) {
|
||||
if (this.isNew) {
|
||||
try {
|
||||
if (!this.ind_order) {
|
||||
const myrec = await ListaIngresso.findOne({ idapp: this.idapp }).limit(1).sort({ ind_order: -1 });
|
||||
|
||||
if (!!myrec) {
|
||||
this.ind_order = myrec._doc.ind_order + 1;
|
||||
} else {
|
||||
this.ind_order = 1;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
this.ind_order = 2;
|
||||
}
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
|
||||
|
||||
// ListaIngressoSchema.methods.toJSON = function () {
|
||||
// const ListaIngresso = this;
|
||||
// const userObject = ListaIngresso.toObject();
|
||||
@@ -86,13 +118,27 @@ ListaIngressoSchema.statics.findByIndOrder = function (idapp, ind_order) {
|
||||
}
|
||||
};
|
||||
|
||||
ListaIngressoSchema.statics.findByIndOrderETess = function (idapp, ind_order, num_tess) {
|
||||
ListaIngressoSchema.statics.findByAllRecByUsername = function (idapp, username) {
|
||||
const ListaIngresso = this;
|
||||
|
||||
try {
|
||||
return ListaIngresso.findOne({
|
||||
'idapp': idapp,
|
||||
'ind_order': ind_order,
|
||||
return ListaIngresso.find({
|
||||
idapp,
|
||||
username,
|
||||
deleted: false
|
||||
});
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
ListaIngressoSchema.statics.findByUsernameETess = async function (idapp, username, num_tess) {
|
||||
const ListaIngresso = this;
|
||||
|
||||
try {
|
||||
return await ListaIngresso.findOne({
|
||||
idapp,
|
||||
username,
|
||||
num_tess,
|
||||
});
|
||||
} catch (e) {
|
||||
@@ -100,67 +146,87 @@ ListaIngressoSchema.statics.findByIndOrderETess = function (idapp, ind_order, nu
|
||||
}
|
||||
};
|
||||
|
||||
ListaIngressoSchema.statics.findAllByIndOrder = function (idapp, ind_order) {
|
||||
ListaIngressoSchema.statics.findAllByUsername = function (idapp, username) {
|
||||
const ListaIngresso = this;
|
||||
|
||||
try {
|
||||
return ListaIngresso.find({
|
||||
'idapp': idapp,
|
||||
'ind_order': ind_order,
|
||||
added: false,
|
||||
username,
|
||||
added: false, // NON QUELLI GIA INSERITI !
|
||||
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
|
||||
});
|
||||
} catch (e) {
|
||||
|
||||
console.error(e.message);
|
||||
}
|
||||
};
|
||||
|
||||
ListaIngressoSchema.statics.deleteUserInListaIngresso = async function (idapp, ind_order) {
|
||||
ListaIngressoSchema.statics.deleteUserInListaIngresso = async function (idapp, username) {
|
||||
const ListaIngresso = this;
|
||||
|
||||
return ListaIngresso.findOneAndUpdate({
|
||||
return ListaIngresso.updateMany({
|
||||
idapp,
|
||||
ind_order,
|
||||
username,
|
||||
}, { $set: { deleted: true } }, { new: false })
|
||||
|
||||
};
|
||||
|
||||
ListaIngressoSchema.statics.addUserInListaIngresso = async function (idapp, ind_order, lang, addednowreal, num_tess) {
|
||||
ListaIngressoSchema.statics.addUserInListaIngresso = async function (idapp, username, invitante_username, lang, addednowreal, nuovo, dateins, note, added) {
|
||||
const ListaIngresso = this;
|
||||
|
||||
const { User } = require('./user');
|
||||
const telegrambot = require('../telegram/telegrambot');
|
||||
|
||||
try {
|
||||
let listaingresso = await ListaIngresso.findByIndOrderETess(idapp, ind_order, num_tess);
|
||||
let listaingresso = null;
|
||||
if (!nuovo) {
|
||||
listaingresso = await ListaIngresso.findByUsernameETess(idapp, username, 1);
|
||||
}
|
||||
if (!listaingresso) {
|
||||
listaingresso = new ListaIngresso({
|
||||
ind_order: ind_order,
|
||||
_id: new ObjectID(),
|
||||
idapp,
|
||||
num_tess,
|
||||
username,
|
||||
num_tess: 1,
|
||||
date_added: new Date(),
|
||||
_id: new ObjectID()
|
||||
invitante_username,
|
||||
});
|
||||
|
||||
if (!!note) {
|
||||
listaingresso.note = note;
|
||||
}
|
||||
if (!!added) {
|
||||
listaingresso.added = added;
|
||||
}
|
||||
|
||||
if (!!dateins) {
|
||||
try {
|
||||
listaingresso.date_added = dateins;
|
||||
} catch (e) {
|
||||
listaingresso.date_added = new Date();
|
||||
}
|
||||
}
|
||||
|
||||
if (listaingresso) {
|
||||
return await listaingresso.save().then(async (ris) => {
|
||||
if (addednowreal) {
|
||||
if (!!ris) {
|
||||
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
|
||||
}
|
||||
const ris = await listaingresso.save();
|
||||
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
|
||||
}
|
||||
return ris;
|
||||
});
|
||||
}
|
||||
return ris;
|
||||
}
|
||||
}
|
||||
|
||||
const giapresente = await Nave.findOne({ idapp, ind_order, num_tess });
|
||||
const giapresente = await
|
||||
Nave.findOne({ idapp, ind_order, num_tess: 1 });
|
||||
if (!!giapresente) {
|
||||
// Era stato già aggiunto!
|
||||
let fields_to_update = { added: true };
|
||||
await ListaIngresso.findOneAndUpdate({ _id: listaingresso._id }, { $set: fields_to_update }, { new: false });
|
||||
await
|
||||
ListaIngresso.findOneAndUpdate({ _id: listaingresso._id }, { $set: fields_to_update }, { new: false });
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -171,44 +237,69 @@ ListaIngressoSchema.statics.addUserInListaIngresso = async function (idapp, ind_
|
||||
console.error(e.message);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
function getQueryProj(myfilter, myobjField, myfilter2) {
|
||||
function getQueryProj(myfilter, myobjField, myfilter2, mygroup) {
|
||||
const query = [
|
||||
{ $match: myfilter },
|
||||
{
|
||||
$lookup: {
|
||||
from: "users",
|
||||
localField: "ind_order",
|
||||
foreignField: "ind_order", // field in the user collection
|
||||
as: "user"
|
||||
as: "user",
|
||||
let: { username: '$username' },
|
||||
pipeline: [
|
||||
{
|
||||
$match: {
|
||||
$expr: {
|
||||
$and: [
|
||||
{ $eq: ['$username', '$$username'] },
|
||||
{ $eq: ['$idapp', myfilter.idapp] },
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
$replaceRoot: { newRoot: { $mergeObjects: [{ $arrayElemAt: ["$user", 0] }, "$$ROOT"] } }
|
||||
},
|
||||
{ $match: myfilter2 },
|
||||
{ $project: myobjField }
|
||||
];
|
||||
|
||||
if (!!mygroup) {
|
||||
query.push(
|
||||
{ $group: mygroup }
|
||||
);
|
||||
}
|
||||
|
||||
if (!!myobjField) {
|
||||
query.push(
|
||||
{ $project: myobjField }
|
||||
);
|
||||
}
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
ListaIngressoSchema.statics.getPosizioneInLista = async function (idapp, ind_order, num_tess) {
|
||||
ListaIngressoSchema.statics.getPosizioneInLista = async function (idapp, arrrec, ind_order, num_tess) {
|
||||
|
||||
arrrec = await ListaIngresso.getProssimiInLista(idapp, true);
|
||||
|
||||
let posiz = 0;
|
||||
let totposiz = arrrec.length;
|
||||
let numNaviEntrato = 0;
|
||||
|
||||
for (let ind = 0; ind < arrrec.length; ind++) {
|
||||
if (arrrec[ind].ind_order === ind_order && arrrec[ind].num_tess === num_tess) {
|
||||
posiz = ind;
|
||||
numNaviEntrato = arrrec[ind].numNaviEntrato;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return { posiz: posiz + 1, totposiz, num_tess }
|
||||
return { posiz: posiz + 1, totposiz, num_tess, numNaviEntrato }
|
||||
|
||||
};
|
||||
|
||||
@@ -220,7 +311,8 @@ ListaIngressoSchema.statics.showListaOrd = async function (idapp, solonuovi) {
|
||||
let mystr = '';
|
||||
let conta = 1;
|
||||
for (const rec of arrrec) {
|
||||
mystr += '[' + conta + '] ' + rec.ind_order + ' [' + rec.numinvitatiattivi + '] - [' + rec.numinvitati + '] (' + rec.ind_order + ') ' + rec.name + ' ' + rec.surname;
|
||||
mystr += conta + ' - ' + ' [' + rec.numinvitatiattivi + '] - [' + rec.numinvitati + '] (' + rec.ind_order + ') ' + rec.username + ' ' + rec.name + ' ' + rec.surname;
|
||||
mystr += ' inv = ' + rec.invitante_username;
|
||||
mystr += ' num_tess = ' + rec.num_tess;
|
||||
if (rec.added)
|
||||
mystr += ' (ADDED ++)';
|
||||
@@ -234,7 +326,11 @@ ListaIngressoSchema.statics.showListaOrd = async function (idapp, solonuovi) {
|
||||
|
||||
|
||||
ListaIngressoSchema.statics.getFieldsForSearch = function () {
|
||||
return [{field: 'ind_order', type: tools.FieldType.number }]
|
||||
return [
|
||||
{ field: 'ind_order', type: tools.FieldType.number },
|
||||
{ field: 'username', type: tools.FieldType.string },
|
||||
{ field: 'invitante_username', type: tools.FieldType.string },
|
||||
]
|
||||
};
|
||||
|
||||
ListaIngressoSchema.statics.executeQueryTable = function (idapp, params) {
|
||||
@@ -269,6 +365,7 @@ ListaIngressoSchema.statics.getProssimiInLista = async function (idapp, solonuov
|
||||
name: 1,
|
||||
surname: 1,
|
||||
username: 1,
|
||||
invitante_username: 1,
|
||||
email: 1,
|
||||
lang: 1,
|
||||
num_tess: 1,
|
||||
@@ -278,7 +375,7 @@ ListaIngressoSchema.statics.getProssimiInLista = async function (idapp, solonuov
|
||||
};
|
||||
|
||||
let myfilter2 = {
|
||||
username: { $exists: true },
|
||||
surname: { $exists: true },
|
||||
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
|
||||
};
|
||||
|
||||
@@ -297,19 +394,36 @@ ListaIngressoSchema.statics.getProssimiInLista = async function (idapp, solonuov
|
||||
}, myobjField, myfilter2);
|
||||
}
|
||||
|
||||
arrrec = await ListaIngresso.aggregate(myquery).sort({ ind_order: 1 })
|
||||
// await ListaIngresso.aggiornaIndex();
|
||||
|
||||
arrrec = await ListaIngresso.aggregate(myquery).sort({ date_added: 1 })
|
||||
.then(async (arrlista) => {
|
||||
|
||||
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);
|
||||
const arrindex = {};
|
||||
|
||||
if (rec.num_tess > 2) {
|
||||
rec.numinvitati = rec.numinvitati - (rec.num_tess - 1);
|
||||
rec.numinvitatiattivi = rec.numinvitatiattivi - (rec.num_tess - 1);
|
||||
for (const rec of arrlista) {
|
||||
|
||||
// ++Todo: TOGLIERE!
|
||||
if (false) {
|
||||
rec.numNaviEntrato = await Nave.getnumNaviByUsername(idapp, rec.username);
|
||||
|
||||
rec.numinvitati = await ListaIngresso.getnumInvitati(idapp, rec.username);
|
||||
rec.numinvitatiattivi = await ListaIngresso.getnumInvitatiAttivi(idapp, rec.username);
|
||||
}
|
||||
|
||||
const arrListaIngrUser = arrindex[rec.username];
|
||||
if (!arrListaIngrUser) {
|
||||
arrindex[rec.username] = 1 + rec.numNaviEntrato;
|
||||
} else {
|
||||
arrindex[rec.username] += 1; // incrementa
|
||||
}
|
||||
|
||||
// if (rec.num_tess > 2) {
|
||||
rec.numinvitati = rec.numinvitati - (arrindex[rec.username] - 1) * 2;
|
||||
rec.numinvitatiattivi = rec.numinvitatiattivi - (arrindex[rec.username] - 1) * 2;
|
||||
// }
|
||||
if (rec.numinvitati < 0) {
|
||||
rec.numinvitati = 0;
|
||||
}
|
||||
@@ -335,6 +449,337 @@ ListaIngressoSchema.statics.getProssimiInLista = async function (idapp, solonuov
|
||||
return arrrec;
|
||||
};
|
||||
|
||||
ListaIngressoSchema.statics.creaTessituraeConv = async function (idapp) {
|
||||
const ListaIngresso = this;
|
||||
|
||||
const { User } = require('./user');
|
||||
|
||||
try {
|
||||
if (true) {
|
||||
// Elimina TUTTI i Cancellati (ma non Sospesi)
|
||||
await User.remove({
|
||||
idapp,
|
||||
$and: [
|
||||
{ deleted: { $exists: true, $eq: true } }, // cancellati
|
||||
{ $or: [{ sospeso: { $exists: false } }, { sospeso: { $exists: true, $eq: false } }] }, // ma non sospeso
|
||||
]
|
||||
});
|
||||
|
||||
|
||||
// Comprende anche i sospesi
|
||||
const arrusers = await User.find({
|
||||
idapp,
|
||||
});
|
||||
|
||||
// Ricalcola il Campo Index
|
||||
await User.ricalcolaIndex(idapp);
|
||||
|
||||
// Ricrea i record ListaIngresso (num_tess = 1), per ogni User
|
||||
for (const user of arrusers) {
|
||||
if (user.ind_order >= 0) {
|
||||
let ingr = new ListaIngresso();
|
||||
ingr._id = new ObjectID();
|
||||
ingr.idapp = idapp;
|
||||
ingr.ind_order = user.ind_order;
|
||||
ingr.username = user.username;
|
||||
ingr.invitante_username = user.aportador_solidario;
|
||||
ingr.num_tess = 1;
|
||||
// ingr.date_added = user.date_reg;
|
||||
ingr.added = false;
|
||||
const listaingr = await ListaIngresso.find({ idapp, ind_order: ingr.ind_order, num_tess: 1 });
|
||||
|
||||
const trovatanave = await Nave.findOne({ idapp, ind_order: ingr.ind_order, num_tess: 1 })
|
||||
.then((mynave) => {
|
||||
if (!!mynave) {
|
||||
ingr.date_added = mynave.created;
|
||||
ingr.added = true;
|
||||
}
|
||||
return !!mynave;
|
||||
});
|
||||
|
||||
if (listaingr.length === 0) {
|
||||
if (trovatanave)
|
||||
await ingr.save();
|
||||
else {
|
||||
// non ha ancora i 7 requisiti
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
const listaingr2 = await ListaIngresso.find({ idapp, ind_order: ingr.ind_order });
|
||||
|
||||
for (const ingr2 of listaingr2) {
|
||||
|
||||
const ris = await ListaIngresso.findByIdAndUpdate(ingr2._id, {
|
||||
$set: {
|
||||
username: ingr.username,
|
||||
invitante_username: ingr.invitante_username
|
||||
}
|
||||
}, { new: false });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// cancella in user i campi che non uso più
|
||||
await User.findByIdAndUpdate(user.id, {
|
||||
$set: {
|
||||
old_order: user.ind_order,
|
||||
ind_order: -1,
|
||||
// aportador_solidario: ''
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Comprende anche i sospesi
|
||||
const arrIdTelegramUsers = await User.find({ idapp, 'profile.teleg_id': { $gt: 1 } },
|
||||
{ _id: 1, username: 1, aportador_solidario: 1, old_order: 1, lang: 1, date_reg: 1, 'profile.teleg_id': 1 })
|
||||
.sort({
|
||||
'profile.teleg_id': 1,
|
||||
old_order: 1
|
||||
});
|
||||
|
||||
|
||||
// Crea altri ListaIngresso per gli utenti con i sottoaccount:
|
||||
/*
|
||||
const arrIdTelegramUsers = [];
|
||||
const arrusersAlreadyExist = [];
|
||||
for (const user of arrusers) {
|
||||
if (!!user.profile.teleg_id) {
|
||||
const trovati = arrusersAlreadyExist.find((rec) => rec.teleg_id === user.profile.teleg_id);
|
||||
if (trovati) {
|
||||
// era già presente, quindi lo aggiungo !
|
||||
const trovatoidteleg = arrIdTelegramUsers.find((rec) => rec.teleg_id === user.profile.teleg_id);
|
||||
if (!trovatoidteleg)
|
||||
arrIdTelegramUsers.push({ teleg_id: user.profile.teleg_id, username: user.username });
|
||||
} else {
|
||||
arrusersAlreadyExist.push({ teleg_id: user.profile.teleg_id, username: user.username });
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
let index = 0;
|
||||
|
||||
let teleg_id = 0;
|
||||
let username = '';
|
||||
let invitante_username = '';
|
||||
let invitante_degli_invitati = '';
|
||||
|
||||
// Questi sono Utenti che hanno associato Telegram a più Account !
|
||||
for (const myuser of arrIdTelegramUsers) {
|
||||
|
||||
// Crea 1 record listaingresso per ogni record aggiuntivo ! escludendo il primo!
|
||||
if (teleg_id !== myuser.profile.teleg_id) {
|
||||
index = 0;
|
||||
teleg_id = myuser.profile.teleg_id;
|
||||
username = myuser.username;
|
||||
invitante_username = myuser.aportador_solidario;
|
||||
invitante_degli_invitati = myuser.username;
|
||||
}
|
||||
|
||||
if (index > 0) {
|
||||
// Ind_order to find !
|
||||
const ind_order = myuser.old_order;
|
||||
//const findnave = await Nave.find({ idapp, ind_order: myuser.old_order, num_tess: 1 });
|
||||
|
||||
if (ind_order >= 0) {
|
||||
const findlistaingresso = await ListaIngresso.findOne({ idapp, ind_order, num_tess: 1 });
|
||||
|
||||
if (!!findlistaingresso) {
|
||||
await ListaIngresso.findByIdAndUpdate(findlistaingresso._id, {
|
||||
$set: {
|
||||
username,
|
||||
invitante_username,
|
||||
note: findlistaingresso.username,
|
||||
}
|
||||
}, { new: false });
|
||||
|
||||
await Nave.updateMany({idapp, ind_order}, {
|
||||
$set: {
|
||||
note: findlistaingresso.username,
|
||||
}
|
||||
}, { new: false });
|
||||
|
||||
|
||||
// Crea Record ListaIngresso
|
||||
// const newrecingr = await ListaIngresso.addUserInListaIngresso(idapp, myuser.username, invitante_username, myuser.lang, false, true, myuser.date_reg, note, added);
|
||||
|
||||
// Assegna l'Invitante agli Invitati ! trova tutti gli invitati che hanno questo username
|
||||
const arrinvitati = await User.find({ idapp, aportador_solidario: myuser.username }, { username: 1 });
|
||||
for (const invitato of arrinvitati) {
|
||||
await User.changeInvitante(idapp, invitato.username, invitante_degli_invitati, ind_order)
|
||||
}
|
||||
|
||||
// poi imposta come cancellato questo record
|
||||
await User.findByIdAndUpdate(myuser._id, { $set: { deleted: true } });
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
index++;
|
||||
}
|
||||
|
||||
return index;
|
||||
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
ListaIngressoSchema.statics.getListaTessByUsername = function (idapp, username) {
|
||||
const ListaIngresso = this;
|
||||
|
||||
return ListaIngresso.find({
|
||||
idapp,
|
||||
username,
|
||||
// added: true,
|
||||
deleted: false,
|
||||
});
|
||||
|
||||
|
||||
};
|
||||
|
||||
ListaIngressoSchema.statics.getarray = async function (idapp, filtri, myobjField) {
|
||||
const ListaIngresso = this;
|
||||
|
||||
let myfilter2 = {
|
||||
surname: { $exists: true },
|
||||
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
|
||||
};
|
||||
|
||||
let myquery = getQueryProj(
|
||||
filtri,
|
||||
myobjField,
|
||||
myfilter2
|
||||
);
|
||||
|
||||
return await ListaIngresso.aggregate(myquery);
|
||||
|
||||
};
|
||||
|
||||
|
||||
ListaIngressoSchema.statics.getInvitati = async function (idapp, username, myobjField) {
|
||||
const ListaIngresso = this;
|
||||
|
||||
return ListaIngresso.getarray(idapp,
|
||||
{
|
||||
idapp,
|
||||
deleted: false,
|
||||
invitante_username: username,
|
||||
username: { $ne: username },
|
||||
},
|
||||
myobjField);
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
ListaIngressoSchema.statics.getUserByInvitante_Username = async function (idapp, invitante_username) {
|
||||
const ListaIngresso = this;
|
||||
|
||||
const arr = ListaIngresso.getarray(idapp,
|
||||
{
|
||||
idapp,
|
||||
deleted: false,
|
||||
invitante_username: invitante_username,
|
||||
username: { $ne: {invitante_username} },
|
||||
},
|
||||
null);
|
||||
|
||||
if (!!arr)
|
||||
return arr[0];
|
||||
else
|
||||
return null;
|
||||
};
|
||||
|
||||
*/
|
||||
|
||||
ListaIngressoSchema.statics.getnumInvitati = async function (idapp, username) {
|
||||
const ListaIngresso = this;
|
||||
|
||||
const arrlistainv = await ListaIngresso.find({
|
||||
idapp,
|
||||
invitante_username: username,
|
||||
deleted: false,
|
||||
username: { $ne: username },
|
||||
}, { username: 1 });
|
||||
|
||||
const { User } = require('./user');
|
||||
|
||||
// Ottieni gli invitati che ancora non hanno un'imbarco
|
||||
const arrinv = await User.find({
|
||||
idapp,
|
||||
aportador_solidario: username,
|
||||
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }]
|
||||
});
|
||||
|
||||
for (const inv of arrinv) {
|
||||
if (!arrlistainv.find((rec) => rec.username === inv.username))
|
||||
arrlistainv.push(inv);
|
||||
}
|
||||
|
||||
if (!!arrlistainv)
|
||||
return arrlistainv.length;
|
||||
else
|
||||
return 0;
|
||||
|
||||
};
|
||||
|
||||
ListaIngressoSchema.statics.getnumInvitatiAttivi = async function (idapp, username) {
|
||||
const ListaIngresso = this;
|
||||
|
||||
const { User } = require('./user');
|
||||
|
||||
let myfilter2 = {
|
||||
surname: { $exists: true },
|
||||
$and: User.getQueryQualified(),
|
||||
};
|
||||
|
||||
let myquery = getQueryProj({
|
||||
idapp,
|
||||
invitante_username: username,
|
||||
username: { $ne: username },
|
||||
deleted: false,
|
||||
},
|
||||
{ username: 1, ind_order: 1 },
|
||||
myfilter2,
|
||||
);
|
||||
|
||||
// { _id: null, count: { $sum: 1 }
|
||||
|
||||
arrlistainv = await ListaIngresso.aggregate(myquery);
|
||||
|
||||
// Ottieni gli invitati che ancora non hanno un'imbarco
|
||||
const arrinv = await User.find({
|
||||
idapp,
|
||||
aportador_solidario: username,
|
||||
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
|
||||
$and: User.getQueryQualified()
|
||||
});
|
||||
|
||||
for (const inv of arrinv) {
|
||||
if (!arrlistainv.find((rec) => rec.username === inv.username))
|
||||
arrlistainv.push(inv);
|
||||
}
|
||||
|
||||
if (!!arrlistainv)
|
||||
return arrlistainv.length;
|
||||
else
|
||||
return 0;
|
||||
};
|
||||
|
||||
|
||||
ListaIngressoSchema.statics.aggiornaIndex = function (idapp) {
|
||||
const ListaIngresso = this;
|
||||
|
||||
const arrlista = ListaIngresso.find({ idapp }).sort({ created: 1 });
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
const ListaIngresso = mongoose.model('ListaIngresso', ListaIngressoSchema);
|
||||
|
||||
|
||||
|
||||
@@ -91,6 +91,31 @@ NaveSchema.statics.findByIndOrder = function (idapp, ind_order) {
|
||||
}
|
||||
};
|
||||
|
||||
NaveSchema.statics.checkIfNaveExist = async function (idapp, username) {
|
||||
const Nave = this;
|
||||
|
||||
try {
|
||||
|
||||
const arrlista = await ListaIngresso.find({
|
||||
idapp,
|
||||
username,
|
||||
// added: true,
|
||||
deleted: false,
|
||||
});
|
||||
|
||||
for (const rec of arrlista) {
|
||||
const mynave = await Nave.find({ idapp, ind_order: rec.ind_order });
|
||||
if (!!mynave)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
NaveSchema.statics.findByIndOrderAndNumTess = function (idapp, ind_order, num_tess) {
|
||||
const Nave = this;
|
||||
|
||||
@@ -108,9 +133,34 @@ NaveSchema.statics.findByIndOrderAndNumTess = function (idapp, ind_order, num_te
|
||||
NaveSchema.statics.findById = function (idapp, id) {
|
||||
const Nave = this;
|
||||
|
||||
const myquery = getQueryProj({ idapp, '_id': ObjectID(id) });
|
||||
const { User } = require('./user');
|
||||
|
||||
return Nave.aggregate(myquery);
|
||||
const myquery = getQueryProj({ idapp, '_id': id });
|
||||
|
||||
return Nave.aggregate(myquery)
|
||||
.then(async (rec) => {
|
||||
try {
|
||||
if (!!rec) {
|
||||
if (rec.length > 0) {
|
||||
const ris = await User.findByIndOrder(idapp, rec[0].ind_order);
|
||||
if (!!ris) {
|
||||
if (!!ris._doc)
|
||||
rec[0] = { ...rec[0], ...ris._doc };
|
||||
else
|
||||
rec[0] = { ...rec[0], ...ris };
|
||||
return rec[0];
|
||||
}
|
||||
return rec[0];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}catch (e) {
|
||||
console.error(e.message);
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
@@ -176,7 +226,7 @@ NaveSchema.statics.findDonatoreByNave = function (idapp, nave) {
|
||||
|
||||
return Nave.findOne(miaquery);
|
||||
} catch (e) {
|
||||
|
||||
console.error(e.message);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -243,16 +293,13 @@ NaveSchema.statics.findRecByRigaColParent = async function (idapp, riga, col, nu
|
||||
|
||||
recfind = await Nave.findById(idapp, myrec.parent_id);
|
||||
if (!!recfind) {
|
||||
if (recfind.length > 0) {
|
||||
recfind = recfind[0];
|
||||
lastrec = recfind;
|
||||
myrigacol.riga = lastrec.riga;
|
||||
myrigacol.col = lastrec.col;
|
||||
} else {
|
||||
//lastrec = await User.findByIndOrder(idapp, 0);
|
||||
lastrec = await Nave.findGeneric({ idapp, riga: 0, col: 0 });
|
||||
break;
|
||||
}
|
||||
lastrec = recfind;
|
||||
myrigacol.riga = lastrec.riga;
|
||||
myrigacol.col = lastrec.col;
|
||||
} else {
|
||||
//lastrec = await User.findByIndOrder(idapp, 0);
|
||||
lastrec = await Nave.findGeneric({ idapp, riga: 0, col: 0 });
|
||||
break;
|
||||
}
|
||||
}
|
||||
parentup++;
|
||||
@@ -267,43 +314,6 @@ NaveSchema.statics.findRecByRigaColParent = async function (idapp, riga, col, nu
|
||||
|
||||
};
|
||||
|
||||
function getlimiti(mypos) {
|
||||
|
||||
if (mypos.col < 0) {
|
||||
mypos.col = 0;
|
||||
}
|
||||
|
||||
if (mypos.riga < 0) {
|
||||
mypos.riga = 0;
|
||||
mypos.col = 0;
|
||||
}
|
||||
|
||||
return mypos;
|
||||
}
|
||||
|
||||
function getRigaColGenerica(idapp, riga, col, numup) {
|
||||
mypos = {
|
||||
idapp,
|
||||
riga,
|
||||
col,
|
||||
numup
|
||||
};
|
||||
|
||||
if (idapp === tools.AYNI) {
|
||||
tools.getRigaColByPosUp(mypos);
|
||||
ris = getlimiti(mypos);
|
||||
}
|
||||
|
||||
return ris;
|
||||
}
|
||||
|
||||
function getRigaColSognatoreByFuoco(idapp, riga, col) {
|
||||
return getRigaColGenerica(idapp, riga, col, 6);
|
||||
}
|
||||
|
||||
function getRigaColMediatoreByFuoco(idapp, riga, col) {
|
||||
return getRigaColGenerica(idapp, riga, col, 3);
|
||||
}
|
||||
|
||||
NaveSchema.statics.findGeneric = function (myrigacol) {
|
||||
|
||||
@@ -339,17 +349,17 @@ NaveSchema.statics.findGeneric = function (myrigacol) {
|
||||
if (!!newrec) {
|
||||
let myarr = {};
|
||||
if (rec[0]._doc === undefined)
|
||||
myarr = { ...newrec._doc, ...rec[0] };
|
||||
myarr = { ...newrec, ...rec[0] };
|
||||
else
|
||||
myarr = { ...newrec._doc, ...rec[0]._doc };
|
||||
myarr = { ...newrec, ...rec[0]._doc };
|
||||
return myarr;
|
||||
} else {
|
||||
let myarr = rec[0];
|
||||
if (!!newrec) {
|
||||
if (rec[0]._doc === undefined)
|
||||
myarr = { ...newrec._doc, ...rec[0] };
|
||||
myarr = { ...newrec, ...rec[0] };
|
||||
else
|
||||
myarr = { ...newrec._doc, ...rec[0]._doc };
|
||||
myarr = { ...newrec, ...rec[0]._doc };
|
||||
}
|
||||
return myarr;
|
||||
}
|
||||
@@ -403,9 +413,11 @@ function getQueryProj(myfilter) {
|
||||
name: 1,
|
||||
surname: 1,
|
||||
username: 1,
|
||||
invitante_username: 1,
|
||||
deleted: 1,
|
||||
sospeso: 1,
|
||||
'profile.paymenttypes': 1,
|
||||
'profile.teleg_id': 1,
|
||||
'profile.email_paypal': 1,
|
||||
'profile.cell': 1,
|
||||
made_gift: 1,
|
||||
@@ -433,10 +445,32 @@ function getQueryProj(myfilter) {
|
||||
{ $match: myfilter },
|
||||
{
|
||||
$lookup: {
|
||||
from: "users",
|
||||
from: "listaingressos",
|
||||
localField: "ind_order",
|
||||
foreignField: "ind_order", // field in the user collection
|
||||
as: "user"
|
||||
as: "mylista"
|
||||
}
|
||||
},
|
||||
{
|
||||
$unwind: "$mylista"
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "users",
|
||||
as: "user",
|
||||
let: {username: '$mylista.username' },
|
||||
pipeline: [
|
||||
{
|
||||
$match: {
|
||||
$expr: {
|
||||
$and: [
|
||||
{ $eq: ['$username', '$$username'] },
|
||||
{ $eq: ['$idapp', myfilter.idapp] },
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -521,32 +555,34 @@ NaveSchema.statics.getPlaccaGenerica = async function (idapp, riga, col, offset,
|
||||
let recmediatore = await Nave.findMediatoreByFuoco(idapp, riga, col, offset);
|
||||
let navepersistente = await NavePersistente.findByRigaColByDonatore(idapp, riga, col, offset);
|
||||
|
||||
mystr = tools.ACAPO;
|
||||
if (!solorecord) {
|
||||
mystr = tools.ACAPO;
|
||||
|
||||
mystr += 'GIFTING CHAT (' + riga + '.' + col + ') ' + tools.ACAPO + tools.ACAPO;
|
||||
mystr += 'GIFTING CHAT (' + riga + '.' + col + ') ' + tools.ACAPO + tools.ACAPO;
|
||||
|
||||
if (offset === tools.Placca.SONOFUOCO) {
|
||||
mystr += tools.Placca.SOGNATORE + tools.Placca.STR_SOGNATORE + ': ' + await getusertextbyrec(recsognatori[0], '', '', riga, col, '') + tools.ACAPO + tools.ACAPO;
|
||||
mystr += tools.Placca.MEDIATORE + tools.Placca.STR_MEDIATORE + ': ' + await getusertextbyrec(recmediatore, '', '', riga, col, '') + tools.ACAPO + tools.ACAPO;
|
||||
}
|
||||
if (offset === tools.Placca.SONOFUOCO) {
|
||||
mystr += tools.Placca.SOGNATORE + tools.Placca.STR_SOGNATORE + ': ' + await getusertextbyrec(recsognatori[0], '', '', riga, col, '') + tools.ACAPO + tools.ACAPO;
|
||||
mystr += tools.Placca.MEDIATORE + tools.Placca.STR_MEDIATORE + ': ' + await getusertextbyrec(recmediatore, '', '', riga, col, '') + tools.ACAPO + tools.ACAPO;
|
||||
}
|
||||
|
||||
if (offset === tools.Placca.SONOACQUA) {
|
||||
mystr += tools.Placca.SOGNATORE + tools.Placca.STR_SOGNATORE + ': ' + await getusertextbyrec(recmediatore, '', '', riga, col, '') + tools.ACAPO + tools.ACAPO;
|
||||
}
|
||||
if (offset === tools.Placca.SONOACQUA) {
|
||||
mystr += tools.Placca.SOGNATORE + tools.Placca.STR_SOGNATORE + ': ' + await getusertextbyrec(recmediatore, '', '', riga, col, '') + tools.ACAPO + tools.ACAPO;
|
||||
}
|
||||
|
||||
let symb = {
|
||||
car: 'D',
|
||||
icona: '🔥'
|
||||
};
|
||||
|
||||
if (offset === tools.Placca.SONOFUOCO) {
|
||||
mystr += tools.Placca.STR_DONATORI + ':' + tools.ACAPO;
|
||||
} else if (offset === tools.Placca.SONOACQUA) {
|
||||
mystr += tools.Placca.STR_MEDIATORI + ':' + tools.ACAPO;
|
||||
symb = {
|
||||
car: 'A',
|
||||
icona: '💦'
|
||||
let symb = {
|
||||
car: 'D',
|
||||
icona: '🔥'
|
||||
};
|
||||
|
||||
if (offset === tools.Placca.SONOFUOCO) {
|
||||
mystr += tools.Placca.STR_DONATORI + ':' + tools.ACAPO;
|
||||
} else if (offset === tools.Placca.SONOACQUA) {
|
||||
mystr += tools.Placca.STR_MEDIATORI + ':' + tools.ACAPO;
|
||||
symb = {
|
||||
car: 'A',
|
||||
icona: '💦'
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// mystr += '🔥🌏💦💨🔥🌏💦💨' + tools.ACAPO;
|
||||
@@ -573,7 +609,9 @@ NaveSchema.statics.getPlaccaGenerica = async function (idapp, riga, col, offset,
|
||||
recfuoco = checkifNullThenEmpty(recfuoco, indr, indc);
|
||||
arrdonatori.push({ index: ind, ...recfuoco });
|
||||
|
||||
mystr += await getusertextbyrec(recfuoco, symb.icona, symb.car, indr, indc, ind) + tools.ACAPO;
|
||||
if (!solorecord) {
|
||||
mystr += await getusertextbyrec(recfuoco, symb.icona, symb.car, indr, indc, ind) + tools.ACAPO;
|
||||
}
|
||||
ind++;
|
||||
}
|
||||
|
||||
@@ -777,45 +815,82 @@ NaveSchema.statics.getNavePos = async function (idapp, riga, col, solorecord, in
|
||||
|
||||
};
|
||||
|
||||
async function Fuochi8Completati(idapp, params) {
|
||||
// Inviare un msg al Mediatore che può aprire la Chat con gli 8 fuochi
|
||||
const telegrambot = require('../telegram/telegrambot');
|
||||
|
||||
let text = '\nCompletata NAVE [riga=' + params.riga + ',col=' + params.col + ', ind_order=' + params.ind_order + ']';
|
||||
console.log(text);
|
||||
tools.writeNaveLog(text);
|
||||
|
||||
const { User } = require('./user');
|
||||
|
||||
const rec = await User.findByIndOrder(idapp, params.ind_order);
|
||||
|
||||
text = await Nave.getNaveByUser(idapp, params.ind_order, rec.lang, true);
|
||||
|
||||
// Inviare un msg a questi 8 Fuochi, che la loro placca è Pronta !
|
||||
|
||||
if (tools.isAbilitaNave(idapp)) {
|
||||
// .............
|
||||
}
|
||||
|
||||
if (false) {
|
||||
await telegrambot.sendMsgTelegram(idapp, rec.username, text, true);
|
||||
} else {
|
||||
await telegrambot.sendMsgTelegramToTheAdmin(idapp, text);
|
||||
}
|
||||
|
||||
// Inviare la placca a Managers
|
||||
// await telegrambot.sendMsgTelegramToTheManagers(idapp, txt);
|
||||
}
|
||||
// async function Fuochi8Completati(idapp, params) {
|
||||
// // Inviare un msg al Mediatore che può aprire la Chat con gli 8 fuochi
|
||||
// const telegrambot = require('../telegram/telegrambot');
|
||||
//
|
||||
// let text = '\nCompletata NAVE [riga=' + params.riga + ',col=' + params.col + ', ind_order=' + params.ind_order + ']';
|
||||
// console.log(text);
|
||||
// tools.writeNaveLog(text);
|
||||
//
|
||||
// const { User } = require('./user');
|
||||
//
|
||||
// const rec = await User.findByIndOrder(idapp, params.ind_order);
|
||||
//
|
||||
// text = await Nave.getNaveByUser(idapp, params.ind_order, rec.lang, true);
|
||||
//
|
||||
// // Inviare un msg a questi 8 Fuochi, che la loro placca è Pronta !
|
||||
//
|
||||
// if (tools.isAbilitaNave(idapp)) {
|
||||
// // .............
|
||||
// }
|
||||
//
|
||||
// if (false) {
|
||||
// await telegrambot.sendMsgTelegram(idapp, rec.username, text, true);
|
||||
// } else {
|
||||
// await telegrambot.sendMsgTelegramToTheAdmin(idapp, text);
|
||||
// }
|
||||
//
|
||||
// // Inviare la placca a Managers
|
||||
// // await telegrambot.sendMsgTelegramToTheManagers(idapp, txt);
|
||||
// }
|
||||
|
||||
NaveSchema.statics.getArrPosizioniByIndOrder = async function (idapp, ind_order) {
|
||||
const Nave = this;
|
||||
|
||||
|
||||
arrposizioni = await Nave.find({ 'idapp': idapp, ind_order }).sort({ riga: 1, col: 1 });
|
||||
arrposizioni = await Nave.find({ idapp, ind_order }).sort({ riga: 1, col: 1 });
|
||||
|
||||
return arrposizioni;
|
||||
};
|
||||
|
||||
NaveSchema.statics.getArrPosizioniByUsername = async function (idapp, username) {
|
||||
const Nave = this;
|
||||
|
||||
const { ListaIngresso } = require('./listaingresso');
|
||||
|
||||
try {
|
||||
const arrrec_indorder = await ListaIngresso.findByAllRecByUsername(idapp, username).distinct("ind_order");
|
||||
|
||||
let arrposizioni = [];
|
||||
|
||||
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) {
|
||||
console.error(e.message);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
NaveSchema.statics.getArrProfiliByIndOrder = async function (idapp, ind_order) {
|
||||
const Nave = this;
|
||||
|
||||
arrposizioni = await Nave.find({ 'idapp': idapp, ind_order }).sort({ riga: 1, col: 1 });
|
||||
|
||||
arrprofili = [];
|
||||
|
||||
// Ind_Order
|
||||
// Ind_order_base
|
||||
|
||||
|
||||
return arrprofili;
|
||||
};
|
||||
|
||||
NaveSchema.statics.getPrimaNaveByRiga = async function (idapp, riga) {
|
||||
const Nave = this;
|
||||
|
||||
@@ -1174,32 +1249,36 @@ NaveSchema.statics.visuNaviUtentiEliminati = async function (idapp) {
|
||||
};
|
||||
|
||||
|
||||
NaveSchema.statics.getNaveByUser = async function (idapp, ind_order, lang, fuoco) {
|
||||
NaveSchema.statics.getNaveByUser = async function (idapp, username, lang, fuoco) {
|
||||
const Nave = this;
|
||||
|
||||
let mystr = '';
|
||||
let rec = {};
|
||||
const arrposiz = await Nave.getArrPosizioniByIndOrder(idapp, ind_order);
|
||||
if (!!arrposiz) {
|
||||
for (const pos of arrposiz) {
|
||||
let mypos = {
|
||||
riga: pos.riga,
|
||||
col: pos.col,
|
||||
numup: 3,
|
||||
};
|
||||
tools.getRigaColByPosUp(mypos);
|
||||
try {
|
||||
const arrposiz = await Nave.getArrPosizioniByUsername(idapp, username);
|
||||
if (!!arrposiz) {
|
||||
for (const pos of arrposiz) {
|
||||
let mypos = {
|
||||
riga: pos.riga,
|
||||
col: pos.col,
|
||||
numup: 3,
|
||||
};
|
||||
tools.getRigaColByPosUp(mypos);
|
||||
|
||||
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);
|
||||
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);
|
||||
}
|
||||
// mystr += await Nave.getPlaccaPerDonatore(idapp, pos.riga, pos.col, false, rec);
|
||||
// mystr += await Nave.getPlaccaPerMediatore(idapp, pos.riga, pos.col, false, rec);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
}
|
||||
|
||||
return mystr;
|
||||
@@ -1333,6 +1412,53 @@ NaveSchema.statics.getNextNumTess = async function (idapp, ind_order) {
|
||||
|
||||
};
|
||||
|
||||
NaveSchema.statics.getnumNaviByUsername = async function (idapp, username) {
|
||||
const Nave = this;
|
||||
|
||||
try {
|
||||
|
||||
const { ListaIngresso } = require('./listaingresso');
|
||||
|
||||
// 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] } }, {
|
||||
riga: 1,
|
||||
col: 1,
|
||||
ind_order: 1
|
||||
});
|
||||
|
||||
if (!!arrrec)
|
||||
return arrrec.length;
|
||||
else
|
||||
return 0;
|
||||
|
||||
}catch (e) {
|
||||
console.error(e.message);
|
||||
}
|
||||
};
|
||||
|
||||
NaveSchema.statics.getSognatoreByRigaColMediatore = async function (idapp, navemediatore) {
|
||||
|
||||
const ris = this.getRigaColSognatoreByMediatore(idapp, navemediatore.riga, navemediatore.col, 3);
|
||||
|
||||
const myquery = getQueryProj({
|
||||
idapp,
|
||||
riga: ris.riga,
|
||||
col: ris.col,
|
||||
});
|
||||
|
||||
arrrec = await Nave.aggregate(myquery);
|
||||
|
||||
if (!!arrrec) {
|
||||
if (arrrec.length > 0)
|
||||
return arrrec[0];
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
|
||||
|
||||
const Nave = mongoose.model('Nave', NaveSchema);
|
||||
|
||||
|
||||
@@ -118,10 +118,32 @@ function getQueryProj(myfilter) {
|
||||
{ $match: myfilter },
|
||||
{
|
||||
$lookup: {
|
||||
from: "users",
|
||||
from: "listaingressos",
|
||||
localField: "ind_order",
|
||||
foreignField: "ind_order", // field in the user collection
|
||||
as: "user"
|
||||
as: "mylista"
|
||||
}
|
||||
},
|
||||
{
|
||||
$unwind: "$mylista"
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "users",
|
||||
as: "user",
|
||||
let: {username: '$mylista.username' },
|
||||
pipeline: [
|
||||
{
|
||||
$match: {
|
||||
$expr: {
|
||||
$and: [
|
||||
{ $eq: ['$username', '$$username'] },
|
||||
{ $eq: ['$idapp', myfilter.idapp] },
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@@ -333,8 +333,6 @@ ProjectSchema.statics.updateCalc = async function (userId, idproj, objdatacalc,
|
||||
|
||||
|
||||
ProjectSchema.pre('save', function (next) {
|
||||
// var Project = this;
|
||||
|
||||
// console.log('Project.expiring_at', Project.expiring_at);
|
||||
|
||||
next();
|
||||
|
||||
@@ -10,7 +10,7 @@ const { Settings } = require('../models/settings');
|
||||
const { ListaIngresso } = require('../models/listaingresso');
|
||||
const { Nave } = require('../models/nave');
|
||||
const { NavePersistente } = require('../models/navepersistente');
|
||||
const { ExtraList } = require('../models/extralist');
|
||||
// const { ExtraList } = require('../models/extralist');
|
||||
|
||||
const { ObjectID } = require('mongodb');
|
||||
|
||||
@@ -46,9 +46,15 @@ const UserSchema = new mongoose.Schema({
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
index: {
|
||||
type: Number
|
||||
},
|
||||
ind_order: {
|
||||
type: Number
|
||||
},
|
||||
old_order: {
|
||||
type: Number
|
||||
},
|
||||
username: {
|
||||
type: String,
|
||||
required: true,
|
||||
@@ -121,7 +127,7 @@ const UserSchema = new mongoose.Schema({
|
||||
news_on: {
|
||||
type: Boolean
|
||||
},
|
||||
aportador_solidario: {
|
||||
aportador_solidario: { // da cancellare
|
||||
type: String,
|
||||
},
|
||||
aportador_iniziale: {
|
||||
@@ -401,6 +407,7 @@ UserSchema.statics.getUserShortDataByUsername = async function (idapp, username)
|
||||
lang: 1,
|
||||
ind_order: 1,
|
||||
username: 1,
|
||||
aportador_solidario: 1,
|
||||
name: 1,
|
||||
surname: 1,
|
||||
deleted: 1,
|
||||
@@ -429,101 +436,96 @@ UserSchema.statics.getUserShortDataByUsername = async function (idapp, username)
|
||||
|
||||
if (myrec) {
|
||||
myrec.qualified = await User.isUserQualified7(idapp, myrec.username);
|
||||
myrec.numinvitati = await User.getnumInvitati(idapp, myrec.username);
|
||||
myrec.numinvitatiattivi = await User.getnumInvitatiAttivi(idapp, myrec.username);
|
||||
myrec.numNaviEntrato = await Nave.getnumNaviByUsername(idapp, myrec.username);
|
||||
myrec.numinvitati = await ListaIngresso.getnumInvitati(idapp, myrec.username);
|
||||
myrec.numinvitatiattivi = await ListaIngresso.getnumInvitatiAttivi(idapp, myrec.username);
|
||||
}
|
||||
|
||||
return myrec
|
||||
};
|
||||
|
||||
UserSchema.statics.getDownlineByUsername = async function (idapp, username) {
|
||||
|
||||
if (username === undefined)
|
||||
return null;
|
||||
|
||||
const User = this;
|
||||
const arrrec = await User.find({
|
||||
'idapp': idapp,
|
||||
'aportador_solidario': username,
|
||||
const arrrec = await ListaIngresso.getInvitati(idapp, username,
|
||||
{
|
||||
index: 1,
|
||||
lang: 1,
|
||||
invitante_username: 1,
|
||||
ind_order: 1,
|
||||
username: 1,
|
||||
name: 1,
|
||||
surname: 1,
|
||||
verified_email: 1,
|
||||
'profile.teleg_id': 1,
|
||||
'profile.saw_zoom_presentation': 1,
|
||||
'profile.saw_and_accepted': 1,
|
||||
'profile.email_paypal': 1,
|
||||
'profile.my_dream': 1,
|
||||
'profile.paymenttypes': 1,
|
||||
'profile.cell': 1,
|
||||
made_gift: 1,
|
||||
email: 1,
|
||||
date_reg: 1,
|
||||
img: 1
|
||||
}
|
||||
);
|
||||
|
||||
// Ottieni gli invitati che ancora non hanno un'imbarco
|
||||
const arrinv = await User.find({
|
||||
idapp,
|
||||
aportador_solidario: username,
|
||||
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }]
|
||||
}, {
|
||||
lang: 1,
|
||||
aportador_solidario: 1,
|
||||
ind_order: 1,
|
||||
username: 1,
|
||||
name: 1,
|
||||
surname: 1,
|
||||
verified_email: 1,
|
||||
'profile.teleg_id': 1,
|
||||
'profile.saw_zoom_presentation': 1,
|
||||
'profile.saw_and_accepted': 1,
|
||||
'profile.email_paypal': 1,
|
||||
'profile.my_dream': 1,
|
||||
'profile.paymenttypes': 1,
|
||||
'profile.cell': 1,
|
||||
made_gift: 1,
|
||||
email: 1,
|
||||
date_reg: 1,
|
||||
img: 1
|
||||
}, (err, arrrec) => {
|
||||
return arrrec;
|
||||
});
|
||||
|
||||
for (const inv of arrinv) {
|
||||
if (!arrrec.find((rec) => rec.username === inv.username))
|
||||
arrrec.push(inv);
|
||||
}
|
||||
|
||||
|
||||
if (!!arrrec) {
|
||||
for (const rec of arrrec) {
|
||||
rec._doc.qualified = await User.isUserQualified7(idapp, rec.username);
|
||||
rec._doc.numinvitati = await User.getnumInvitati(idapp, rec.username);
|
||||
rec._doc.numinvitatiattivi = await User.getnumInvitatiAttivi(idapp, rec.username);
|
||||
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
|
||||
return arrrec;
|
||||
|
||||
};
|
||||
|
||||
UserSchema.statics.getQueryQualified = function () {
|
||||
return [
|
||||
{
|
||||
$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.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",
|
||||
}]
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
UserSchema.statics.getnumInvitatiAttivi = function (idapp, username) {
|
||||
const User = this;
|
||||
|
||||
if (username === undefined)
|
||||
return 0;
|
||||
|
||||
// return User.count({
|
||||
return User.countDocuments({
|
||||
idapp,
|
||||
aportador_solidario: username,
|
||||
$and: [
|
||||
{
|
||||
$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: [
|
||||
{ '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) {
|
||||
const User = this;
|
||||
@@ -534,30 +536,7 @@ UserSchema.statics.isUserQualified7 = async function (idapp, username) {
|
||||
const myquery = {
|
||||
'idapp': idapp,
|
||||
'username': username,
|
||||
$and: [
|
||||
{
|
||||
$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.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",
|
||||
}]
|
||||
}]
|
||||
$and: User.getQueryQualified(),
|
||||
};
|
||||
|
||||
const myrec = await User.findOne(myquery);
|
||||
@@ -572,7 +551,7 @@ UserSchema.statics.isUserQualified9 = async function (idapp, username) {
|
||||
return false;
|
||||
|
||||
qualified = await User.isUserQualified7(idapp, username);
|
||||
numinvitatiattivi = await User.getnumInvitatiAttivi(idapp, username);
|
||||
numinvitatiattivi = await ListaIngresso.getnumInvitatiAttivi(idapp, username);
|
||||
|
||||
return qualified && (numinvitatiattivi >= 2);
|
||||
|
||||
@@ -616,16 +595,6 @@ UserSchema.statics.getindOrderDuplicate = function (idapp) {
|
||||
});
|
||||
};
|
||||
|
||||
UserSchema.statics.getnumInvitati = function (idapp, username) {
|
||||
const User = this;
|
||||
|
||||
return User.count({
|
||||
idapp,
|
||||
aportador_solidario: username,
|
||||
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
|
||||
});
|
||||
};
|
||||
|
||||
UserSchema.statics.findByLinkreg = function (idapp, linkreg) {
|
||||
const User = this;
|
||||
|
||||
@@ -696,24 +665,55 @@ UserSchema.statics.findByIndOrder = function (idapp, ind_order) {
|
||||
}
|
||||
};
|
||||
|
||||
UserSchema.statics.findByOldOrder = function (idapp, old_order) {
|
||||
const User = this;
|
||||
|
||||
UserSchema.pre('save', function (next) {
|
||||
const user = this;
|
||||
|
||||
|
||||
/*
|
||||
if (user.isModified('password')) {
|
||||
bcrypt.genSalt(10, (err, salt) => {
|
||||
bcrypt.hash(user.password, salt, (err, hash) => {
|
||||
user.password = hash;
|
||||
next();
|
||||
});
|
||||
try {
|
||||
return User.findOne({
|
||||
idapp,
|
||||
old_order,
|
||||
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
|
||||
});
|
||||
} else {
|
||||
next();
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
UserSchema.pre('save', async function (next) {
|
||||
|
||||
try {
|
||||
if (this.isNew) {
|
||||
try {
|
||||
const myrec = await User.findOne({ idapp: this.idapp }).limit(1).sort({ index: -1 });
|
||||
|
||||
if (!!myrec) {
|
||||
this.index = myrec._doc.index + 1;
|
||||
} else {
|
||||
this.index = 1;
|
||||
}
|
||||
} catch (e) {
|
||||
this.index = 2;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
if (user.isModified('password')) {
|
||||
bcrypt.genSalt(10, (err, salt) => {
|
||||
bcrypt.hash(user.password, salt, (err, hash) => {
|
||||
user.password = hash;
|
||||
next();
|
||||
});
|
||||
});
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
*/
|
||||
|
||||
next();
|
||||
}catch (e) {
|
||||
console.error(e.message);
|
||||
}
|
||||
*/
|
||||
next();
|
||||
});
|
||||
|
||||
UserSchema.methods.removeToken = function (token) {
|
||||
@@ -763,15 +763,6 @@ UserSchema.statics.getUserById = function (idapp, id) {
|
||||
})
|
||||
};
|
||||
|
||||
UserSchema.statics.getUserByAportador = function (idapp, aportador_solidario) {
|
||||
const User = this;
|
||||
|
||||
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;
|
||||
|
||||
@@ -920,25 +911,31 @@ 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,
|
||||
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }]
|
||||
},
|
||||
{
|
||||
idapp: 1,
|
||||
ind_order: 1,
|
||||
username: 1,
|
||||
name: 1,
|
||||
surname: 1
|
||||
}
|
||||
)
|
||||
.then((rec) => {
|
||||
return rec;
|
||||
}).catch((e) => {
|
||||
console.error('getSmallRecByIndOrder', e);
|
||||
});
|
||||
try {
|
||||
const rec = await ListaIngresso.getarray(idapp,
|
||||
{
|
||||
idapp,
|
||||
ind_order,
|
||||
deleted: false,
|
||||
},
|
||||
{
|
||||
idapp: 1,
|
||||
ind_order: 1,
|
||||
username: 1,
|
||||
name: 1,
|
||||
surname: 1
|
||||
});
|
||||
|
||||
if (!!rec)
|
||||
return rec[0];
|
||||
|
||||
return null;
|
||||
|
||||
} catch (e) {
|
||||
console.error('getSmallRecByIndOrder', e);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -995,7 +992,7 @@ UserSchema.statics.isAdminByIdTeleg = async function (idapp, idtelegram) {
|
||||
|
||||
return await User.findOne({
|
||||
idapp,
|
||||
'username': 'paoloar77',
|
||||
username: 'paoloar77',
|
||||
'profile.manage_telegram': true,
|
||||
'profile.teleg_id': idtelegram
|
||||
}, { 'profile.teleg_id': 1 })
|
||||
@@ -1061,13 +1058,17 @@ UserSchema.statics.getUsersListByParams = function (params) {
|
||||
*/
|
||||
|
||||
UserSchema.statics.getFieldsForSearch = function () {
|
||||
return [{ field: 'username', type: tools.FieldType.string },
|
||||
return [
|
||||
{ field: 'username', type: tools.FieldType.string },
|
||||
{ field: 'name', type: tools.FieldType.string },
|
||||
{ field: 'index', type: tools.FieldType.number },
|
||||
{ field: 'ind_order', type: tools.FieldType.number },
|
||||
{ field: 'old_order', type: tools.FieldType.number },
|
||||
{ field: 'surname', type: tools.FieldType.string },
|
||||
{ field: 'email', type: tools.FieldType.string },
|
||||
{ field: 'profile.cell', type: tools.FieldType.string },
|
||||
{ field: 'profile.email_paypal', type: tools.FieldType.string },
|
||||
{ field: 'profile.teleg_id', type: tools.FieldType.number },
|
||||
{ field: 'profile.username_telegram', type: tools.FieldType.string },
|
||||
{ field: 'aportador_solidario', type: tools.FieldType.string }]
|
||||
};
|
||||
@@ -1102,20 +1103,23 @@ UserSchema.statics.getDashboard = async function (idapp, aportador_solidario, us
|
||||
// DATA: username, name, surname, email, intcode_cell, cell
|
||||
const dashboard = {
|
||||
aportador: {},
|
||||
downline: []
|
||||
downline: [],
|
||||
arrposizioni: [],
|
||||
arrimbarchi: [],
|
||||
arrusers: {},
|
||||
};
|
||||
|
||||
dashboard.myself = await User.getUserShortDataByUsername(idapp, username);
|
||||
// Data of my Aportador
|
||||
dashboard.aportador = await User.getUserShortDataByUsername(idapp, aportador_solidario);
|
||||
if (dashboard.aportador === undefined) {
|
||||
dashboard.aportador = await ExtraList.getUserNotRegisteredByNameSurname(idapp, aportador_solidario_nome_completo);
|
||||
}
|
||||
// if (dashboard.aportador === undefined) {
|
||||
// dashboard.aportador = await ExtraList.getUserNotRegisteredByNameSurname(idapp, aportador_solidario_nome_completo);
|
||||
// }
|
||||
|
||||
dashboard.downline = [];
|
||||
|
||||
// Data of my Downline
|
||||
const arrap = await User.getDownlineByUsername(idapp, aportador_solidario);
|
||||
const arrap = await User.getDownlineByUsername(idapp, username);
|
||||
if (!!arrap)
|
||||
dashboard.numpeople_aportador = arrap.length;
|
||||
|
||||
@@ -1132,32 +1136,33 @@ UserSchema.statics.getDashboard = async function (idapp, aportador_solidario, us
|
||||
}
|
||||
}
|
||||
|
||||
if (!!dashboard.myself.ind_order)
|
||||
dashboard.arrposizioni = await Nave.getArrPosizioniByIndOrder(idapp, dashboard.myself.ind_order);
|
||||
else
|
||||
dashboard.arrposizioni = [];
|
||||
dashboard.arrimbarchi = await ListaIngresso.findAllByUsername(idapp, username);
|
||||
|
||||
if (!!dashboard.myself.ind_order)
|
||||
dashboard.arrimbarchi = await ListaIngresso.findAllByIndOrder(idapp, dashboard.myself.ind_order);
|
||||
else
|
||||
dashboard.arrimbarchi = [];
|
||||
// dashboard.arrprofili = await Nave.getArrProfiliByIndOrder(idapp, dashboard.myself.ind_order);
|
||||
|
||||
dashboard.arrposizioni = await Nave.getArrPosizioniByUsername(idapp, username);
|
||||
|
||||
const arrrec = await ListaIngresso.getProssimiInLista(idapp, true);
|
||||
|
||||
for (let myimbarco of dashboard.arrimbarchi) {
|
||||
myimbarco._doc.posiz = await ListaIngresso.getPosizioneInLista(idapp, myimbarco.ind_order, myimbarco.num_tess);
|
||||
if (!!myimbarco.invitante_username)
|
||||
dashboard.arrusers[myimbarco.invitante_username] = await User.getUserShortDataByUsername(idapp, myimbarco.invitante_username);
|
||||
myimbarco._doc.posiz = await ListaIngresso.getPosizioneInLista(idapp, arrrec, 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);
|
||||
}
|
||||
|
||||
//for (let indriga = 0; indriga < 10; indriga++) {
|
||||
// dashboard.navi_partenza.push(await Nave.getPrimaNaveByRiga(idapp, indriga));
|
||||
//}
|
||||
|
||||
|
||||
const arrnew = [];
|
||||
|
||||
for (let mypos of dashboard.arrposizioni) {
|
||||
@@ -1167,7 +1172,8 @@ UserSchema.statics.getDashboard = async function (idapp, aportador_solidario, us
|
||||
|
||||
if (mypos.num_tess % 2 !== 0) {
|
||||
for (let myrec of dashboard.arrposizioni) {
|
||||
if (myrec.num_tess === mypos.num_tess + 1) {
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -1190,14 +1196,14 @@ UserSchema.statics.getDashboard = async function (idapp, aportador_solidario, us
|
||||
|
||||
myrec.nave_partenza = await NavePersistente.findByRigaColByDonatore(idapp, myrec.riga, myrec.col, 0);
|
||||
|
||||
arrnew.push(myrec);
|
||||
arrnew.push(myrec);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dashboard.arrposizioni = [...dashboard.arrposizioni, ...arrnew];
|
||||
|
||||
// console.table(dashboard.arrnavi);
|
||||
// console.table(dashboard.arrnavi);
|
||||
|
||||
return dashboard;
|
||||
} catch (e) {
|
||||
@@ -1248,6 +1254,7 @@ UserSchema.statics.getUsersRegistered = async function (idapp) {
|
||||
return await User.count(myfind);
|
||||
};
|
||||
|
||||
/*
|
||||
UserSchema.statics.getUsersQualified = async function (idapp, numinvitati) {
|
||||
const User = this;
|
||||
|
||||
@@ -1285,7 +1292,7 @@ UserSchema.statics.getUsersQualified = async function (idapp, numinvitati) {
|
||||
let arrris = [];
|
||||
|
||||
for (const rec of arrusers) {
|
||||
rec.numinvitatiattivi = await User.getnumInvitatiAttivi(idapp, rec.username);
|
||||
rec.numinvitatiattivi = await ListaIngresso.getnumInvitatiAttivi(idapp, rec.username);
|
||||
if (rec.numinvitatiattivi >= numinvitati) {
|
||||
arrris.push(rec);
|
||||
}
|
||||
@@ -1294,33 +1301,14 @@ UserSchema.statics.getUsersQualified = async function (idapp, numinvitati) {
|
||||
return arrris
|
||||
|
||||
};
|
||||
*/
|
||||
|
||||
UserSchema.statics.visuUtentiNonInNavi = async function (idapp) {
|
||||
const User = this;
|
||||
|
||||
const arrusers = await User.find({
|
||||
idapp,
|
||||
$and: [
|
||||
{ $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }] },
|
||||
{
|
||||
$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] } }
|
||||
],
|
||||
}]
|
||||
}]
|
||||
|
||||
$and: User.getQueryQualified()
|
||||
}, {
|
||||
name: 1,
|
||||
surname: 1,
|
||||
@@ -1373,7 +1361,7 @@ UserSchema.statics.visuUtentiNonInNavi = async function (idapp) {
|
||||
visualizza = true;
|
||||
}
|
||||
|
||||
user.numinvitati = await User.getnumInvitati(idapp, user.username);
|
||||
user.numinvitati = await ListaIngresso.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 });
|
||||
@@ -1439,13 +1427,13 @@ UserSchema.statics.visuUtentiNonInNavi = async function (idapp) {
|
||||
return { num, mystr };
|
||||
};
|
||||
|
||||
UserSchema.statics.getNumUsersQualified = async function (idapp, numinvitati) {
|
||||
|
||||
arrrec = await this.getUsersQualified(idapp, numinvitati);
|
||||
|
||||
return arrrec.length
|
||||
|
||||
};
|
||||
// UserSchema.statics.getNumUsersQualified = async function (idapp, numinvitati) {
|
||||
//
|
||||
// arrrec = await this.getUsersQualified(idapp, numinvitati);
|
||||
//
|
||||
// return arrrec.length
|
||||
//
|
||||
// };
|
||||
|
||||
|
||||
UserSchema.statics.getEmailNotVerified = async function (idapp) {
|
||||
@@ -1562,8 +1550,8 @@ UserSchema.statics.calculateStat = async function (idapp, username) {
|
||||
const User = this;
|
||||
|
||||
return calcstat = {
|
||||
numinvitati: await User.getnumInvitati(idapp, username),
|
||||
numinvitati_attivi: await User.getnumInvitatiAttivi(idapp, username),
|
||||
numinvitati: await ListaIngresso.getnumInvitati(idapp, username),
|
||||
numinvitati_attivi: await ListaIngresso.getnumInvitatiAttivi(idapp, username),
|
||||
};
|
||||
|
||||
};
|
||||
@@ -1693,12 +1681,13 @@ if (tools.INITDB_FIRSTIME) {
|
||||
}
|
||||
|
||||
async function addUtentiInLista(idapp, mode, arrusers) {
|
||||
|
||||
let num = 0;
|
||||
for (const rec of arrusers) {
|
||||
let ok = false;
|
||||
let qualified = await User.isUserQualified7(idapp, rec.username);
|
||||
let numinvitatiattivi = await User.getnumInvitatiAttivi(idapp, rec.username);
|
||||
let numinvitati = await User.getnumInvitati(idapp, rec.username);
|
||||
let numinvitatiattivi = await ListaIngresso.getnumInvitatiAttivi(idapp, rec.username);
|
||||
let numinvitati = await ListaIngresso.getnumInvitati(idapp, rec.username);
|
||||
|
||||
if (rec.profile.special_req) {
|
||||
numinvitatiattivi = 2;
|
||||
@@ -1719,12 +1708,13 @@ async function addUtentiInLista(idapp, mode, arrusers) {
|
||||
}
|
||||
|
||||
if (ok) {
|
||||
ris = await ListaIngresso.addUserInListaIngresso(idapp, rec.ind_order, rec.lang, false, 1);
|
||||
ris = await ListaIngresso.addUserInListaIngresso(idapp, rec.username, rec.aportador_solidario, rec.lang, false, true);
|
||||
if (!!ris)
|
||||
num++;
|
||||
}
|
||||
}
|
||||
return num;
|
||||
|
||||
}
|
||||
|
||||
UserSchema.statics.deveRitessersi = async function (idapp, ind_order) {
|
||||
@@ -1750,6 +1740,72 @@ UserSchema.statics.getUsernameByIndOrder = async function (idapp, ind_order) {
|
||||
|
||||
};
|
||||
|
||||
UserSchema.statics.getUsernameByIndex = async function (idapp, index) {
|
||||
|
||||
const myrec = await User.findOne({
|
||||
idapp,
|
||||
index,
|
||||
}, { username: 1 });
|
||||
|
||||
return (!!myrec) ? myrec.username : ''
|
||||
|
||||
};
|
||||
|
||||
UserSchema.statics.ricalcolaIndex = async function (idapp) {
|
||||
const User = this;
|
||||
|
||||
const arrusers = await User.find({ idapp }).sort({ ind_order: 1 });
|
||||
let index = 1;
|
||||
try {
|
||||
for (const user of arrusers) {
|
||||
let field = {
|
||||
index
|
||||
};
|
||||
|
||||
index++;
|
||||
|
||||
const ris = await User.findOneAndUpdate({ _id: user._id }, { $set: field }, { new: false });
|
||||
}
|
||||
}catch (e) {
|
||||
console.error(e.message);
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
UserSchema.statics.changeInvitante = async function (idapp, username, invitante_username, ind_order_ingr) {
|
||||
const User = this;
|
||||
|
||||
const rec_ind_order_prima = await ListaIngresso.findOne({ idapp, username });
|
||||
|
||||
let modif_aportador = false;
|
||||
// cambia aportador_solidario solo se è la prima nave!
|
||||
|
||||
// Oppure se ancora non sono in Lista!
|
||||
if (!rec_ind_order_prima) {
|
||||
modif_aportador = true;
|
||||
} else {
|
||||
if (rec_ind_order_prima.ind_order === ind_order_ingr) {
|
||||
modif_aportador = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (modif_aportador) {
|
||||
await User.findOneAndUpdate({ idapp, username }, { $set: { aportador_solidario: invitante_username } });
|
||||
}
|
||||
|
||||
// **
|
||||
// ** Cambia invitante_username e ind_order di LISTAINGRESSO
|
||||
// **
|
||||
const rec_ingr = await ListaIngresso.findOne({ idapp, username: username });
|
||||
if (!!rec_ingr) {
|
||||
await ListaIngresso.findByIdAndUpdate(rec_ingr._id, { $set: { invitante_username, ind_order: ind_order_ingr } });
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
UserSchema.statics.DbOp = async function (idapp, mydata) {
|
||||
const User = this;
|
||||
try {
|
||||
@@ -1788,7 +1844,7 @@ UserSchema.statics.DbOp = async function (idapp, mydata) {
|
||||
arrusers = await User.find({
|
||||
'idapp': idapp,
|
||||
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }]
|
||||
}).sort({ ind_order: 1 });
|
||||
}).sort({ date_added: 1 });
|
||||
let num = 0;
|
||||
|
||||
num += await addUtentiInLista(idapp, 1, arrusers);
|
||||
|
||||
Reference in New Issue
Block a user