This commit is contained in:
paoloar77
2022-02-03 00:33:15 +01:00
parent c391ca85c3
commit daf872fe55
20 changed files with 651 additions and 4831 deletions

View File

@@ -1,362 +0,0 @@
const mongoose = require('mongoose').set('debug', false)
const _ = require('lodash');
const tools = require('../tools/general');
const { ListaIngresso } = require('./listaingresso');
const { Settings } = require('./settings');
const { User } = require('./user');
const { ObjectID } = require('mongodb');
const shared_consts = require('../tools/shared_nodejs');
mongoose.Promise = global.Promise;
mongoose.level = "F";
// Resolving error Unknown modifier: $pushAll
mongoose.plugin(schema => {
schema.options.usePushEach = true
});
mongoose.set('debug', process.env.DEBUG);
const FlottaSchema = new mongoose.Schema({
idapp: {
type: String,
required: true,
},
index: {
type: Number
},
riga: {
type: Number,
},
col_prima: {
type: Number,
},
col_ultima: {
type: Number,
},
date_start: {
type: Date
},
date_close: {
type: Date
},
provvisoria: {
type: Boolean,
},
DoniAttesaDiConferma: {
type: Number,
},
DoniMancanti: {
type: Number,
},
DoniConfermati: {
type: Number,
},
DoniTotali: {
type: Number,
},
note_interne: {
type: String
},
sognatore: {
type: String
},
sognatore_nomecognome: {
type: String
},
link_superchat: {
type: String,
},
link_payment: {
type: String,
},
email_paypal: {
type: String,
},
revolut: {
type: String,
},
payeer_id: {
type: String,
},
advcash_id: {
type: String,
},
note_payment: {
type: String,
},
tutor1: {
type: String,
},
tutor2: {
type: String,
},
tutor3: {
type: String,
},
tutorslo: {
type: String,
},
msg_inviato: {
type: Boolean,
},
});
function getQueryProj(myfilter) {
myobjField = {
_id: 1,
idapp: 1,
lang: 1,
ind_order: 1,
name: 1,
surname: 1,
username: 1,
'profile.paymenttypes': 1,
'profile.email_paypal': 1,
'profile.payeer_id': 1,
'profile.advcash_id': 1,
'profile.revolut': 1,
'profile.cell': 1,
made_gift: 1,
commento_al_sognatore: 1,
sent_msg_howto_make_gift: 1,
date_made_gift: 1,
note: 1,
received_gift: 1,
date_received_gift: 1,
num_tess: 1,
parent_id: 1,
riga: 1,
col: 1,
created: 1,
// date_start: 1,
// date_gift_chat_open: 1,
// link_chat: 1,
// provvisoria: 1,
// note_bot: 1,
// note_interne: 1,
// tutor: 1,
// tutor_namesurname: 1,
};
const query = [
{ $match: myfilter },
{
$lookup: {
from: "listaingressos",
localField: "ind_order",
foreignField: "ind_order", // field in the user collection
as: "mylista"
}
},
{
$replaceRoot: { newRoot: { $mergeObjects: [ { $arrayElemAt: [ "$mylista", 0 ] }, "$$ROOT" ] } }
},
{
$lookup: {
from: "users",
as: "user",
let: {username: '$username' },
pipeline: [
{
$match: {
$expr: {
$and: [
{ $eq: ['$username', '$$username'] },
{ $eq: ['$idapp', myfilter.idapp] },
]
}
}
}
]
}
},
{
$replaceRoot: { newRoot: { $mergeObjects: [{ $arrayElemAt: ["$user", 0] }, "$$ROOT"] } }
// $replaceRoot: { newRoot: { $mergeObjects: [{ $arrayElemAt: ["$user", 0] },] } }
},
{ $project: myobjField }
];
return query;
}
FlottaSchema.statics.findById = function (idapp, id) {
const Flotta = this;
const myquery = getQueryProj({ idapp, '_id': ObjectID(id) });
return Flotta.aggregate(myquery);
};
FlottaSchema.statics.getFieldsForSearch = function () {
return [{ field: 'ind_order', type: tools.FieldType.number },
{ field: 'col', type: tools.FieldType.number }]
};
FlottaSchema.statics.executeQueryTable = function (idapp, params) {
params.fieldsearch = this.getFieldsForSearch();
return tools.executeQueryTable(this, idapp, params);
};
FlottaSchema.statics.findAllIdApp = async function (idapp) {
const Flotta = this;
const myfind = { idapp };
return Flotta.find(myfind).sort({ riga: 1, col: 1 });
};
FlottaSchema.statics.getListaFlotta = function (idapp) {
const Flotta = this;
const myfind = { idapp };
return Flotta.find(myfind).sort({ riga: 1, col_prima: 1 });
};
FlottaSchema.statics.getLastFlotta = function (idapp) {
const Flotta = this;
const myfind = { idapp, date_start: { $lte: tools.IncDateNow(0) }, provvisoria: false };
return Flotta.findOne(myfind).sort({ riga: -1, col_prima: -1 }).limit(1);
};
FlottaSchema.statics.findByRigaColByDonatore = function (idapp, riga, col, offset) {
const Flotta = this;
mypos = {
riga,
col,
numup: 3 + offset,
};
tools.getRigaColByPosUp(mypos);
return Flotta.findOne({ idapp, riga: mypos.riga, col_prima: mypos.col });
};
FlottaSchema.statics.findByRigaCol = function (idapp, riga, col) {
const Flotta = this;
return Flotta.findOne({ idapp, riga, col });
};
FlottaSchema.statics.getLastRigaCol = async function (idapp) {
return Flotta.findOne({ idapp }).sort({ riga: -1, col_prima: -1 });
};
FlottaSchema.statics.getLastRigaColDefinitiva = async function (idapp) {
return Flotta.findOne({ idapp, provvisoria: false }).sort({ riga: -1, col_prima: -1 });
};
FlottaSchema.pre('save', async function (next) {
if (this.isNew) {
const myrec = await Flotta.findOne().limit(1).sort({ _id: -1 });
if (!!myrec) {
this.index = myrec._doc.index + 1;
} else {
this.index = 1;
}
}
next();
});
FlottaSchema.statics.addRecordFlottaByParams = async function (params) {
// Check if Exist:
const giapresente = await Flotta.findOne({
idapp: params.idapp,
riga: params.riga,
col: params.col
});
if (!giapresente) {
// Prende la nave prima:
const lastnave = await Flotta.findOne({idapp}).sort({riga: -1, col: -1});
let nextgiftchat = null;
if (((params.col - 1) % 8 === 0)) {
nextgiftchat = getNextDayNave(lastnave.date_gift_chat_open);
} else {
nextgiftchat = lastnave.date_gift_chat_open;
}
const next_date_start = tools.AddDate(nextgiftchat, 7);
let myFlotta = new Flotta({
idapp: params.idapp,
riga: params.riga,
col: params.col,
riga1don: params.riga1don,
col1don: params.col1don,
date_gift_chat_open: nextgiftchat,
date_start: next_date_start,
provvisoria: true,
});
return await myFlotta.save();
}
return false;
};
FlottaSchema.statics.getFlottaByNavePersistente = async function (idapp, navepers) {
const Flotta = this;
// const indcolflottaprima = tools.getPrimaColFlotta(navepers.col1don + 7);
const myflotta = await Flotta.findOne({ idapp, riga: navepers.riga,
$and: [
{ col_prima: { $lte: navepers.col1don } },
{ col_ultima: { $gte: navepers.col1don } } ]
});
return myflotta;
};
FlottaSchema.statics.getStrFlotta = function (flotta) {
return `Flotta ${flotta.riga}.${Math.ceil(flotta.col_prima / 8)} - ${flotta.riga}.${Math.ceil(flotta.col_ultima / 8)}: Sognatore: ${flotta.sognatore_nomecognome}`;
};
FlottaSchema.statics.getFlottaByRigaColDonatore = async function (idapp, riga, col) {
const Flotta = this;
let mypos = {
idapp,
riga,
col,
numup: 3
};
tools.getRigaColByPosUp(mypos);
const myflotta = await Flotta.findOne({ idapp, riga: mypos.riga,
$and: [
{ col_prima: { $lte: col } },
{ col_ultima: { $gte: col } } ]
});
return myflotta;
};
const Flotta = mongoose.model('Flotta', FlottaSchema);
module.exports = { Flotta };

