- Nuovo Sistema di Flotte per Tutor.

X - Mettere anche la email del sognatore, per chi è abituato ad inviarla in quel modo...
X - Controllare che sul sito compaiano le informazioni del Sognatore...
This commit is contained in:
Paolo Arena
2020-06-08 13:31:05 +02:00
parent 591dd46723
commit 92d426c3a6
21 changed files with 2037 additions and 254 deletions

325
src/server/models/flotta.js Executable file
View File

@@ -0,0 +1,325 @@
const mongoose = require('mongoose');
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,
},
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.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 = 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;
};
const Flotta = mongoose.model('Flotta', FlottaSchema);
module.exports = { Flotta };

View File

@@ -78,6 +78,12 @@ const GraduatoriaSchema = new mongoose.Schema({
invitante_username: {
type: String,
},
navestr: {
type: String,
},
note: {
type: String,
},
date_added: { // Data d'Ingresso (Completato i Requisiti o premuto Bottone Magico)
type: Date,
},
@@ -197,11 +203,15 @@ GraduatoriaSchema.statics.addSingoloInGraduatoria_InFondo = async function (idap
const { ListaIngresso } = require('../models/listaingresso');
arrindex[recingr.username] = lastimbarco.indimbarco;
if (!!lastimbarco) {
arrindex[recingr.username] = lastimbarco.indimbarco;
} else {
arrindex[recingr.username] = 1;
}
const newingr = await ListaIngresso.aggiornaRecListaIngr(idapp, recingr, arrindex);
const myrectoadd = addRecGraduatoria(idapp, newingr);
const myrectoadd = addRecGraduatoria(idapp, newingr, 100000);
return await myrectoadd.save(myrectoadd)
.then((ris) => {
@@ -211,6 +221,7 @@ GraduatoriaSchema.statics.addSingoloInGraduatoria_InFondo = async function (idap
console.error(e.message);
});
};
function addRecGraduatoria(idapp, ingr, index) {
@@ -233,6 +244,8 @@ function addRecGraduatoria(idapp, ingr, index) {
numinvitatiattiviTot: ingr.numinvitatiattiviTot,
punteggio: ingr.punteggio,
invitante_username: ingr.invitante_username,
navestr: ingr.navestr,
note: ingr.note,
date_added: ingr.date_added,
});
@@ -312,12 +325,24 @@ GraduatoriaSchema.statics.isWorking = function (idapp) {
};
GraduatoriaSchema.statics.isUpdating = function (idapp) {
return Settings.getValDbSettings(idapp, tools.UPDATE_GRADUATORIA, false);
};
GraduatoriaSchema.statics.setWorking = function (idapp, stato) {
return Settings.setBool(idapp, 'GRAD_WORK', stato);
};
GraduatoriaSchema.statics.setGradUpdating = function (idapp, stato) {
return Settings.setBool(idapp, tools.UPDATE_GRADUATORIA, stato);
};
function getinvit(index, myrec) {
let inv = myrec.numinvitati;
let invattivi = myrec.numinvitatiattivi;

View File

@@ -54,6 +54,9 @@ const ListaIngressoSchema = new mongoose.Schema({
num_tess: {
type: Number,
},
navestr: {
type: String,
},
note: {
type: String,
},
@@ -614,8 +617,8 @@ ListaIngressoSchema.statics.GeneraGraduatoria = async function (idapp, solonuovi
let myquery = '';
//++Todo: DA TOGLIERE IL COMMENTO !!!
// if (await Graduatoria.isWorking(idapp))
// return;
if (await Graduatoria.isWorking(idapp))
return;
await Graduatoria.setWorking(idapp, true);
@@ -627,6 +630,7 @@ ListaIngressoSchema.statics.GeneraGraduatoria = async function (idapp, solonuovi
surname: 1,
username: 1,
invitante_username: 1,
navestr: 1,
email: 1,
lang: 1,
num_tess: 1,
@@ -638,8 +642,13 @@ ListaIngressoSchema.statics.GeneraGraduatoria = async function (idapp, solonuovi
try {
let myfilter2 = {
surname: { $exists: true },
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
$or: [{ surname: { $exists: true } }, { deleted: { $exists: false } }, {
deleted: {
$exists: true,
$eq: false
}
}],
};
if (solonuovi) {
@@ -931,8 +940,13 @@ ListaIngressoSchema.statics.getarray = async function (idapp, filtri, myobjField
let myfilter2 = {
surname: { $exists: true },
$or: [{ 'user.deleted': { $exists: false } }, { 'user.deleted': { $exists: true, $eq: false } }],
$or: [{ surname: { $exists: true } }, { 'user.deleted': { $exists: false } }, {
'user.deleted': {
$exists: true,
$eq: false
}
}],
};
let myquery = getQueryProj(
@@ -949,8 +963,8 @@ ListaIngressoSchema.statics.getarrayIndOrder = async function (idapp, filtri, my
const ListaIngresso = this;
let myfilter2 = {
surname: { $exists: true },
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
$or: [{ surname: { $exists: true } }, { deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
};
let myquery = getQueryIndOrder(
@@ -973,7 +987,8 @@ ListaIngressoSchema.statics.getIngrEUserByFilter = async function (idapp, myfilt
ind_order: 1,
name: 1,
surname: 1,
index: 1
index: 1,
num_tess: 1
});
if (!!arr) {
@@ -989,7 +1004,7 @@ ListaIngressoSchema.statics.getInvitati = async function (idapp, username, inclu
let myq = {
idapp,
$or: [{ 'user.deleted': { $exists: false } }, { 'user.deleted': { $exists: true, $eq: false } }],
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
invitante_username: username,
};
@@ -1043,7 +1058,7 @@ ListaIngressoSchema.statics.getnumInvitatiBase = async function (idapp, username
idapp,
invitante_username: username,
// username: { $ne: username },
$or: [{ 'user.deleted': { $exists: false } }, { 'user.deleted': { $exists: true, $eq: false } }],
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
},
{ username: 1, ind_order: 1 },
myfilter2,
@@ -1058,7 +1073,7 @@ ListaIngressoSchema.statics.getnumInvitatiBase = async function (idapp, username
idapp,
aportador_solidario: username,
//$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
$or: [{ 'user.deleted': { $exists: false } }, { 'user.deleted': { $exists: true, $eq: false } }],
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
};
if (attivi) {
@@ -1114,13 +1129,37 @@ ListaIngressoSchema.statics.getnumInvitati = async function (idapp, username) {
};
ListaIngressoSchema.statics.Esegui_CronTab = async function (idapp) {
ListaIngressoSchema.statics.Esegui_CronTab = async function (idapp, mydata) {
const ListaIngresso = this;
console.log('Lancia CronTab: [IDAPP=' + idapp + ']');
await ListaIngresso.GeneraGraduatoria(idapp, true);
let num = 0;
try {
if (!await Graduatoria.isUpdating()) {
await Graduatoria.setGradUpdating(idapp, true);
ris = await Nave.delNaviProvvisorie(idapp);
mystr = await ListaIngresso.GeneraGraduatoria(idapp, true);
await Graduatoria.setWorking(idapp, false);
num = await Nave.generaNave(idapp, mydata, false);
}
} catch (e) {
console.error('ERRORE CronTab: [IDAPP=' + idapp + ']', e.message);
} finally {
await Graduatoria.setGradUpdating(idapp, false);
await Graduatoria.setWorking(idapp, false);
console.log('FINE CronTab: [IDAPP=' + idapp + ']');
}
return num;
};
ListaIngressoSchema.statics.getnumInvitatiAttivi = function (idapp, username) {

102
src/server/models/msg_template.js Executable file
View File

@@ -0,0 +1,102 @@
const mongoose = require('mongoose');
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 MsgTemplateSchema = new Schema({
idapp: {
type: String,
},
typemsg: {
type: Number,
},
title: {
type: String,
},
title_it: {
type: String,
},
msg_it: {
type: String,
},
title_enUs: {
type: String,
},
msg_enUs: {
type: String,
},
title_si: {
type: String,
},
msg_si: {
type: String,
},
title_fr: {
type: String,
},
msg_fr: {
type: String,
},
title_es: {
type: String,
},
msg_es: {
type: String,
},
title_pt: {
type: String,
},
msg_pt: {
type: String,
},
});
MsgTemplateSchema.statics.getFieldsForSearch = function () {
return [{ field: 'title', type: tools.FieldType.string },
]
};
MsgTemplateSchema.statics.executeQueryTable = function (idapp, params) {
params.fieldsearch = this.getFieldsForSearch();
return tools.executeQueryTable(this, idapp, params);
};
MsgTemplateSchema.statics.getMsgByLang = async function (idapp, typemsg, lang) {
const MsgTemplate = this;
try {
const mymsg = await MsgTemplate.findOne({ idapp, typemsg });
if (!!mymsg) {
if ((!!mymsg["msg_" + lang]) && (!!mymsg["title_" + lang])) {
return { body: mymsg["msg_" + lang], title: mymsg["title_" + lang] }
}
}
} catch (e) {
return { body: '', title: '' };
}
return { body: '', title: '' };
};
MsgTemplateSchema.statics.findAllIdApp = async function (idapp) {
const MsgTemplate = this;
const myfind = { idapp };
return await MsgTemplate.find(myfind, (err, arrrec) => {
return arrrec
});
};
const MsgTemplate = mongoose.model('MsgTemplate', MsgTemplateSchema);
module.exports = { MsgTemplate };

View File

@@ -7,6 +7,7 @@ const { ListaIngresso } = require('./listaingresso');
const { NavePersistente } = require('./navepersistente');
const { Settings } = require('./settings');
const { User } = require('./user');
const { Flotta } = require('../models/flotta');
const { ObjectID } = require('mongodb');
@@ -73,6 +74,9 @@ const NaveSchema = new mongoose.Schema({
type: Number,
default: 1
},
commento_al_sognatore: {
type: String
},
note: {
type: String
},
@@ -272,6 +276,21 @@ NaveSchema.statics.getusersByNave = function (idapp, navemediatore) {
};
NaveSchema.statics.getusersByFlotta = function (idapp, riga, col_prima, col_ultima) {
const miaquery = {
idapp,
riga: riga + 3,
$and: [
{ col: { $gte: col_prima } },
{ col: { $lte: col_ultima } }
],
};
return Nave.find(miaquery);
};
NaveSchema.statics.findRecByRigaColParent = async function (idapp, riga, col, numparentUp) {
const Nave = this;
@@ -427,7 +446,10 @@ function getQueryProj(myfilter) {
'profile.paymenttypes': 1,
'profile.teleg_id': 1,
'profile.email_paypal': 1,
'profile.link_payment': 1,
'profile.note_payment': 1,
'profile.cell': 1,
commento_al_sognatore: 1,
made_gift: 1,
sent_msg_howto_make_gift: 1,
date_made_gift: 1,
@@ -502,6 +524,7 @@ function getQueryInvitante(myfilter) {
username: 1,
invitante_username: 1,
made_gift: 1,
commento_al_sognatore: 1,
sent_msg_howto_make_gift: 1,
date_made_gift: 1,
note: 1,
@@ -574,13 +597,6 @@ NaveSchema.statics.getCol = function (idapp) {
return Settings.getKeyNum(idapp, 'col', 1);
};
function getPrimoFuocoByIndCol(col) {
// let ris = Math.ceil(col - (col % 8)) + 1;
let ris = ((Math.ceil(col / 8) - 1) * 8) + 1;
if (ris <= 0)
ris = 1;
return ris
}
async function getusertextbyrec(myrec, symbol, lettera, riga, col, ind) {
let visu_test = false;
@@ -619,10 +635,16 @@ function checkifNullThenEmpty(rec, riga, col) {
NaveSchema.statics.getPlaccaGenerica = async function (idapp, riga, col, offset, solorecord) {
const Nave = this;
const { Flotta } = require('../models/flotta');
try {
let recsognatori = await Nave.findSognatoriByFuoco(idapp, riga, col, offset);
let recmediatore = await Nave.findMediatoreByFuoco(idapp, riga, col, offset);
let navepersistente = await NavePersistente.findByRigaColByDonatore(idapp, riga, col, offset);
let flotta = null;
if (!!navepersistente)
flotta = await Flotta.getFlottaByNavePersistente(idapp, navepersistente);
if (!solorecord) {
mystr = tools.ACAPO;
@@ -658,7 +680,7 @@ NaveSchema.statics.getPlaccaGenerica = async function (idapp, riga, col, offset,
let arrdonatori = [];
// let numcol = Math.pow(2, indriga - 1);
let primofuoco = getPrimoFuocoByIndCol(col * Math.pow(2, offset));
let primofuoco = tools.getPrimoFuocoByIndCol(col * Math.pow(2, offset));
let ind = 1;
for (let indcol = primofuoco; indcol < primofuoco + 8; indcol++) {
@@ -689,6 +711,7 @@ NaveSchema.statics.getPlaccaGenerica = async function (idapp, riga, col, offset,
recsognatori,
recmediatore,
navepersistente,
flotta,
arrdonatori
};
@@ -1014,7 +1037,7 @@ async function addRecordNaveByParams(params, siRitesse) {
const giapresente = await Nave.findOne({
idapp: params.idapp,
ind_order: params.ind_order,
num_tess: params.num_tess
num_tess: params.num_tess,
});
if (!!giapresente) {
if (params.persistenti) {
@@ -1037,10 +1060,14 @@ async function addRecordNaveByParams(params, siRitesse) {
});
myNave.created = new Date();
if (!!params.note) {
myNave.note = params.note;
}
// console.log('[' + params.riga + ',' + params.col + ']');
// console.log('parent = [' + params.rigaparent + ',' + params.colparent + ']');
const recfindparent = await Nave.findByRigaCol(idapp, params.rigaparent, params.colparent, false);
const recfindparent = await Nave.findByRigaCol(params.idapp, params.rigaparent, params.colparent, false);
// console.log('recfindparent = [' + recfindparent + ']');
// console.table(recfindparent);
@@ -1058,14 +1085,17 @@ async function addRecordNaveByParams(params, siRitesse) {
if (!!result) {
if (params.persistenti) {
let fields_to_update = { added: true };
let fields_to_update = { added: true, navestr: mypos.riga + '.' + mypos.col };
await ListaIngresso.findOneAndUpdate({ _id: params.id.toString() }, { $set: fields_to_update }, { new: false });
} else {
let fields_to_update = { navestr: mypos.riga + '.' + mypos.col };
await ListaIngresso.findOneAndUpdate({ _id: params.id.toString() }, { $set: fields_to_update }, { new: false });
}
params.conta++;
// Check if the Ship has Completed
if (idapp === tools.AYNI) {
if (params.idapp === tools.AYNI) {
if ((params.col % 8) === 0) {
// Completed 8 people
if (!params.primavolta) {
@@ -1089,8 +1119,8 @@ async function addRecordNaveByParams(params, siRitesse) {
else
params.colparent = Math.ceil(params.col / 2);
await Nave.setRiga(idapp, params.riga);
await Nave.setCol(idapp, params.col);
await Nave.setRiga(params.idapp, params.riga);
await Nave.setCol(params.idapp, params.col);
return true;
}
@@ -1126,33 +1156,35 @@ NaveSchema.statics.addUserFromListaIngresso_IntoNave = async function (init, ida
const { User } = require('./user');
if (init) {
params.idapp = idapp;
params.conta = 0;
}
try {
params.primavolta = (params.riga === 1) && (params.col === 1);
params.riga = await Nave.getRiga(idapp);
params.col = await Nave.getCol(idapp);
params.maxcol = tools.getmaxcol(params.riga);
params.colparent = Math.ceil(params.col / 2);
params.rigaparent = params.riga - 1;
if (init) {
params.idapp = idapp;
params.conta = 0;
}
if (params.rigaparent === 0)
params.colparent = 0;
params.primavolta = (params.riga === 1) && (params.col === 1);
params.riga = await Nave.getRiga(idapp);
params.col = await Nave.getCol(idapp);
params.maxcol = tools.getmaxcol(params.riga);
params.colparent = Math.ceil(params.col / 2);
params.rigaparent = params.riga - 1;
myriga = params.riga;
mycol = params.col;
if (params.rigaparent === 0)
params.colparent = 0;
const inserito = await addRecordNaveByParams(params, false);
if (inserito) {
if (idapp === tools.AYNI) {
if ((((params.col) % 8) === 0) && (params.col % 64 !== 0)) {
myriga = params.riga;
mycol = params.col;
const inserito = await addRecordNaveByParams(params, false);
if (inserito) {
if (idapp === tools.AYNI) {
let recmediatore = await Nave.findMediatoreByFuoco(idapp, myriga, mycol, 0);
if (!!recmediatore) {
const ris = await Nave.checkifDeveRitessersi(recmediatore);
if (ris.deveritessersi) {
console.log('Si deve ritessere: [riga=', params.riga, 'col', params.col, ']');
let sognatore = await Nave.getSognatoreByRigaColMediatore(idapp, recmediatore);
if ((((params.col) % 8) === 0) && ((params.col % 64 !== 0) || (sognatore.username !== recmediatore.username))) {
if (!!recmediatore) {
const ris = await Nave.checkifDeveRitessersi(recmediatore);
// console.log('Si deve ritessere: [riga=', params.riga, 'col', params.col, ']');
if (ris.deveritessersi) {
params.ind_order = recmediatore.ind_order;
params.id = recmediatore._id;
@@ -1163,10 +1195,9 @@ NaveSchema.statics.addUserFromListaIngresso_IntoNave = async function (init, ida
}
}
}
}
/**
if ((params.riga === 4 + 3) && (params.col === (8 * 2) + 3)) {
/**
if ((params.riga === 4 + 3) && (params.col === (8 * 2) + 3)) {
// Si ritesse il Fondo AYNI nella Nave 3.3
const userFondo = await User.findByIndex(idapp, 0);
params.ind_order = userFondo.ind_order;
@@ -1176,12 +1207,15 @@ NaveSchema.statics.addUserFromListaIngresso_IntoNave = async function (init, ida
await addRecordNaveByParams(params, true);
} **/
}
}
}
// Se ho completato 8 persone, allora
if (addednowreal) {
// Se ho completato 8 persone, allora
if (addednowreal) {
}
} catch (e) {
console.error(e.message);
}
};
@@ -1233,6 +1267,7 @@ NaveSchema.statics.generaNave = async function (idapp, mydata, persistenti) {
params.ind_order = reclista.ind_order;
params.id = reclista.idListaIngresso;
params.num_tess = reclista.num_tess;
params.note = reclista.note;
params.persistenti = persistenti;
await Nave.addUserFromListaIngresso_IntoNave(index === 0, idapp, params, false);
@@ -1307,26 +1342,49 @@ NaveSchema.statics.pulisciNonPresenzeInNave = async function (idapp) {
NaveSchema.statics.visuNaviUtentiEliminati = async function (idapp) {
const Nave = this;
let numrec = 0;
const { ListaIngresso } = require('./listaingresso');
const { User } = require('./user');
const myquery = getQueryProj({ idapp });
arrrec = await Nave.aggregate(myquery).sort({ riga: 1, col: 1 });
arrnavi = await Nave.find({ idapp }).sort({ riga: 1, col: 1 });
let mystr = 'ELIMINATI: \n';
let conta = 0;
for (const rec of arrrec) {
if (!rec.username) {
let navepersistente = await NavePersistente.findByRigaColByDonatore(idapp, rec.riga, rec.col, 0);
for (const nave of arrnavi) {
const recingr = await ListaIngresso.findOne({
idapp,
ind_order: nave.ind_order,
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }]
});
let rec = null;
if (!!recingr) {
rec = await User.findOne({ idapp, username: recingr.username });
}
if (!rec || !rec.username || rec.deleted) {
let navepersistente = await NavePersistente.findByRigaColByDonatore(idapp, nave.riga, nave.col, 0);
if (!!navepersistente) {
mystr += '[' + conta + '] [NAVI ' + navepersistente.riga + '.' + navepersistente.col + '] [' + rec.riga + '.' + rec.col + '] ' + rec.ind_order;
mystr += ' num_tess = ' + rec.num_tess;
mystr += '[' + conta + '] [NAVI ' + navepersistente.riga + '.' + navepersistente.col + '] [' + nave.riga + '.' + nave.col + '] ' + ' ord= ' + nave.ind_order;
mystr += ' num_tess = ' + nave.num_tess + ' ';
if (!!rec) {
if (!!rec.username) {
mystr += ' [' + rec.username + '] ';
}
if (!!rec.name) {
mystr += ' (' + rec.name + ' ' + rec.surname + ') ';
}
if (rec.deleted) {
mystr += ' (CANCELLATO)';
}
}
mystr += '\n';
conta++;
}
}
}
return { mystr, num: conta };
};
@@ -1421,6 +1479,58 @@ NaveSchema.statics.getDonatoridelSognatore = async function (idapp, riganave, co
};
NaveSchema.statics.getFlotta = async function (idapp, riga, col_prima, col_ultima) {
const Nave = this;
const myquery = getQueryProj({
idapp,
riga: riga + 3,
col: { $gte: col_prima, $lte: col_ultima }
});
const { Flotta } = require('../models/flotta');
const flotta = await Flotta.findOne({ idapp, riga, col_prima });
const { User } = require('./user');
const usersognatore = await User.findOne({idapp, username: flotta.sognatore });
if (!!usersognatore) {
flotta.link_payment = usersognatore.profile.link_payment;
flotta.email_paypal = usersognatore.profile.email_paypal;
flotta.note_payment = usersognatore.profile.note_payment;
}
const arrnaviout = [];
const arrnavi = await Nave.aggregate(myquery);
for (const nave of arrnavi) {
// Se è il mediatore, allora non includerlo nei Donatori!
mypos = {
riga: nave.riga,
col: nave.col,
numup: 3,
};
tools.getRigaColByPosUp(mypos);
const navemediatore = await Nave.findByRigaCol(idapp, mypos.riga, mypos.col, true);
if (!!navemediatore) {
if (navemediatore.ind_order !== nave.ind_order) {
arrnaviout.push(nave);
}
} else {
arrnaviout.push(nave);
}
}
flotta._doc.log_attivita = tools.readFlottaLog(idapp, flotta.riga, flotta.col_prima);
return { arrdonatori: arrnaviout, flotta };
};
NaveSchema.statics.isDefinitiva = async function (idapp, mynave) {
const nave = await NavePersistente.findByRigaColByDonatore(idapp, mynave.riga, mynave.col, 0);
return (!!nave) ? !nave.provvisoria : false;
@@ -1553,9 +1663,47 @@ NaveSchema.statics.checkIfMadeGift = async function (idapp, username) {
};
NaveSchema.statics.getSognatoreByRigaColMediatore = async function (idapp, navemediatore) {
NaveSchema.statics.delNaviProvvisorie = async function (idapp) {
const Nave = this;
const ris = this.getRigaColSognatoreByMediatore(idapp, navemediatore.riga, navemediatore.col, 3);
let num = 0;
const arrnavi = await Nave.find({ idapp });
for (const nave of arrnavi) {
let persistente = await NavePersistente.findByRigaColByDonatore(idapp, nave.riga, nave.col, 0);
if (!!persistente) {
if (persistente.provvisoria) {
let ris = await Nave.deleteOne({ _id: nave._id });
if (!!ris) {
num++;
}
}
}
}
// Pulisci gli added se era stato cancellato dalla nave
await Nave.pulisciNonPresenzeInNave(idapp);
const data = await Nave.getLastRigaCol(idapp);
await Nave.setRiga(idapp, data.riga);
await Nave.setCol(idapp, data.col + 1);
const maxcol = tools.getmaxcol(data.riga);
if (data.col === maxcol) {
await Nave.setRiga(idapp, data.riga + 1);
await Nave.setCol(idapp, 1);
}
return { num };
};
NaveSchema.statics.getSognatoreByRigaColMediatore = async function (idapp, navemediatore) {
const Nave = this;
const ris = tools.getRigaColSognatoreByMediatore(idapp, navemediatore.riga, navemediatore.col);
const myquery = getQueryProj({
idapp,
@@ -1573,7 +1721,6 @@ NaveSchema.statics.getSognatoreByRigaColMediatore = async function (idapp, navem
return null;
};
const Nave = mongoose.model('Nave', NaveSchema);
module.exports = { Nave };

View File

@@ -7,6 +7,8 @@ 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');
@@ -92,6 +94,8 @@ function getQueryProj(myfilter) {
username: 1,
'profile.paymenttypes': 1,
'profile.email_paypal': 1,
'profile.link_payment': 1,
'profile.note_payment': 1,
'profile.cell': 1,
made_gift: 1,
sent_msg_howto_make_gift: 1,
@@ -125,13 +129,13 @@ function getQueryProj(myfilter) {
}
},
{
$replaceRoot: { newRoot: { $mergeObjects: [ { $arrayElemAt: [ "$mylista", 0 ] }, "$$ROOT" ] } }
$replaceRoot: { newRoot: { $mergeObjects: [{ $arrayElemAt: ["$mylista", 0] }, "$$ROOT"] } }
},
{
$lookup: {
from: "users",
as: "user",
let: {username: '$username' },
let: { username: '$username' },
pipeline: [
{
$match: {
@@ -209,7 +213,7 @@ NavePersistenteSchema.statics.getListaNavi = function (idapp) {
NavePersistenteSchema.statics.getLastNave = function (idapp) {
const NavePersistente = this;
const myfind = { idapp, date_start: { $lte: tools.IncDateNow(0) }, provvisoria: false };
const myfind = { idapp, date_start: { $lte: tools.IncDateNow(0) }, provvisoria: false };
return NavePersistente.findOne(myfind,
{
@@ -250,10 +254,13 @@ NavePersistenteSchema.statics.findByRigaCol = function (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 });
};
@@ -272,7 +279,8 @@ NavePersistenteSchema.pre('save', async function (next) {
function getNextDayNave(miadata) {
const dayofweek = [1, 3, 5]; // LUNEDI, MERCOLEDI, VENERDI
// const dayofweek = [1, 2, 4, 5]; // LUNEDI, MARTEDI', GIOVEDI, VENERDI
const dayofweek = [1, 4]; // LUNEDI, GIOVEDI
let mydate = tools.AddDate(miadata, 1);
@@ -285,6 +293,7 @@ function getNextDayNave(miadata) {
}
NavePersistenteSchema.statics.addRecordNavePersistenteByParams = async function (params) {
const NavePersistente = this;
// Check if Exist:
const giapresente = await NavePersistente.findOne({
@@ -295,7 +304,7 @@ NavePersistenteSchema.statics.addRecordNavePersistenteByParams = async function
if (!giapresente) {
// Prende la nave prima:
const lastnave = await NavePersistente.findOne({idapp}).sort({riga: -1, col: -1});
const lastnave = await NavePersistente.findOne({ idapp: params.idapp }).sort({ riga: -1, col: -1 });
let nextgiftchat = null;
@@ -323,6 +332,160 @@ NavePersistenteSchema.statics.addRecordNavePersistenteByParams = async function
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_gift_chat_open'] = fieldvalue['date_close'];
} 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');
let num = 0;
try {
let nuovo = false;
// let primacol = false;
indcolflottaprima = tools.getPrimaColFlotta(naveinput.col1don + 7);
console.log(num, ' -> [', naveinput.riga, '.', naveinput.col, '] 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_start;
myflotta.date_close = navepers.date_gift_chat_open;
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.link_payment = '';
myflotta.note_payment = '';
if (!!sognatore) {
myflotta.email_paypal = sognatore.profile.email_paypal;
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.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);

View File

@@ -56,7 +56,7 @@ SettingsSchema.statics.getValDbSettings = function (idapp, key, def) {
return Settings.findOne({ idapp, key })
.then((myrec) => {
// console.log('getValDbSettings', myrec, 'idapp', idapp);
if (myrec) {
if (!!myrec) {
if (myrec.type === tools.FieldType.date)
return myrec.value_date;
else if (myrec.type === tools.FieldType.number)
@@ -112,6 +112,8 @@ SettingsSchema.statics.setKeyNum = async function (idapp, key, value) {
myrec = await Settings.findOneAndUpdate({ idapp, key }, { $set: { value_num: value } }, { new: false });
}
return myrec
};
SettingsSchema.statics.setBool = async function (idapp, key, valbool) {
@@ -130,6 +132,8 @@ SettingsSchema.statics.setBool = async function (idapp, key, valbool) {
myrec = await Settings.findOneAndUpdate({ idapp, key }, { $set: { value_bool: valbool } }, { new: false });
}
return myrec
};

View File

@@ -6,6 +6,7 @@ const _ = require('lodash');
const tools = require('../tools/general');
const { Flotta } = require('../models/flotta');
const { Settings } = require('../models/settings');
const { ListaIngresso } = require('../models/listaingresso');
const { Graduatoria } = require('../models/graduatoria');
@@ -153,6 +154,15 @@ const UserSchema = new mongoose.Schema({
sospeso: {
type: Boolean
},
non_voglio_imbarcarmi: {
type: Boolean
},
navinonpresenti: {
type: Boolean
},
subaccount: {
type: Boolean
},
profile: {
img: {
type: String
@@ -175,6 +185,12 @@ const UserSchema = new mongoose.Schema({
email_paypal: {
type: String
},
link_payment: {
type: String
},
note_payment: {
type: String
},
paymenttypes: [],
username_telegram: {
type: String
@@ -203,10 +219,13 @@ const UserSchema = new mongoose.Schema({
saw_zoom_presentation: {
type: Boolean
},
special_req: {
qualified: {
type: Boolean
},
vuole_ritessersi: {
qualified_2invitati: {
type: Boolean
},
special_req: {
type: Boolean
},
sex: {
@@ -345,7 +364,17 @@ UserSchema.statics.findByCredentials = function (idapp, username, password) {
return User.findOne({
idapp, username: username,
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }]
$or: [
{ deleted: { $exists: false } },
{ deleted: { $exists: true, $eq: false } },
{
$and: [
{ deleted: { $exists: true, $eq: true } },
{ subaccount: { $exists: true, $eq: true } }
]
}
],
}).then((user) => {
if (!user) {
// Check if with email:
@@ -354,7 +383,7 @@ UserSchema.statics.findByCredentials = function (idapp, username, password) {
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }]
})
} else {
return !user.deleted ? user : null
return !user.deleted || (user.deleted && user.subaccount) ? user : null
}
}).then(user => {
if (!user)
@@ -409,6 +438,7 @@ UserSchema.statics.getUserShortDataByUsername = async function (idapp, username)
'username': username,
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
}, {
idapp: 1,
lang: 1,
index: 1,
ind_order: 1,
@@ -421,8 +451,12 @@ UserSchema.statics.getUserShortDataByUsername = async function (idapp, username)
verified_email: 1,
'profile.teleg_id': 1,
'profile.saw_zoom_presentation': 1,
'profile.qualified': 1,
'profile.qualified_2invitati': 1,
'profile.saw_and_accepted': 1,
'profile.email_paypal': 1,
'profile.link_payment': 1,
'profile.note_payment': 1,
'profile.my_dream': 1,
'profile.paymenttypes': 1,
'profile.cell': 1,
@@ -467,8 +501,12 @@ UserSchema.statics.getDownlineByUsername = async function (idapp, username, incl
verified_email: 1,
'profile.teleg_id': 1,
'profile.saw_zoom_presentation': 1,
'profile.qualified': 1,
'profile.qualified_2invitati': 1,
'profile.saw_and_accepted': 1,
'profile.email_paypal': 1,
'profile.link_payment': 1,
'profile.note_payment': 1,
'profile.my_dream': 1,
'profile.paymenttypes': 1,
'profile.cell': 1,
@@ -558,7 +596,6 @@ UserSchema.statics.getQueryQualified = function () {
}
UserSchema.statics.isUserQualified7 = async function (idapp, username) {
const User = this;
@@ -576,6 +613,72 @@ UserSchema.statics.isUserQualified7 = async function (idapp, username) {
return !!myrec;
};
UserSchema.statics.isUserAlreadyQualified = async function (idapp, username) {
const User = this;
if (username === undefined)
return false;
const myquery = {
'idapp': idapp,
'username': username,
'profile.qualified': { $exists: true, $eq: true },
};
const myrec = await User.findOne(myquery);
return !!myrec;
};
UserSchema.statics.isUserAlreadyQualified_2Invitati = async function (idapp, username) {
const User = this;
if (username === undefined)
return false;
const myquery = {
'idapp': idapp,
'username': username,
'profile.qualified_2invitati': { $exists: true, $eq: true },
};
const myrec = await User.findOne(myquery);
return !!myrec;
};
UserSchema.statics.setUserQualified = async function (idapp, username) {
const User = this;
if (username === undefined)
return false;
const myquery = {
'idapp': idapp,
'username': username,
};
const myrec = await User.findOneAndUpdate(myquery, { $set: { 'profile.qualified': true } }, { new: false } );
return !!myrec;
};
UserSchema.statics.setUserQualified_2Invitati = async function (idapp, username) {
const User = this;
if (username === undefined)
return false;
const myquery = {
'idapp': idapp,
'username': username,
};
const myrec = await User.findOneAndUpdate(myquery, { $set: { 'profile.qualified_2invitati': true } }, { new: false } );
return !!myrec;
};
UserSchema.statics.isUserQualified9 = async function (idapp, username) {
const User = this;
@@ -873,6 +976,22 @@ UserSchema.statics.SetTelegramCheckCode = async function (idapp, id, teleg_check
};
UserSchema.statics.NonVoglioImbarcarmi = async function (idapp, username) {
const User = this;
const fields_to_update = {
non_voglio_imbarcarmi: true
};
return await User.findOneAndUpdate({
idapp,
username,
}, { $set: fields_to_update }, { new: false }).then((record) => {
return !!record;
});
};
UserSchema.statics.SetTelegramIdSuccess = async function (idapp, id, teleg_id) {
const User = this;
@@ -923,7 +1042,7 @@ UserSchema.statics.SetTelegramWasBlocked = async function (idapp, teleg_id) {
'profile.teleg_id': 0,
};
if (process.env.PROD === 1) {
if (process.env.PROD === "1") {
const ris = await User.findOneAndUpdate({
idapp,
@@ -1007,10 +1126,15 @@ UserSchema.statics.getRecByIndOrder = async function (idapp, ind_order) {
ind_order: 1,
old_order: 1,
username: 1,
email: 1,
name: 1,
lang: 1,
surname: 1,
'profile.teleg_id': 1,
'profile.email_paypal': 1,
'profile.link_payment': 1,
'profile.note_payment': 1,
'profile.paymenttypes': 1,
};
const rec = await ListaIngresso.getarray(idapp,
@@ -1161,6 +1285,7 @@ UserSchema.statics.getFieldsForSearch = function () {
{ field: 'email', type: tools.FieldType.string },
{ field: 'profile.cell', type: tools.FieldType.string },
{ field: 'profile.email_paypal', type: tools.FieldType.string },
{ field: 'profile.link_payment', 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 }]
@@ -1235,6 +1360,8 @@ UserSchema.statics.getDashboard = async function (idapp, aportador_solidario, us
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);
}
@@ -1924,6 +2051,111 @@ UserSchema.statics.changeInvitante = async function (idapp, username, invitante_
};
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.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;
// Solo i Cancellati !
arrusers = await User.find({ 'idapp': idapp, deleted: true });
let num = 0;
for (const rec of arrusers) {
// Cerca il suo Principale!
const trovato = await User.findOne({
idapp,
'profile.teleg_id': rec.profile.teleg_id,
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }]
});
if (trovato) {
num++;
await User.findByIdAndUpdate(rec._id, { subaccount: true }, { new: false });
}
}
return { num };
};
UserSchema.statics.DbOp = async function (idapp, mydata) {
const User = this;
try {