- Billettera

- Lista Ingressi
 - Send a Tutti la propria Lavagna.
This commit is contained in:
Paolo Arena
2020-02-19 16:09:16 +01:00
parent eccb5bbb57
commit 26715cda44
23 changed files with 1740 additions and 226 deletions

View File

@@ -7,8 +7,12 @@ const _ = require('lodash');
const tools = require('../tools/general');
const { Settings } = require('../models/settings');
const { ListaIngresso } = require('../models/listaingresso');
const { Billettera } = require('./billettera');
const { ExtraList } = require('../models/extralist');
const { ObjectID } = require('mongodb');
const shared_consts = require('../tools/shared_nodejs');
const queryclass = require('../classes/queryclass');
@@ -160,6 +164,9 @@ const UserSchema = new mongoose.Schema({
teleg_id: {
type: Number
},
teleg_id_old: {
type: Number
},
teleg_checkcode: {
type: Number
},
@@ -178,6 +185,9 @@ const UserSchema = new mongoose.Schema({
saw_zoom_presentation: {
type: Boolean
},
special_req: {
type: Boolean
},
sex: {
type: Number,
},
@@ -316,14 +326,24 @@ UserSchema.statics.findByCredentials = function (idapp, username, password) {
};
UserSchema.statics.findByUsername = function (idapp, username) {
UserSchema.statics.findByUsername = async function (idapp, username, alsoemail) {
const User = this;
// /^bar$/i
const regexusername = new RegExp(["^", username, "$"].join(""), "i");
return User.findOne({
return await User.findOne({
'idapp': idapp,
'username': username,
'username': regexusername,
}).then(async (ris) => {
if ((!ris) && (alsoemail)) {
regexemail = new RegExp(["^", username.toLowerCase(), "$"].join(""), "i");
return await User.findOne({
'idapp': idapp,
'email': regexemail,
});
}
return ris;
});
};
@@ -360,6 +380,7 @@ UserSchema.statics.getUserShortDataByUsername = async function (idapp, username)
});
if (myrec) {
myrec.qualified = await User.isUserQualified7(idapp, myrec.username);
myrec.numinvitati = await User.getnumInvitati(idapp, myrec.username);
myrec.numinvitatiattivi = await User.getnumInvitatiAttivi(idapp, myrec.username);
}
@@ -395,6 +416,7 @@ UserSchema.statics.getDownlineByUsername = async function (idapp, username) {
if (!!arrrec) {
for (const rec of arrrec) {
rec._doc.qualified = await User.isUserQualified7(idapp, rec.username);
rec._doc.numinvitati = await User.getnumInvitati(idapp, rec.username);
rec._doc.numinvitatiattivi = await User.getnumInvitatiAttivi(idapp, rec.username);
}
@@ -411,9 +433,55 @@ UserSchema.statics.getnumInvitatiAttivi = function (idapp, username) {
return User.count({
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.saw_and_accepted': 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 },
});
};
UserSchema.statics.isUserQualified7 = async function (idapp, username) {
const User = this;
const myrec = await User.findOne({
'idapp': idapp,
'username': username,
$or: [
{
special_req: true
},
{
verified_email: true,
'profile.teleg_id': { $gt: 1 },
'profile.saw_and_accepted': shared_consts.ALL_SAW_AND_ACCEPTED,
'profile.saw_zoom_presentation': true,
'profile.my_dream': { $exists: true },
'profile.email_paypal': { $exists: true },
$and: [
{ "$expr": { "$gt": [{ "$strLenCP": "$profile.my_dream" }, 10] } },
{ "$expr": { "$gt": [{ "$strLenCP": "$profile.email_paypal" }, 6] } }
],
$where: "this.profile.paymenttypes.length >= 1",
}]
});
return !!myrec;
};
UserSchema.statics.getnumPaymentOk = function (idapp) {
const User = this;
return User.count({
idapp,
$where: "this.profile.paymenttypes.length >= 1",
'profile.email_paypal': { $exists: true },
});
};
@@ -488,6 +556,21 @@ UserSchema.statics.getLastUser = function (idapp) {
return User.findOne({ idapp }).sort({ ind_order: -1 })
};
UserSchema.statics.findByIndOrder = function (idapp, ind_order) {
const User = this;
try {
return User.findOne({
'idapp': idapp,
'ind_order': ind_order,
});
} catch (e) {
}
};
UserSchema.pre('save', function (next) {
const user = this;
@@ -561,7 +644,7 @@ UserSchema.statics.TelegIdByUsername = async function (idapp, username) {
});
};
UserSchema.statics.SetTelegramCheckCode = async function (idapp, username, teleg_checkcode) {
UserSchema.statics.SetTelegramCheckCode = async function (idapp, id, teleg_checkcode) {
const User = this;
const fields_to_update = {
@@ -569,25 +652,42 @@ UserSchema.statics.SetTelegramCheckCode = async function (idapp, username, teleg
};
return await User.findOneAndUpdate({
idapp,
username
_id: id
}, { $set: fields_to_update }, { new: false }).then((record) => {
return !!record;
});
};
UserSchema.statics.SetTelegramIdSuccess = async function (idapp, username, teleg_id) {
UserSchema.statics.SetTelegramIdSuccess = async function (idapp, id, teleg_id) {
const User = this;
const fields_to_update = {
'profile.teleg_id': teleg_id,
'profile.teleg_id_old': 0,
'profile.teleg_checkcode': 0
};
return await User.findOneAndUpdate({
idapp,
username
_id: id
}, { $set: fields_to_update }, { new: false }).then((record) => {
return record;
});
};
UserSchema.statics.SetTelegramWasBlocked = async function (idapp, teleg_id) {
const User = this;
const fields_to_update = {
'profile.teleg_id_old': teleg_id,
'profile.teleg_id': 0,
};
const ris = await User.findOneAndUpdate({
idapp,
'profile.teleg_id': teleg_id
}, { $set: fields_to_update }, { new: false }).then((record) => {
return record;
});
@@ -609,7 +709,7 @@ UserSchema.statics.getNameSurnameByUsername = async function (idapp, username) {
UserSchema.statics.getusersManagers = async function (idapp) {
const User = this;
return await User.find({ idapp, 'profile.manage_telegram': true }, { 'profile.teleg_id': 1 })
return await User.find({ idapp, 'profile.manage_telegram': true }, { 'profile.teleg_id': 1, perm: 1 })
.then((arrrec) => {
return (!!arrrec) ? arrrec : null;
}).catch((e) => {
@@ -620,11 +720,11 @@ UserSchema.statics.getusersManagers = async function (idapp) {
UserSchema.statics.getUsersTelegALL = async function (idapp) {
const User = this;
return await User.find({ idapp, 'profile.teleg_id': { $gt: 0 } }, { 'profile.teleg_id': 1, perm: 1 })
return await User.find({ idapp, 'profile.teleg_id': { $gt: 0 } })
.then((arrrec) => {
return (!!arrrec) ? arrrec : null;
}).catch((e) => {
console.error('getusersManagers', e);
console.error('getUsersTelegALL', e);
});
};
@@ -813,6 +913,58 @@ UserSchema.statics.getUsersRegistered = async function (idapp) {
return await User.count(myfind);
};
UserSchema.statics.getUsersQualified = async function (idapp, numinvitati) {
const User = this;
const arrusers = await User.find({
idapp,
$or: [
{
special_req: true
},
{
verified_email: true,
'profile.teleg_id': { $gt: 0 },
$where: "this.profile.paymenttypes.length >= 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] } }
],
}]
}, {
'username': 1,
});
if (numinvitati === 0)
return arrusers; // PRENDI TUTTI
let arrris = [];
for (const rec of arrusers) {
rec.numinvitatiattivi = await User.getnumInvitatiAttivi(idapp, rec.username);
if (rec.numinvitatiattivi >= numinvitati) {
arrris.push(rec);
}
}
return arrris
};
UserSchema.statics.getNumUsersQualified = async function (idapp, numinvitati) {
arrrec = await this.getUsersQualified(idapp, numinvitati);
return arrrec.length
};
UserSchema.statics.getEmailNotVerified = async function (idapp) {
const User = this;
@@ -964,6 +1116,47 @@ if (tools.INITDB_FIRSTIME) {
// UserSchema.index({ surname: 1 });
}
async function addUtentiInLista(idapp, mode) {
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);
if (mode === 1) {
// 9 punti qualificati
ok = qualified && (numinvitatiattivi >= 2);
} else if (mode === 2) {
// 7 punti qualificati
ok = qualified;
} else {
ok = true;
// // almeno telegram ID
// ok = user.profile.teleg_id > 0;
// } else {
// ok = true;
}
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();
num++;
}
}
}
return num;
}
UserSchema.statics.DbOp = async function (idapp, mydata) {
const User = this;
try {
@@ -971,14 +1164,52 @@ UserSchema.statics.DbOp = async function (idapp, mydata) {
arrusers = await User.find({ 'idapp': idapp });
let num = 0;
for (const rec of arrusers) {
let mycell = tools.removespaces(rec.profile.intcode_cell + rec.profile.cell);
await User.findOneAndUpdate({ _id: rec._id }, { $set: { 'profile.cell': mycell } })
num++;
// DISATTIVATO: ORA NON MI SERVE PIU
if (false) {
let mycell = tools.removespaces(rec.profile.intcode_cell + rec.profile.cell);
await User.findOneAndUpdate({ _id: rec._id }, { $set: { 'profile.cell': mycell } });
num++;
}
}
return { num };
// return await User.updateMany({ idapp }, { $set: { 'profile.cell': { $concat: ["$profile.intcode_cell", "$profile.cell"] } } })
} else if (mydata.dbop === 'changeEmailLowerCase') {
arrusers = await User.find({ 'idapp': idapp });
let num = 0;
for (const rec of arrusers) {
let myemail = rec.email.toLowerCase();
if (myemail !== rec.email) {
await User.findOneAndUpdate({ _id: rec._id }, { $set: { 'email': myemail } });
num++;
}
}
return { num };
} else if (mydata.dbop === 'creaLista') {
await ListaIngresso.remove({ idapp });
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, 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);
@@ -987,6 +1218,7 @@ UserSchema.statics.DbOp = async function (idapp, mydata) {
};
const User = mongoose.model('User', UserSchema);