View File

@@ -8,7 +8,6 @@ const tools = require('../tools/general');
const { ObjectID } = require('mongodb');
const { Nave } = require('./nave');
const { Settings } = require('./settings');
const shared_consts = require('../tools/shared_nodejs');
@@ -192,7 +191,7 @@ GraduatoriaSchema.statics.getFirstUserGradFree = async function (idapp) {
};
/*
GraduatoriaSchema.statics.addSingoloInGraduatoria_InFondo = async function (idapp, recingr) {
const Graduatoria = this;
@@ -200,8 +199,6 @@ GraduatoriaSchema.statics.addSingoloInGraduatoria_InFondo = async function (idap
const arrindex = [];
const { ListaIngresso } = require('../models/listaingresso');
if (!!lastimbarco) {
arrindex[recingr.username] = lastimbarco.indimbarco;
} else {
@@ -223,6 +220,8 @@ GraduatoriaSchema.statics.addSingoloInGraduatoria_InFondo = async function (idap
};
*/
function addRecGraduatoria(idapp, ingr, index) {
try {

File diff suppressed because it is too large Load Diff

253
src/server/models/mygroup.js Executable file
View File

@@ -0,0 +1,253 @@
const mongoose = require('mongoose').set('debug', false);
const Schema = mongoose.Schema;
const tools = require('../tools/general');
mongoose.Promise = global.Promise;
mongoose.level = 'F';
// Resolving error Unknown modifier: $pushAll
mongoose.plugin(schema => {
schema.options.usePushEach = true;
});
const MyGroupSchema = new Schema({
idapp: {
type: String,
},
groupname: {
type: String,
},
title: {
type: String,
},
descr: {
type: String,
},
idSector: {
type: Number,
},
userId: {
type: String,
},
photos: [
{
imagefile: {
type: String,
},
alt: {
type: String,
},
description: {
type: String,
},
}],
idCity: [
{
type: Number,
}],
website: {
type: String,
},
link_telegram: {
type: String,
},
visibility: {
type: Number,
},
admins: [
{
_id: false,
username: {type: String},
date: {type: Date},
},
],
blocked: {
type: Boolean,
},
username_who_block: {
type: String,
},
date_created: {
type: Date,
default: Date.now,
},
date_blocked: {
type: Date,
},
req_users: [
{
_id: false,
username: {type: String},
date: {type: Date},
}], // username
deleted: {
type: Boolean,
default: false,
},
});
MyGroupSchema.statics.getFieldsForSearch = function() {
return [{field: 'descr', type: tools.FieldType.string}];
};
MyGroupSchema.statics.executeQueryTable = function(idapp, params) {
params.fieldsearch = this.getFieldsForSearch();
return tools.executeQueryTable(this, idapp, params);
};
MyGroupSchema.statics.findAllIdApp = async function(idapp) {
const myfind = {idapp};
return await MyGroup.find(myfind);
};
// Rimuovo la Richiesta del Gruppo
MyGroupSchema.statics.removeReqGroup = async function(
idapp, username, groupnameDest) {
const {User} = require('../models/user');
return User.updateOne({idapp, username: username},
{$pull: {'profile.req_groups': {groupname: {$in: [groupnameDest]}}}});
};
function getWhatToShow(idapp, username) {
// ++Todo: MyGroup what to show
return {
groupname: 1,
title: 1,
descr: 1,
visibility: 1,
idSector: 1,
userId: 1,
photos: 1,
idCity: 1,
website: 1,
link_telegram: 1,
admins: 1,
blocked: 1,
};
}
function getWhatToShow_Unknown(idapp, username) {
return {
groupname: 1,
title: 1,
descr: 1,
photos: 1,
visibility: 1,
idSector: 1,
idCity: 1,
};
}
MyGroupSchema.statics.getArrUsernameFromFieldByGroupname = async function(
idapp, groupname, field) {
const {User} = require('../models/user');
const myobj = {};
myobj[field + '.' + subfield] = 1;
let arrrec = await User.findOne({
idapp,
groupname,
$or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}],
}, myobj).then((ris) => ris ? ris._doc[field] : []);
if (arrrec.length > 0) {
return arrrec.map(m => m.username);
}
return [];
};
MyGroupSchema.statics.getUsernameReqGroupsByGroupname = async function(
idapp, groupname) {
return this.getArrUsernameFromFieldByGroupname(idapp, groupname, 'req_users');
};
MyGroupSchema.statics.getInfoGroupByGroupname = async function(
idapp, groupname) {
const whatToShow = getWhatToShow(idapp, groupname);
return MyGroup.findOne({
idapp,
groupname,
}, whatToShow).then((rec) => !!rec ? rec._doc : null);
};
MyGroupSchema.statics.getGroupsByUsername = async function(idapp, username) {
try {
const {User} = require('../models/user');
const whatToShow = getWhatToShow(idapp, username);
const whatToShow_Unknown = getWhatToShow_Unknown(idapp, username);
const arrUsernameGroups = await User.getUsernameGroupsByUsername(idapp,
username);
// const arrUsernameReqGroups = await MyGroup.getUsernameReqGroupsByGroupname(idapp, username);
let listUsersGroup = await User.find({
idapp,
username: {$in: arrUsernameGroups},
$or: [
{deleted: {$exists: false}},
{deleted: {$exists: true, $eq: false}}],
}, whatToShow);
let listgroups = await MyGroup.find({
idapp,
$or: [
{deleted: {$exists: false}},
{deleted: {$exists: true, $eq: false}}],
}, whatToShow_Unknown);
/*let listRequestUsersGroup = await User.find({
idapp,
username: {$in: arrUsernameReqGroups},
$or: [
{deleted: {$exists: false}},
{deleted: {$exists: true, $eq: false}}],
}, whatToShow_Unknown);
*/
let listSentRequestGroups = await MyGroup.find({
idapp,
'req_users': {
$elemMatch: {username: {$eq: username}},
},
$or: [
{deleted: {$exists: false}},
{deleted: {$exists: true, $eq: false}}],
}, whatToShow_Unknown);
return {
listUsersGroup,
listgroups,
//listRequestUsersGroup,
listSentRequestGroups,
};
} catch (e) {
console.log('Error', e);
}
return {
listUsersGroup: [],
listRequestUsersGroup: [],
listTrusted: [],
listSentRequestGroups: [],
};
};
const MyGroup = mongoose.model('MyGroup', MyGroupSchema);
module.exports = {MyGroup};

