- Nave
- Requirements - Send Msg to Passeggeri
This commit is contained in:
@@ -8,7 +8,7 @@ const tools = require('../tools/general');
|
||||
|
||||
const { Settings } = require('../models/settings');
|
||||
const { ListaIngresso } = require('../models/listaingresso');
|
||||
const { Billettera } = require('./billettera');
|
||||
const { Nave } = require('../models/nave');
|
||||
const { ExtraList } = require('../models/extralist');
|
||||
|
||||
const { ObjectID } = require('mongodb');
|
||||
@@ -126,6 +126,9 @@ const UserSchema = new mongoose.Schema({
|
||||
aportador_solidario: {
|
||||
type: String,
|
||||
},
|
||||
aportador_iniziale: {
|
||||
type: String,
|
||||
},
|
||||
aportador_solidario_nome_completo: {
|
||||
type: String,
|
||||
},
|
||||
@@ -188,6 +191,9 @@ const UserSchema = new mongoose.Schema({
|
||||
special_req: {
|
||||
type: Boolean
|
||||
},
|
||||
vuole_ritessersi: {
|
||||
type: Boolean
|
||||
},
|
||||
sex: {
|
||||
type: Number,
|
||||
},
|
||||
@@ -338,7 +344,7 @@ UserSchema.statics.findByUsername = async function (idapp, username, alsoemail)
|
||||
if ((!ris) && (alsoemail)) {
|
||||
regexemail = new RegExp(["^", username.toLowerCase(), "$"].join(""), "i");
|
||||
|
||||
return await User.findOne({
|
||||
return User.findOne({
|
||||
'idapp': idapp,
|
||||
'email': regexemail,
|
||||
});
|
||||
@@ -365,6 +371,7 @@ UserSchema.statics.getUserShortDataByUsername = async function (idapp, username)
|
||||
'profile.email_paypal': 1,
|
||||
'profile.my_dream': 1,
|
||||
'profile.paymenttypes': 1,
|
||||
'profile.cell': 1,
|
||||
made_gift: 1,
|
||||
email: 1,
|
||||
date_reg: 1,
|
||||
@@ -389,6 +396,9 @@ UserSchema.statics.getUserShortDataByUsername = async function (idapp, username)
|
||||
};
|
||||
|
||||
UserSchema.statics.getDownlineByUsername = async function (idapp, username) {
|
||||
if (username === undefined)
|
||||
return null;
|
||||
|
||||
const User = this;
|
||||
const arrrec = await User.find({
|
||||
'idapp': idapp,
|
||||
@@ -406,6 +416,7 @@ UserSchema.statics.getDownlineByUsername = async function (idapp, username) {
|
||||
'profile.email_paypal': 1,
|
||||
'profile.my_dream': 1,
|
||||
'profile.paymenttypes': 1,
|
||||
'profile.cell': 1,
|
||||
made_gift: 1,
|
||||
email: 1,
|
||||
date_reg: 1,
|
||||
@@ -430,32 +441,45 @@ UserSchema.statics.getDownlineByUsername = async function (idapp, username) {
|
||||
UserSchema.statics.getnumInvitatiAttivi = function (idapp, username) {
|
||||
const User = this;
|
||||
|
||||
return User.count({
|
||||
if (username === undefined)
|
||||
return 0;
|
||||
|
||||
// return User.count({
|
||||
return User.countDocuments({
|
||||
idapp,
|
||||
aportador_solidario: username,
|
||||
verified_email: true,
|
||||
'profile.teleg_id': { $gt: 1 },
|
||||
'profile.saw_and_accepted': shared_consts.ALL_SAW_AND_ACCEPTED,
|
||||
'profile.saw_zoom_presentation': true,
|
||||
'profile.my_dream': { $exists: true },
|
||||
$and: [
|
||||
{ "$expr": { "$gt": [{ "$strLenCP": "$profile.my_dream" }, 10] } },
|
||||
{ "$expr": { "$gt": [{ "$strLenCP": "$profile.email_paypal" }, 6] } }
|
||||
],
|
||||
$where: "this.profile.paymenttypes.length >= 1",
|
||||
'profile.email_paypal': { $exists: true },
|
||||
$or: [
|
||||
{
|
||||
'profile.special_req': true
|
||||
},
|
||||
{
|
||||
|
||||
verified_email: true,
|
||||
'profile.teleg_id': { $gt: 1 },
|
||||
'profile.saw_and_accepted': shared_consts.ALL_SAW_AND_ACCEPTED,
|
||||
'profile.saw_zoom_presentation': true,
|
||||
'profile.my_dream': { $exists: true },
|
||||
'profile.paymenttypes': { "$in": ['paypal'] },
|
||||
$and: [
|
||||
{ "$expr": { "$gt": [{ "$strLenCP": "$profile.my_dream" }, 10] } },
|
||||
{ "$expr": { "$gt": [{ "$strLenCP": "$profile.email_paypal" }, 6] } }
|
||||
],
|
||||
}]
|
||||
});
|
||||
};
|
||||
|
||||
UserSchema.statics.isUserQualified7 = async function (idapp, username) {
|
||||
const User = this;
|
||||
|
||||
const myrec = await User.findOne({
|
||||
if (username === undefined)
|
||||
return false;
|
||||
|
||||
const myquery = {
|
||||
'idapp': idapp,
|
||||
'username': username,
|
||||
$or: [
|
||||
{
|
||||
special_req: true
|
||||
'profile.special_req': true
|
||||
},
|
||||
{
|
||||
verified_email: true,
|
||||
@@ -464,22 +488,39 @@ UserSchema.statics.isUserQualified7 = async function (idapp, username) {
|
||||
'profile.saw_zoom_presentation': true,
|
||||
'profile.my_dream': { $exists: true },
|
||||
'profile.email_paypal': { $exists: true },
|
||||
'profile.paymenttypes': { "$in": ['paypal'] },
|
||||
$and: [
|
||||
{ "$expr": { "$gt": [{ "$strLenCP": "$profile.my_dream" }, 10] } },
|
||||
{ "$expr": { "$gt": [{ "$strLenCP": "$profile.email_paypal" }, 6] } }
|
||||
],
|
||||
$where: "this.profile.paymenttypes.length >= 1",
|
||||
}]
|
||||
});
|
||||
};
|
||||
|
||||
const myrec = await User.findOne(myquery);
|
||||
|
||||
return !!myrec;
|
||||
};
|
||||
|
||||
UserSchema.statics.isUserQualified9 = async function (idapp, username) {
|
||||
const User = this;
|
||||
|
||||
if (username === undefined)
|
||||
return false;
|
||||
|
||||
qualified = await User.isUserQualified7(idapp, username);
|
||||
numinvitatiattivi = await User.getnumInvitatiAttivi(idapp, username);
|
||||
|
||||
return qualified && (numinvitatiattivi >= 2);
|
||||
|
||||
};
|
||||
|
||||
UserSchema.statics.getnumPaymentOk = function (idapp) {
|
||||
const User = this;
|
||||
|
||||
return User.count({
|
||||
idapp,
|
||||
'profile.paymenttypes': { "$in": ['paypal'] },
|
||||
$where: "this.profile.paymenttypes.length >= 1",
|
||||
'profile.email_paypal': { $exists: true },
|
||||
});
|
||||
@@ -529,6 +570,21 @@ UserSchema.statics.findByLinkreg = function (idapp, linkreg) {
|
||||
});
|
||||
};
|
||||
|
||||
UserSchema.statics.AportadorOrig = function (idapp, id) {
|
||||
const User = this;
|
||||
|
||||
return User.findOne({
|
||||
'_id': id,
|
||||
'idapp': idapp,
|
||||
}).then((rec) => {
|
||||
if (rec)
|
||||
return rec.aportador_iniziale;
|
||||
else
|
||||
return '';
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
UserSchema.statics.findByLinkTokenforgot = function (idapp, email, tokenforgot) {
|
||||
const User = this;
|
||||
|
||||
@@ -560,17 +616,17 @@ UserSchema.statics.findByIndOrder = function (idapp, ind_order) {
|
||||
const User = this;
|
||||
|
||||
try {
|
||||
// ++Todo: non mettere tutti i campi !!
|
||||
return User.findOne({
|
||||
'idapp': idapp,
|
||||
'ind_order': ind_order,
|
||||
idapp,
|
||||
ind_order,
|
||||
});
|
||||
} catch (e) {
|
||||
|
||||
console.error(e);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
UserSchema.pre('save', function (next) {
|
||||
const user = this;
|
||||
|
||||
@@ -611,6 +667,29 @@ UserSchema.statics.getEmailByUsername = async function (idapp, username) {
|
||||
});
|
||||
};
|
||||
|
||||
UserSchema.statics.getUsernameById = async function (idapp, id) {
|
||||
const User = this;
|
||||
|
||||
return await User.findOne({ idapp, _id: id }, { username: 1 })
|
||||
.then((myuser) => {
|
||||
return ((myuser) ? myuser.username : '');
|
||||
}).catch((e) => {
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
UserSchema.statics.getUserById = function (idapp, id) {
|
||||
const User = this;
|
||||
|
||||
return User.findOne({ idapp, _id: id })
|
||||
};
|
||||
|
||||
UserSchema.statics.getUserByAportador = function (idapp, aportador_solidario) {
|
||||
const User = this;
|
||||
|
||||
return User.findOne({ idapp, aportador_solidario })
|
||||
};
|
||||
|
||||
UserSchema.statics.getAportadorSolidarioByUsername = async function (idapp, username) {
|
||||
const User = this;
|
||||
|
||||
@@ -633,6 +712,17 @@ UserSchema.statics.UserByIdTelegram = async function (idapp, teleg_id) {
|
||||
});
|
||||
};
|
||||
|
||||
UserSchema.statics.UsersByIdTelegram = async function (idapp, teleg_id) {
|
||||
const User = this;
|
||||
|
||||
return await User.find({ idapp, 'profile.teleg_id': teleg_id })
|
||||
.then((rec) => {
|
||||
return (!!rec) ? rec._doc : null;
|
||||
}).catch((e) => {
|
||||
console.error('UserExistByIdTelegram', e);
|
||||
});
|
||||
};
|
||||
|
||||
UserSchema.statics.TelegIdByUsername = async function (idapp, username) {
|
||||
const User = this;
|
||||
|
||||
@@ -705,6 +795,24 @@ UserSchema.statics.getNameSurnameByUsername = async function (idapp, username) {
|
||||
});
|
||||
};
|
||||
|
||||
UserSchema.statics.getSmallRecByIndOrder = async function (idapp, ind_order) {
|
||||
const User = this;
|
||||
|
||||
return await User.findOne({ idapp, ind_order },
|
||||
{
|
||||
ind_order: 1,
|
||||
username: 1,
|
||||
name: 1,
|
||||
surname: 1
|
||||
}
|
||||
)
|
||||
.then((rec) => {
|
||||
return rec;
|
||||
}).catch((e) => {
|
||||
console.error('getSmallRecByIndOrder', e);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
UserSchema.statics.getusersManagers = async function (idapp) {
|
||||
const User = this;
|
||||
@@ -717,15 +825,25 @@ UserSchema.statics.getusersManagers = async function (idapp) {
|
||||
});
|
||||
};
|
||||
|
||||
UserSchema.statics.getUsersTelegALL = async function (idapp) {
|
||||
UserSchema.statics.getUsersTelegALL = async function (idapp, username) {
|
||||
const User = this;
|
||||
|
||||
return await User.find({ idapp, 'profile.teleg_id': { $gt: 0 } })
|
||||
.then((arrrec) => {
|
||||
return (!!arrrec) ? arrrec : null;
|
||||
}).catch((e) => {
|
||||
console.error('getUsersTelegALL', e);
|
||||
});
|
||||
if (!!username) {
|
||||
return await User.find({ idapp, username, 'profile.teleg_id': { $gt: 0 } })
|
||||
.then((arrrec) => {
|
||||
return (!!arrrec) ? arrrec : null;
|
||||
}).catch((e) => {
|
||||
console.error('getUsersTelegALL', e);
|
||||
});
|
||||
} else {
|
||||
return await User.find({ idapp, 'profile.teleg_id': { $gt: 0 } })
|
||||
.then((arrrec) => {
|
||||
return (!!arrrec) ? arrrec : null;
|
||||
}).catch((e) => {
|
||||
console.error('getUsersTelegALL', e);
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
UserSchema.statics.isManagerByIdTeleg = async function (idapp, idtelegram) {
|
||||
@@ -851,13 +969,15 @@ UserSchema.statics.getDashboard = async function (idapp, aportador_solidario, us
|
||||
dashboard.aportador = await ExtraList.getUserNotRegisteredByNameSurname(idapp, aportador_solidario_nome_completo);
|
||||
}
|
||||
|
||||
dashboard.downline = [];
|
||||
|
||||
// Data of my Downline
|
||||
const arrap = await User.getDownlineByUsername(idapp, aportador_solidario);
|
||||
dashboard.numpeople_aportador = arrap.length;
|
||||
if (!!arrap)
|
||||
dashboard.numpeople_aportador = arrap.length;
|
||||
|
||||
dashboard.downline = await User.getDownlineByUsername(idapp, username);
|
||||
dashboard.downnotreg = await ExtraList.getDownlineNotRegisteredByNameSurname(idapp, dashboard.myself.name + ' ' + dashboard.myself.surname);
|
||||
// dashboard.downnotreg = await ExtraList.getDownlineNotRegisteredByNameSurname(idapp, dashboard.myself.name + ' ' + dashboard.myself.surname);
|
||||
|
||||
dashboard.downbyuser = {};
|
||||
|
||||
@@ -868,6 +988,18 @@ UserSchema.statics.getDashboard = async function (idapp, aportador_solidario, us
|
||||
dashboard.downbyuser[down2.username] = await User.getDownlineByUsername(idapp, down2.username);
|
||||
}
|
||||
}
|
||||
|
||||
dashboard.arrnavi = await Nave.getArrPosizioniByIndOrder(idapp, dashboard.myself.ind_order);
|
||||
|
||||
dashboard.navi_partenza = [];
|
||||
for (let indriga = 0; indriga < 10; indriga++) {
|
||||
dashboard.navi_partenza.push(await Nave.getPrimaNaveByRiga(idapp, indriga));
|
||||
}
|
||||
|
||||
for (let mynave of dashboard.arrnavi) {
|
||||
mynave._doc.rec = await Nave.getNaveByRigaCol(idapp, mynave.riga, mynave.col);
|
||||
}
|
||||
|
||||
return dashboard;
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
@@ -920,12 +1052,12 @@ UserSchema.statics.getUsersQualified = async function (idapp, numinvitati) {
|
||||
idapp,
|
||||
$or: [
|
||||
{
|
||||
special_req: true
|
||||
'profile.special_req': true
|
||||
},
|
||||
{
|
||||
verified_email: true,
|
||||
'profile.teleg_id': { $gt: 0 },
|
||||
$where: "this.profile.paymenttypes.length >= 1",
|
||||
'profile.paymenttypes': { "$in": ['paypal'] },
|
||||
'profile.saw_and_accepted': shared_consts.ALL_SAW_AND_ACCEPTED,
|
||||
'profile.saw_zoom_presentation': true,
|
||||
'profile.my_dream': { $exists: true },
|
||||
@@ -1022,7 +1154,15 @@ UserSchema.statics.getLastUsers = async function (idapp) {
|
||||
|
||||
const lastn = await Settings.getValDbSettings(idapp, 'SHOW_LAST_N_USERS', 5);
|
||||
|
||||
return await User.find({ idapp }).sort({ date_temp_reg: -1 }).limit(lastn).then((arr) => {
|
||||
return await User.find({ idapp }, {
|
||||
username: 1,
|
||||
name: 1,
|
||||
surname: 1,
|
||||
date_temp_reg: 1,
|
||||
date_reg: 1,
|
||||
ind_order: 1,
|
||||
'profile.nationality': 1,
|
||||
}).sort({ date_temp_reg: -1 }).limit(lastn).then((arr) => {
|
||||
//return JSON.stringify(arr)
|
||||
return arr
|
||||
});
|
||||
@@ -1079,23 +1219,47 @@ UserSchema.statics.findAllDistinctNationality = async function (idapp) {
|
||||
};
|
||||
|
||||
UserSchema.statics.getUsersRegDaily = function (idapp, nrec) {
|
||||
|
||||
const query = [
|
||||
{
|
||||
$match: { idapp }
|
||||
$match: { idapp, date_temp_reg: { $gte: tools.IncDateNow(-(1000 * 60 * 60 * 24 * nrec)) } }
|
||||
},
|
||||
{
|
||||
$group: { _id: { $dateToString: { format: "%Y-%m-%d", date: "$date_temp_reg" } }, count: { $sum: 1 } }
|
||||
},
|
||||
{
|
||||
$sort: { _id: 1 }
|
||||
},
|
||||
{
|
||||
$limit: nrec
|
||||
}
|
||||
];
|
||||
return query
|
||||
};
|
||||
|
||||
UserSchema.statics.getnumRegNDays = function (idapp, nrec) {
|
||||
|
||||
|
||||
const query = [
|
||||
{
|
||||
$match: { idapp, date_temp_reg: { $lt: tools.IncDateNow(-(1000 * 60 * 60 * 24 * nrec)) } }
|
||||
},
|
||||
{
|
||||
$group: { _id: { $dateToString: { format: "%Y-%m-%d", date: "$date_temp_reg" } }, count: { $sum: 1 } }
|
||||
},
|
||||
{
|
||||
$sort: { _id: 1 }
|
||||
}
|
||||
];
|
||||
return query
|
||||
};
|
||||
|
||||
UserSchema.statics.calcnumRegUntilDay = async function (idapp) {
|
||||
const User = this;
|
||||
|
||||
return await User.aggregate(User.getnumRegNDays(idapp, 30))
|
||||
.then((arr) => {
|
||||
return arr.reduce((sum, rec) => sum + rec.count, 0);
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
UserSchema.statics.calcRegDaily = async function (idapp) {
|
||||
const User = this;
|
||||
@@ -1116,22 +1280,31 @@ if (tools.INITDB_FIRSTIME) {
|
||||
// UserSchema.index({ surname: 1 });
|
||||
}
|
||||
|
||||
async function addUtentiInLista(idapp, mode) {
|
||||
async function addUtentiInLista(idapp, mode, arrusers) {
|
||||
let num = 0;
|
||||
for (const rec of arrusers) {
|
||||
let ok = false;
|
||||
let qualified = await User.isUserQualified7(idapp, rec.username);
|
||||
let numinvitatiattivi = await User.getnumInvitatiAttivi(idapp, rec.username);
|
||||
let numinvitati = await User.getnumInvitati(idapp, rec.username);
|
||||
|
||||
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) {
|
||||
// 7 punti qualificati
|
||||
ok = qualified;
|
||||
} else {
|
||||
ok = true;
|
||||
// // almeno telegram ID
|
||||
// ok = user.profile.teleg_id > 0;
|
||||
// } else {
|
||||
@@ -1139,24 +1312,37 @@ async function addUtentiInLista(idapp, mode) {
|
||||
}
|
||||
|
||||
if (ok) {
|
||||
if (!await ListaIngresso.findByUsername(idapp, rec.username)) {
|
||||
let listaingresso = new ListaIngresso({
|
||||
username: rec.username,
|
||||
ind_order: rec.ind_order,
|
||||
name: rec.name,
|
||||
surname: rec.surname,
|
||||
idapp,
|
||||
_id: new ObjectID()
|
||||
});
|
||||
|
||||
await listaingresso.save();
|
||||
ris = await ListaIngresso.addUserInListaIngresso(idapp, rec.ind_order, rec.lang, false, 1);
|
||||
if (!!ris)
|
||||
num++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
UserSchema.statics.deveRitessersi = async function (idapp, ind_order) {
|
||||
|
||||
const myrec = await User.findOne({
|
||||
'idapp': idapp,
|
||||
'ind_order': ind_order,
|
||||
"profile.vuole_ritessersi": true
|
||||
});
|
||||
|
||||
return (!!myrec)
|
||||
|
||||
};
|
||||
|
||||
UserSchema.statics.getUsernameByIndOrder = async function (idapp, ind_order) {
|
||||
|
||||
const myrec = await User.findOne({
|
||||
'idapp': idapp,
|
||||
'ind_order': ind_order,
|
||||
}, { username: 1 });
|
||||
|
||||
return (!!myrec) ? myrec.username : ''
|
||||
|
||||
};
|
||||
|
||||
UserSchema.statics.DbOp = async function (idapp, mydata) {
|
||||
const User = this;
|
||||
try {
|
||||
@@ -1190,26 +1376,21 @@ UserSchema.statics.DbOp = async function (idapp, mydata) {
|
||||
|
||||
} else if (mydata.dbop === 'creaLista') {
|
||||
|
||||
await ListaIngresso.remove({ idapp });
|
||||
await ListaIngresso.deleteMany({ idapp, added: false });
|
||||
|
||||
arrusers = await User.find({ 'idapp': idapp }).sort({ ind_order: 1 });
|
||||
let num = 0;
|
||||
|
||||
num += await addUtentiInLista(idapp, 1);
|
||||
num += await addUtentiInLista(idapp, 2);
|
||||
num += await addUtentiInLista(idapp, 1, arrusers);
|
||||
num += await addUtentiInLista(idapp, 2, arrusers);
|
||||
num += await addUtentiInLista(idapp, 3, arrusers);
|
||||
num += await addUtentiInLista(idapp, 4, arrusers);
|
||||
num += await addUtentiInLista(idapp, 5, arrusers);
|
||||
// num += await addUtentiInLista(idapp, 3);
|
||||
// num += await addUtentiInLista(idapp, 4);
|
||||
|
||||
return { num };
|
||||
|
||||
} else if (mydata.dbop === 'creaBillettera') {
|
||||
const num = await Billettera.generaBillettera(idapp);
|
||||
|
||||
return { num };
|
||||
} else if (mydata.dbop === 'visuPlacca') {
|
||||
const placca = await Billettera.getPlaccaByFuoco(idapp, riga, col);
|
||||
|
||||
return { placca };
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
|
||||
Reference in New Issue
Block a user