Sistemazioni varie BUGS

This commit is contained in:
paoloar77
2022-03-10 23:19:56 +01:00
parent 0d916ac81d
commit d60be7c89e
8 changed files with 75 additions and 30 deletions

View File

@@ -549,8 +549,11 @@ UserSchema.statics.findByCredentials = function(idapp, username, password, pwdcr
const User = this;
let pwd = '';
let regexp = new RegExp(`${username}`, 'i');
return User.findOne({
idapp, username: username,
idapp,
username: {$regex: regexp},
$or: [
{deleted: {$exists: false}},
{deleted: {$exists: true, $eq: false}},
@@ -641,13 +644,14 @@ UserSchema.statics.findByUsername = async function(idapp, username, alsoemail, o
});
};
UserSchema.statics.getUserShortDataByUsername = async function(
idapp, username) {
UserSchema.statics.getUserShortDataByUsername = async function(idapp, username) {
const User = this;
let regexp = new RegExp(`${username}`, 'i');
const myrec = await User.findOne({
'idapp': idapp,
'username': username,
username: {$regex: regexp},
$or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}],
}, {
idapp: 1,
@@ -898,7 +902,11 @@ UserSchema.statics.setVerifiedByAportador = async function(
const userver = await User.findOne(myquery, {verified_by_aportador: 1}).lean();
if (userver.verified_by_aportador !== valuebool) {
let scrivi = true;
if (userver) {
scrivi = userver.verified_by_aportador !== valuebool;
}
if (scrivi) {
const myrec = await User.findOneAndUpdate(myquery,
{$set: {'verified_by_aportador': valuebool}}, {new: false});
@@ -2080,7 +2088,7 @@ UserSchema.statics.SetTelegramIdSuccess = async function(idapp, id, teleg_id) {
if (record) {
return User.findOne({
idapp,
_id: id
_id: id,
}).lean();
}
});
@@ -2173,12 +2181,11 @@ UserSchema.statics.getNameSurnameByUsername = async function(
UserSchema.statics.getIdByUsername = async function(idapp, username) {
const User = this;
let regexp = new RegExp(`${username}`, 'i')
let regexp = new RegExp(`${username}`, 'i');
return User.findOne({
idapp,
username :
{ $regex: regexp },
username: {$regex: regexp},
$or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}],
}, {username: 1, _id: 1}).then((rec) => {
return (!!rec) ? rec._id.toString() : '';
@@ -2190,12 +2197,12 @@ UserSchema.statics.getIdByUsername = async function(idapp, username) {
UserSchema.statics.getRealUsernameByUsername = async function(idapp, username) {
const User = this;
let regexp = new RegExp(`${username}`, 'i')
let regexp = new RegExp(`${username}`, 'i');
return User.findOne({
idapp,
username :
{ $regex: regexp },
username:
{$regex: regexp},
$or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}],
}, {username: 1, _id: 1}).then((rec) => {
return (!!rec) ? rec.username : '';
@@ -2548,6 +2555,21 @@ UserSchema.statics.getUsersRegistered = async function(idapp) {
return User.count(myfind);
};
UserSchema.statics.getUsersOnLineToday = async function(idapp) {
const User = this;
let starttoday = new Date();
starttoday.setHours(6, 0, 0, 0);
const myfind = {
idapp,
$or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}],
lasttimeonline: {$gt: starttoday},
};
return User.count(myfind);
};
/*
UserSchema.statics.getUsersQualified = async function (idapp, numinvitati) {
const User = this;
@@ -2648,8 +2670,8 @@ UserSchema.statics.getUsersAutorizzare = async function(idapp) {
const myfind = {
idapp,
$or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}],
'profile.teleg_id': {$gt: 0},
$or: [{verified_by_aportador: {$exists: false}}, {verified_by_aportador: {$exists: true, $eq: false}}],
'profile.teleg_id': { $gt: 0 },
verified_by_aportador: { $exists: false },
};
return User.count(myfind);