- 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 140e181fcc
commit c939be279e
21 changed files with 2037 additions and 254 deletions

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 {