File diff suppressed because it is too large Load Diff

View File

@@ -1,511 +0,0 @@
const mongoose = require('mongoose').set('debug', false)
const _ = require('lodash');
const tools = require('../tools/general');
const { ListaIngresso } = require('./listaingresso');
const { Settings } = require('./settings');
const { User } = require('./user');
const { Flotta } = require('./flotta');
const { ObjectID } = require('mongodb');
const shared_consts = require('../tools/shared_nodejs');
mongoose.Promise = global.Promise;
mongoose.level = "F";
// Resolving error Unknown modifier: $pushAll
mongoose.plugin(schema => {
schema.options.usePushEach = true
});
mongoose.set('debug', process.env.DEBUG);
const NavePersistenteSchema = new mongoose.Schema({
idapp: {
type: String,
required: true,
},
index: {
type: Number
},
riga: {
type: Number,
},
col: {
type: Number,
},
riga1don: {
type: Number,
},
col1don: {
type: Number,
},
date_start: {
type: Date
},
date_gift_chat_open: {
type: Date
},
link_chat: {
type: String,
},
provvisoria: {
type: Boolean,
},
DoniAttesaDiConferma: {
type: Number,
},
DoniMancanti: {
type: Number,
},
DoniConfermati: {
type: Number,
},
DoniTotali: {
type: Number,
},
note_bot: {
type: String
},
note_interne: {
type: String
},
tutor: {
type: String
},
tutor_namesurname: {
type: String
}
});
function getQueryProj(myfilter) {
myobjField = {
_id: 1,
idapp: 1,
lang: 1,
ind_order: 1,
name: 1,
surname: 1,
username: 1,
'profile.paymenttypes': 1,
'profile.email_paypal': 1,
'profile.revolut': 1,
'profile.link_payment': 1,
'profile.note_payment': 1,
'profile.cell': 1,
made_gift: 1,
sent_msg_howto_make_gift: 1,
date_made_gift: 1,
note: 1,
received_gift: 1,
date_received_gift: 1,
num_tess: 1,
parent_id: 1,
riga: 1,
col: 1,
created: 1,
// date_start: 1,
// date_gift_chat_open: 1,
// link_chat: 1,
// provvisoria: 1,
// note_bot: 1,
// note_interne: 1,
// tutor: 1,
// tutor_namesurname: 1,
};
const query = [
{ $match: myfilter },
{
$lookup: {
from: "listaingressos",
localField: "ind_order",
foreignField: "ind_order", // field in the user collection
as: "mylista"
}
},
{
$replaceRoot: { newRoot: { $mergeObjects: [{ $arrayElemAt: ["$mylista", 0] }, "$$ROOT"] } }
},
{
$lookup: {
from: "users",
as: "user",
let: { username: '$username' },
pipeline: [
{
$match: {
$expr: {
$and: [
{ $eq: ['$username', '$$username'] },
{ $eq: ['$idapp', myfilter.idapp] },
]
}
}
}
]
}
},
{
$replaceRoot: { newRoot: { $mergeObjects: [{ $arrayElemAt: ["$user", 0] }, "$$ROOT"] } }
// $replaceRoot: { newRoot: { $mergeObjects: [{ $arrayElemAt: ["$user", 0] },] } }
},
{ $project: myobjField }
];
return query;
}
NavePersistenteSchema.statics.findById = function (idapp, id) {
const NavePersistente = this;
const myquery = getQueryProj({ idapp, '_id': ObjectID(id) });
return NavePersistente.aggregate(myquery);
};
NavePersistenteSchema.statics.getFieldsForSearch = function () {
return [{ field: 'ind_order', type: tools.FieldType.number },
{ field: 'col', type: tools.FieldType.number }]
};
NavePersistenteSchema.statics.executeQueryTable = function (idapp, params) {
params.fieldsearch = this.getFieldsForSearch();
return tools.executeQueryTable(this, idapp, params);
};
NavePersistenteSchema.statics.findAllIdApp = async function (idapp) {
const NavePersistente = this;
const myfind = { idapp };
return NavePersistente.find(myfind).sort({ riga: 1, col: 1 });
};
NavePersistenteSchema.statics.getListaNavi = function (idapp) {
const NavePersistente = this;
const myfind = { idapp };
return NavePersistente.find(myfind,
{
index: 1,
riga: 1,
col: 1,
riga1don: 1,
col1don: 1,
date_gift_chat_open: 1,
date_start: 1,
provvisoria: 1,
DoniConfermati: 1,
DoniTotali: 1,
DoniMancanti: 1,
}
).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;
mypos = {
riga,
col,
numup: 3 + offset,
};
tools.getRigaColByPosUp(mypos);
return NavePersistente.findOne({ idapp, riga: mypos.riga, col: mypos.col });
};
NavePersistenteSchema.statics.findByRigaCol = function (idapp, riga, col) {
const NavePersistente = this;
return NavePersistente.findOne({ idapp, riga, col });
};
NavePersistenteSchema.statics.getLastRigaCol = async function (idapp) {
const NavePersistente = this;
return NavePersistente.findOne({ idapp }).sort({ riga: -1, col: -1 });
};
NavePersistenteSchema.statics.getLastRigaColDefinitiva = async function (idapp) {
const NavePersistente = this;
return NavePersistente.findOne({ idapp, provvisoria: false }).sort({ riga: -1, col: -1 });
};
NavePersistenteSchema.pre('save', async function (next) {
if (this.isNew) {
const myrec = await NavePersistente.findOne().limit(1).sort({ _id: -1 });
if (!!myrec) {
this.index = myrec._doc.index + 1;
} else {
this.index = 1;
}
}
next();
});
function getNextDayNave(miadata) {
// const dayofweek = [1, 2, 4, 5]; // LUNEDI, MARTEDI', GIOVEDI, VENERDI
const dayofweek = [1, 4]; // LUNEDI, GIOVEDI
let mydate = tools.AddDate(miadata, 1);
while (!dayofweek.includes(mydate.getDay())) {
mydate = tools.AddDate(mydate, 1);
}
return mydate
}
NavePersistenteSchema.statics.addRecordNavePersistenteByParams = async function (params) {
const NavePersistente = this;
// Check if Exist:
const giapresente = await NavePersistente.findOne({
idapp: params.idapp,
riga: params.riga,
col: params.col
});
if (!giapresente) {
// Prende la nave prima:
const lastnave = await NavePersistente.findOne({ idapp: params.idapp }).sort({ riga: -1, col: -1 });
let nextgiftchat = null;
if (((params.col - 1) % 8 === 0)) {
nextgiftchat = getNextDayNave(lastnave.date_gift_chat_open);
} else {
nextgiftchat = lastnave.date_gift_chat_open;
}
const next_date_start = tools.AddDate(nextgiftchat, 7);
let myNavePersistente = new NavePersistente({
idapp: params.idapp,
riga: params.riga,
col: params.col,
riga1don: params.riga1don,
col1don: params.col1don,
date_gift_chat_open: nextgiftchat,
date_start: next_date_start,
provvisoria: true,
});
return await myNavePersistente.save();
}
return false;
};
NavePersistenteSchema.statics.generaFlotte = async function (idapp) {
const NavePersistente = this;
// await Flotta.deleteMany({ idapp });
const arrnavi = await NavePersistente.find({ idapp, col: { $mod: [8, 1] } }).sort({ riga: 1, col: 1 });
let num = 0;
for (const navepers of arrnavi) {
const ris = await NavePersistente.aggiornaFlottaByNavePersistente(idapp, navepers);
if (ris)
num++;
}
return { num }
};
NavePersistenteSchema.statics.changeField = async function (idapp, flotta, fieldvalue) {
let myval = {};
if ('date_close' in fieldvalue) {
myval['date_start'] = fieldvalue['date_close'];
} else if ('date_start' in fieldvalue) {
myval['date_gift_chat_open'] = fieldvalue['date_start'];
} else {
myval = fieldvalue;
}
const ris = await NavePersistente.updateMany({
idapp,
riga: flotta.riga,
$and: [
{ col1don: { $gte: flotta.col_prima } },
{ col1don: { $lte: flotta.col_ultima } },
]
}, { $set: myval });
return ris;
};
NavePersistenteSchema.statics.aggiornaFlottaByNavePersistente = async function (idapp, naveinput) {
const { Nave } = require('../models/nave');
const { User } = require('./user');
const { Flotta } = require('./flotta');
let num = 0;
try {
let nuovo = false;
// let primacol = false;
indcolflottaprima = tools.getPrimaColFlotta(naveinput.col1don + 7);
console.log(num, ' -> [', naveinput.riga, '.', naveinput.col1don, '] indcolflottaprima=', indcolflottaprima);
let ini = Math.ceil(indcolflottaprima / 8);
let fine = ini + 7;
const arrnavi = await NavePersistente.find({
idapp,
riga: naveinput.riga,
$and: [{ col: { $gte: ini } }, { col: { $lte: fine } }]
}).sort({ riga: 1, col: 1 });
let primogiro = true;
let myflotta = await Flotta.findOne({ idapp, riga: naveinput.riga, col_prima: indcolflottaprima });
if (!myflotta) {
myflotta = new Flotta({
_id: new ObjectID(),
idapp,
});
nuovo = true;
}
for (const navepers of arrnavi) {
if (primogiro) {
myflotta.DoniAttesaDiConferma = 0;
myflotta.DoniMancanti = 0;
myflotta.DoniConfermati = 0;
myflotta.DoniTotali = 0;
primogiro = false;
}
if (nuovo) {
myflotta.riga = navepers.riga;
myflotta.col_prima = indcolflottaprima;
myflotta.col_ultima = indcolflottaprima + 63;
myflotta.sognatore = '';
myflotta.sognatore_nomecognome = '';
myflotta.link_superchat = '';
myflotta.msg_inviato = false;
}
myflotta.date_start = navepers.date_gift_chat_open;
myflotta.date_close = navepers.date_start;
let sognatore = await Nave.getSognatoreByRigaColMediatore(idapp, { riga: navepers.riga, col: navepers.col });
if (myflotta.sognatore_nomecognome === '') {
myflotta.sognatore = sognatore.username;
if (!!sognatore.username)
myflotta.sognatore_nomecognome = await User.getNameSurnameByUsername(idapp, sognatore.username);
}
if (nuovo) {
myflotta.email_paypal = '';
myflotta.payeer_id = '';
myflotta.advcash_id = '';
myflotta.revolut = '';
myflotta.link_payment = '';
myflotta.note_payment = '';
if (!!sognatore) {
myflotta.email_paypal = sognatore.profile.email_paypal;
myflotta.payeer_id = sognatore.profile.payeer_id;
myflotta.advcash_id = sognatore.profile.advcash_id;
myflotta.revolut = sognatore.profile.revolut;
myflotta.link_payment = sognatore.profile.link_payment;
myflotta.note_payment = sognatore.profile.note_payment;
}
}
if (!!sognatore) {
if (!myflotta.email_paypal)
myflotta.email_paypal = sognatore.profile.email_paypal;
if (!myflotta.payeer_id)
myflotta.payeer_id = sognatore.profile.payeer_id;
if (!myflotta.advcash_id)
myflotta.advcash_id = sognatore.profile.advcash_id;
if (!myflotta.revolut)
myflotta.revolut = sognatore.profile.revolut;
if (!myflotta.link_payment)
myflotta.link_payment = sognatore.profile.link_payment;
if (!myflotta.note_payment)
myflotta.note_payment = sognatore.profile.note_payment;
}
myflotta.provvisoria = navepers.provvisoria;
if (!!navepers.DoniAttesaDiConferma && !isNaN(navepers.DoniAttesaDiConferma))
myflotta.DoniAttesaDiConferma += navepers.DoniAttesaDiConferma;
if (!!navepers.DoniMancanti && !isNaN(navepers.DoniMancanti))
myflotta.DoniMancanti += navepers.DoniMancanti;
if (!!navepers.DoniConfermati && !isNaN(navepers.DoniConfermati))
myflotta.DoniConfermati += navepers.DoniConfermati;
if (!!navepers.DoniTotali && !isNaN(navepers.DoniTotali))
myflotta.DoniTotali += navepers.DoniTotali;
}
await myflotta.save();
return true;
} catch (e) {
console.log(e.message);
return false;
}
};
const NavePersistente = mongoose.model('NavePersistente', NavePersistenteSchema);
module.exports = { NavePersistente };

View File

@@ -6,14 +6,15 @@ const _ = require('lodash');
const tools = require('../tools/general');
const {Flotta} = require('../models/flotta');
const {Settings} = require('../models/settings');
const {ListaIngresso} = require('../models/listaingresso');
// const {ListaIngresso} = require('../models/listaingresso');
const {Graduatoria} = require('../models/graduatoria');
const {Nave} = require('../models/nave');
const {NavePersistente} = require('../models/navepersistente');
// const {Nave} = require('../models/nave');
// const {NavePersistente} = require('../models/navepersistente');
// const { ExtraList } = require('../models/extralist');
const {MyGroup} = require('../models/mygroup');
const {ObjectID} = require('mongodb');
const shared_consts = require('../tools/shared_nodejs');
@@ -341,6 +342,12 @@ const UserSchema = new mongoose.Schema({
username: {type: String},
date: {type: Date},
}], // username
groups: [
{
_id: false,
groupname: {type: String},
date: {type: Date},
}], // username
},
})
;
@@ -657,12 +664,9 @@ UserSchema.statics.getUserShortDataByUsername = async function(
if (myrec) {
myrec.qualified = await User.isUserQualified7(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);
myrec.numNaviEntrato = 0;
// myrec.numinvitati = await ListaIngresso.getnumInvitati(idapp, myrec.username);
// myrec.numinvitatiattivi = await ListaIngresso.getnumInvitatiAttivi(idapp, myrec.username);
}
return myrec;
@@ -674,37 +678,7 @@ UserSchema.statics.getDownlineByUsername = async function(
if (username === undefined)
return null;
let arrrec = await ListaIngresso.getInvitati(idapp, username, includemyself,
{
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.ask_zoom_partecipato': 1,
'profile.qualified': 1,
'profile.qualified_2invitati': 1,
'profile.saw_and_accepted': 1,
'profile.email_paypal': 1,
'profile.payeer_id': 1,
'profile.advcash_id': 1,
'profile.revolut': 1,
'profile.link_payment': 1,
'profile.note_payment': 1,
// 'profile.my_dream': 1,
'profile.paymenttypes': 1,
'profile.cell': 1,
made_gift: 1,
email: 1,
date_reg: 1,
img: 1,
},
);
let arrrec = [];
let myq = {
idapp,
@@ -716,44 +690,6 @@ UserSchema.statics.getDownlineByUsername = async function(
myq = {...myq, username: {$ne: username}};
}
// Ottieni gli invitati che ancora non hanno un'imbarco
const arrinv = await User.find(myq);
for (const inv of arrinv) {
if (!arrrec.find((rec) => rec.username === inv.username))
arrrec.push(inv._doc);
}
const arrusername = [];
for (const inv of arrrec) {
const rectrovato = arrusername.find((rec) => inv.username === rec.username);
if (!!rectrovato) {
rectrovato.quanti++;
} else {
const myrec = {...inv};
myrec.quanti = 1;
arrusername.push(myrec);
}
}
arrrec = arrusername;
if (!onlynumber) {
if (!!arrrec) {
for (const rec of arrrec) {
rec.qualified = await User.isUserQualified7(idapp, rec.username);
rec.numNaviEntrato = await Nave.getnumNaviByUsername(idapp,
rec.username);
rec.numinvitati = await ListaIngresso.getnumInvitati(idapp,
rec.username);
rec.numinvitatiattivi = await ListaIngresso.getnumInvitatiAttivi(idapp,
rec.username);
}
}
}
return arrrec;
};
@@ -961,6 +897,7 @@ UserSchema.statics.setUserQualified_2Invitati = async function(
return !!myrec;
};
/*
UserSchema.statics.isUserQualified9 = async function(idapp, username) {
const User = this;
@@ -968,11 +905,12 @@ UserSchema.statics.isUserQualified9 = async function(idapp, username) {
return false;
qualified = await User.isUserQualified7(idapp, username);
numinvitatiattivi = await ListaIngresso.getnumInvitatiAttivi(idapp, username);
// numinvitatiattivi = await ListaIngresso.getnumInvitatiAttivi(idapp, username);
return qualified && (numinvitatiattivi >= 2);
};
*/
/*
UserSchema.statics.getnumPaymentOk = function (idapp) {
@@ -1201,6 +1139,16 @@ UserSchema.statics.getUserById = function(idapp, id) {
});
};
UserSchema.statics.getUserByUsername = function(idapp, username) {
const User = this;
return User.findOne({
idapp,
username,
$or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}],
});
};
UserSchema.statics.isMyFriend = async function(idapp, username, myusername) {
const myfriends = await User.getUsernameFriendsByUsername(idapp, myusername);
@@ -1337,11 +1285,11 @@ UserSchema.statics.getArrUsernameFromFieldByUsername = async function(
UserSchema.statics.getUsernameReqFriendsByUsername = async function(
idapp, username) {
return this.getArrUsernameFromFieldByUsername(idapp, username, 'profile',
'req_friends');
return this.getArrUsernameFromFieldByUsername(idapp, username, 'profile', 'req_friends');
};
UserSchema.statics.getUsernameFriendsByUsername = async function(
idapp, username) {
@@ -1350,12 +1298,25 @@ UserSchema.statics.getUsernameFriendsByUsername = async function(
};
UserSchema.statics.getUsernameGroupsByUsername = async function(
idapp, username) {
return this.getArrUsernameFromFieldByUsername(idapp, username, 'profile', 'groups');
};
// Rimuovo l'Amicizia
UserSchema.statics.removeFriend = async function(idapp, username, usernameDest) {
return User.updateOne({idapp, username},
{$pull: {'profile.friends': {username: {$in: [usernameDest]}}}});
};
// Rimuovo il Gruppo
UserSchema.statics.removeFromMyGroups = async function(idapp, username, groupnameDest) {
return User.updateOne({idapp, username},
{$pull: {'profile.groups': {groupname: {$in: [groupnameDest]}}}});
};
// Rimuovo la Richiesta di Amicizia
UserSchema.statics.removeReqFriend = async function(idapp, username, usernameDest) {
return User.updateOne({idapp, username: username},
@@ -1496,8 +1457,106 @@ UserSchema.statics.setFriendsCmd = async function(
return ris;
};
UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameDest, cmd, value) {
let ris = null;
let update = {};
try {
if (cmd === shared_consts.GROUPSCMD.SETGROUP) {
// Aggiungo l'Amicizia a me
const foundIfAlreadyGroup = await User.findOne({
idapp,
username: usernameOrig,
'profile.groups': {
$elemMatch: {groupname: {$eq: groupnameDest}},
},
});
if (!foundIfAlreadyGroup) {
update = {
$push: {
'profile.groups': {
groupname: groupnameDest,
date: new Date(),
},
},
};
ris = await User.updateOne({idapp, username: usernameOrig}, update);
update = {$pull: {'profile.req_groups': {groupname: {$in: [groupnameDest]}}}};
ris = await User.updateOne({idapp, username: usernameOrig}, update);
}
if (ris) {
ris = await MyGroup.getInfoGroupByGroupname(idapp, groupnameDest);
}
} else if (cmd === shared_consts.GROUPSCMD.REQGROUP) {
// Aggiungo la richiesta di Amicizia a me
const foundIfAlreadyAskGroup = await MyGroup.findOne({
idapp,
groupname: groupnameDest,
'req_groups': {
$elemMatch: { username: {$eq: usernameOrig}},
},
});
if (value) {
if (!foundIfAlreadyAskGroup) {
update = {
$push: {
'profile.req_groups': {
username: usernameOrig,
date: new Date(),
},
},
};
ris = await User.updateOne({idapp, username: groupnameDest}, update);
}
if (ris) {
// Invia una notifica alla persona
tools.sendNotificationByGroupName(idapp, groupnameDest, cmd, true);
}
} else {
if (foundIfAlreadyAskGroup) {
ris = await this.removeFromMyGroups(idapp, groupnameDest, usernameOrig); // Rimuovo l'Amicizia da me
}
}
if (ris) {
ris = await User.getInfoAskGroupByUsername(idapp, groupnameDest);
}
} else if (cmd === shared_consts.GROUPSCMD.REMOVE_FROM_MYGROUPS) {
ris = await this.removeFromMyGroups(idapp, usernameOrig, groupnameDest); // Rimuovo l'Amicizia da me
} else if (cmd === shared_consts.GROUPSCMD.CANCEL_REQ_GROUP) {
ris = await MyGroup.removeReqGroup(idapp, usernameOrig, groupnameDest); // Rimuovo l'Amicizia da me
} else if (cmd === shared_consts.GROUPSCMD.BLOCK_GROUP) {
await this.removeFromMyGroups(idapp, usernameOrig, groupnameDest); // Rimuovo l'Amicizia da me
// Blocco il Gruppo
ris = await MyGroup.updateOne({idapp, username: groupnameDest}, {
$set: {
blocked: true,
username_who_block: usernameOrig,
date_blocked: new Date(),
},
});
//++Todo: Send Notification to Admin and Group's manager
}
} catch (e) {
console.error('Error: ', e);
}
return ris;
};
function getWhatToShow(idapp, username) {
//++Todo: check which data to show
return {
username: 1,
aportador_solidario: 1,
@@ -1841,6 +1900,8 @@ UserSchema.statics.getNameSurnameById = async function(idapp, userId) {
UserSchema.statics.getSmallRecByIndOrder = async function(idapp, ind_order) {
try {
const rec = {};
/*
const rec = await ListaIngresso.getarray(idapp,
{
idapp,
@@ -1864,6 +1925,8 @@ UserSchema.statics.getSmallRecByIndOrder = async function(idapp, ind_order) {
if (!!rec)
return rec[0];
*/
return null;
} catch (e) {
@@ -1889,7 +1952,7 @@ UserSchema.statics.getRecByIndOrder = async function(idapp, ind_order) {
const User = this;
try {
/*
let filters = {
idapp: 1,
index: 1,
@@ -1920,6 +1983,8 @@ UserSchema.statics.getRecByIndOrder = async function(idapp, ind_order) {
if (!!rec)
return rec[0];
*/
return null;
} catch (e) {
@@ -2147,99 +2212,6 @@ UserSchema.statics.getDashboard = async function(
if (!!arrap)
dashboard.numpeople_aportador = arrap.length;
dashboard.arrimbarchi = await ListaIngresso.findAllByUsername(idapp,
username);
// dashboard.arrprofili = await Nave.getArrProfiliByIndOrder(idapp, dashboard.myself.ind_order);
dashboard.arrposizioni = await Nave.getArrPosizioniByUsername(idapp,
username);
/* let arrrec = [];
if (dashboard.arrimbarchi.length > 0) {
arrrec = await ListaIngresso.getProssimiInLista(idapp, true);
}*/
for (let myimbarco of dashboard.arrimbarchi) {
if (!!myimbarco.invitante_username)
dashboard.arrusers[myimbarco.invitante_username] = await User.getUserShortDataByUsername(
idapp, myimbarco.invitante_username);
myimbarco._doc.posiz = await Graduatoria.getPosizioneInGraduatoria(idapp,
myimbarco.ind_order, myimbarco.username, myimbarco.num_tess);
}
dashboard.navi_partenza = await NavePersistente.getListaNavi(idapp);
dashboard.lastnave = await NavePersistente.getLastNave(idapp);
for (let mypos of dashboard.arrposizioni) {
mypos.rec = await Nave.getNaveByRigaCol(idapp, mypos.riga, mypos.col);
mypos.nave_partenza = await NavePersistente.findByRigaColByDonatore(idapp,
mypos.riga, mypos.col, 0);
if (!!mypos.nave_partenza)
mypos.flotta = await Flotta.getFlottaByNavePersistente(idapp,
mypos.nave_partenza);
}
//for (let indriga = 0; indriga < 10; indriga++) {
// dashboard.navi_partenza.push(await Nave.getPrimaNaveByRiga(idapp, indriga));
//}
const arrnew = [];
try {
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 &&
(myrec.ind_order === mypos.ind_order)) {
// La Nave di Ritorno (numtess = 2) esiste nella lista !
trovato = true;
break;
}
}
} else {
trovato = true;
}
if (!trovato) {
let myr = null;
if (!!mypos._doc)
myr = mypos._doc;
else
myr = mypos;
if (!!myr && !!myr.rec.mediatore) {
const mymediatore = myr.rec.mediatore.arrdonatori[7];
if (!!mymediatore) {
const myrec = {
riga: mymediatore.riga,
col: mymediatore.col,
name: myr.rec.mediatore.recmediatore.name,
surname: myr.rec.mediatore.recmediatore.surname,
username: myr.rec.mediatore.recmediatore.username,
num_tess: myr.rec.mediatore.recmediatore.num_tess + 1,
rec: await Nave.getNaveByRigaCol(idapp, mymediatore.riga,
mymediatore.col),
nave_partenza: {},
};
myrec.nave_partenza = await NavePersistente.findByRigaColByDonatore(
idapp, myrec.riga, myrec.col, 0);
arrnew.push(myrec);
}
}
}
}
} catch (e) {
console.error(e.message);
}
dashboard.arrposizioni = [...dashboard.arrposizioni, ...arrnew];
// console.table(dashboard.arrnavi);
return dashboard;
@@ -2377,131 +2349,6 @@ UserSchema.statics.getUsersQualified = async function (idapp, numinvitati) {
};
*/
UserSchema.statics.visuUtentiNonInNavi = async function(idapp) {
const User = this;
const arrusers = await User.find({
idapp,
$and: User.getQueryQualified(),
}, {
name: 1,
surname: 1,
username: 1,
ind_order: 1,
deleted: 1,
sospeso: 1,
});
let num = 0;
let innave = 0;
let noninnave = 0;
let mystr = 'visuUtentiNonInNavi: ' + tools.ACAPO;
let reg = 0;
let num0inv = 0;
let num1inv = 0;
let num2inv = 0;
let numnoinlista = 0;
let numeliminati = 0;
let numsospesi = 0;
let strnavidoppie = '';
let esiste = false;
for (const user of arrusers) {
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 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});
let trovato = false;
if (!mianave)
visualizza = true;
if (visualizza) {
mystr += user.username + ' ' + user.name + ' ' + user.surname + ' [' +
user.index + '] [inv=' + user.numinvitati + ']';
trovato = true;
}
if (strnavidoppie.length > 1) {
mystr += ' NAVI DUPLICATE! ' + strnavidoppie.join(',');
}
if (!mianave)
noninnave++;
else
innave++;
if (user.sospeso) {
numsospesi++;
}
if (!mialistaingresso) {
mystr += ' NO IN LISTA INGRESSO!';
trovato = true;
numnoinlista++;
}
if (trovato)
mystr += tools.ACAPO;
if (user.numinvitati === 0) {
num0inv++;
}
if (user.numinvitati === 1) {
num1inv++;
}
if (user.numinvitati >= 2) {
num2inv++;
}
}
}
mystrstart = 'Registrati: ' + reg + tools.ACAPO;
mystrstart += '0 Invitati: ' + num0inv + tools.ACAPO;
mystrstart += '1 Invitato: ' + num1inv + tools.ACAPO;
mystrstart += '2 o più Invitati: ' + num2inv + tools.ACAPO;
mystrstart += 'Presente in Nave: ' + innave + tools.ACAPO;
mystrstart += 'Non in Nave: ' + noninnave + tools.ACAPO;
mystrstart += 'Non in Lista Imbarco: ' + numnoinlista + tools.ACAPO;
mystrstart += 'Usciti (Nascosti): ' + numeliminati + tools.ACAPO;
mystrstart += 'Sospesi: ' + numsospesi + tools.ACAPO;
mystrstart += tools.ACAPO;
mystr = mystrstart + mystr;
return {num, mystr};
};
// UserSchema.statics.getNumUsersQualified = async function (idapp, numinvitati) {
//
@@ -2639,12 +2486,15 @@ UserSchema.statics.checkUser = async function(idapp, username) {
UserSchema.statics.calculateStat = async function(idapp, username) {
const User = this;
/*
return calcstat = {
numinvitati: await ListaIngresso.getnumInvitati(idapp, username),
numinvitati_attivi: await ListaIngresso.getnumInvitatiAttivi(idapp,
username),
};
*/
};
UserSchema.statics.getDistinctNationalityQuery = function(idapp) {
@@ -2804,44 +2654,6 @@ if (tools.INITDB_FIRSTIME) {
// UserSchema.index({ surname: 1 });
}
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 ListaIngresso.getnumInvitatiAttivi(idapp,
rec.username);
let numinvitati = await ListaIngresso.getnumInvitati(idapp, rec.username);
if (rec.profile.special_req) {
numinvitatiattivi = 2;
}
if (mode === 1) {
// 9 punti qualificati
ok = qualified && (numinvitatiattivi >= 2);
} else if (mode === 2) {
// 8 punti qualificati ( 1 Invitato)
ok = qualified && (numinvitati === 2);
} else if (mode === 3) {
ok = qualified && (numinvitatiattivi === 1);
} else if (mode === 4) {
ok = qualified && (numinvitati === 1);
} else if (mode === 5) {
ok = qualified;
}
if (ok) {
ris = await ListaIngresso.addUserInListaIngresso(idapp, rec.username,
rec.aportador_solidario, rec.lang, false, true);
if (!!ris)
num++;
}
}
return num;
}
UserSchema.statics.getUsernameByIndOrder = async function(idapp, ind_order) {
@@ -2886,85 +2698,11 @@ UserSchema.statics.ricalcolaIndex = async function(idapp) {
};
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 } });
await ListaIngresso.findByIdAndUpdate(rec_ingr._id,
{$set: {invitante_username}});
}
};
UserSchema.statics.NessunaNavePresenteByUsername = async function(
idapp, username) {
const User = this;
const rec = await User.findOne({idapp, username},
{username: 1, ind_order: 1});
if (!!rec) {
// Controlla se è qualificato!
const qualified = await User.isUserQualified7(idapp, rec.username);
if (qualified) {
// Ha un'imbarco almeno?
const arrimbarchi = await ListaIngresso.findOne({
idapp, username: rec.username,
$or: [
{deleted: {$exists: false}},
{deleted: {$exists: true, $eq: false}}],
});
const arrnavi = await Nave.findOne({
idapp, ind_order: rec.old_order,
});
if (!arrimbarchi && !arrnavi) {
// NEANCHE 1 !
const recout = await User.findOneAndUpdate({
idapp,
username,
}, {$set: {navinonpresenti: true}}, {new: false});
return (!!recout);
}
}
}
return false;
};
UserSchema.statics.getInfoUser = async function(idapp, username) {
return {
username,
is7req: await User.isUserQualified7(idapp, username),
is9req: await User.isUserQualified9(idapp, username),
// is9req: await User.isUserQualified9(idapp, username),
};
};
@@ -2978,37 +2716,15 @@ UserSchema.statics.checkIfSbloccatiRequisiti = async function(
if (!allData.myuser)
return false;
if (await Nave.checkIfNaveExist(idapp, allData.myuser.username)) {
// Se già sei dentro la Nave, allora sei OK
return true; //TOGLEREE
}
//if (await Nave.checkIfNaveExist(idapp, allData.myuser.username)) {
// // Se già sei dentro la Nave, allora sei OK
// return true; //TOGLEREE
//}
// Controlla se Sblocca i 7 requisiti
const is7req = await User.isUserQualified7(idapp, allData.myuser.username);
const is9req = await User.isUserQualified9(idapp, allData.myuser.username);
const userlista = await ListaIngresso.getListaTessByUsername(idapp,
allData.myuser.username);
//if (userlista.length > 0) { //TOGLIERE
if (userlista.length === 0) {
// Se non sono ancora dentro alla lista, allora controllo
if (!!allData.precDataUser) {
if ((!allData.precDataUser.is7req && is7req) &&
!await User.isUserAlreadyQualified(idapp, allData.myuser.username)) {
await User.setUserQualified(idapp, allData.myuser.username);
// ORA HAI I 7 REQUISITI !
// const msgtext = telegrambot.getCiao(idapp, allData.myuser.username, allData.myuser.lang) + tools.gettranslate('HAI_I_7_REQUISITI', allData.myuser.lang);
// telegrambot.sendMsgTelegram(idapp, allData.myuser.username, msgtext, true); // Anche a STAFF
// Aggiungilo alla ListaIngresso
risingr = await ListaIngresso.addUserInListaIngresso(idapp,
allData.myuser.username, allData.myuser.aportador_iniziale,
allData.myuser.lang, true, false);
}
}
}
const is9req = false;
// const is9req = await User.isUserQualified9(idapp, allData.myuser.username);
if (!!allData.precDataUser) {
if ((!allData.precDataUser.is9req && is9req) &&
@@ -3107,57 +2823,6 @@ UserSchema.statics.mettiSognoePaypal = async function(idapp, modifica) {
};
UserSchema.statics.flagUtentiNaviNonPresenti = async function(idapp) {
const User = this;
let num = 0;
await User.updateMany({idapp}, {$set: {navinonpresenti: false}});
arrusers = await User.find({
'idapp': idapp,
$or: [
{deleted: {$exists: false}},
{deleted: {$exists: true, $eq: false}},
{subaccount: {$exists: false}},
{subaccount: {$exists: true, $eq: false}}],
});
for (const rec of arrusers) {
const nessunanave = await User.NessunaNavePresenteByUsername(idapp,
rec.username);
if (nessunanave)
num++;
}
return {num};
};
UserSchema.statics.addNavePerUtentiNaviNonPresenti = async function(idapp) {
const User = this;
let num = 0;
arrusers = await User.find({
'idapp': idapp,
navinonpresenti: true,
});
for (const user of arrusers) {
// Controlla se è qualificato!
mydata = tools.AddDate(user.date_reg, 7);
const newrecingr = await ListaIngresso.addUserInListaIngresso(idapp,
user.username, user.aportador_solidario, user.lang, true, true, mydata);
await tools.snooze(1000);
num++;
}
return {num};
};
UserSchema.statics.convSubAccount = async function(idapp) {
const User = this;
@@ -3269,6 +2934,18 @@ UserSchema.statics.addExtraInfo = async function(idapp, recUser) {
}, {username: 1});
recUser._doc.profile.asked_friends = listSentMyRequestFriends ? listSentMyRequestFriends : [];
const listSentMyRequestGroups = await User.find({
idapp,
'profile.req_groups': {
$elemMatch: {username: {$eq: recUser.username}},
},
$or: [
{deleted: {$exists: false}},
{deleted: {$exists: true, $eq: false}}],
}, {username: 1});
recUser._doc.profile.asked_groups = listSentMyRequestGroups ? listSentMyRequestGroups : [];
}catch (e){
console.error('Err', e);
}