fix Saldo when press refuse coins.

fix Risolvere problema del ritardo quando si fa il primo login...
This commit is contained in:
Paolo Arena
2022-09-16 17:38:49 +02:00
parent 9f34a6b916
commit 671a39e51c
11 changed files with 162 additions and 62 deletions

View File

@@ -1375,6 +1375,9 @@ UserSchema.statics.getUserProfileByUsername = async function(
lang: 1,
index: 1,
username: 1,
aportador_solidario: 1,
name: 1,
surname: 1,
deleted: 1,
sospeso: 1,
reported: 1,
@@ -1382,12 +1385,28 @@ UserSchema.statics.getUserProfileByUsername = async function(
username_who_report: 1,
verified_email: 1,
verified_by_aportador: 1,
aportador_solidario: 1,
date_reg: 1,
'profile.nationality': 1,
'profile.mygroups': 1,
'profile.mycircuits': 1,
'profile.qualifica': 1,
'profile.biografia': 1,
'profile.teleg_id': 1,
'profile.username_telegram': 1,
'profile.firstname_telegram': 1,
'profile.lastname_telegram': 1,
'profile.intcode_cell': 1,
'profile.cell': 1,
'profile.website': 1,
'profile.img': 1,
"useraport.username": 1,
"useraport.profile.img": 1,
'profile.sex': 1,
'profile.dateofbirth': 1,
'profile.born_city_id': 1,
'profile.born_province': 1,
'profile.born_country': 1,
email: 1,
date_reg: 1,
'useraport.username': 1,
'useraport.profile.img': 1,
};
} else if (perm === tools.Perm.PERM_FRIEND) {
@@ -1425,8 +1444,8 @@ UserSchema.statics.getUserProfileByUsername = async function(
'profile.born_country': 1,
email: 1,
date_reg: 1,
"useraport.username": 1,
"useraport.profile.img": 1,
'useraport.username': 1,
'useraport.profile.img': 1,
};
} else if (perm === tools.Perm.PERM_ALL) {
@@ -1467,8 +1486,8 @@ UserSchema.statics.getUserProfileByUsername = async function(
'comune': 1,
email: 1,
date_reg: 1,
"useraport.username": 1,
"useraport.profile.img": 1,
'useraport.username': 1,
'useraport.profile.img': 1,
};
}
@@ -1488,28 +1507,33 @@ UserSchema.statics.getUserProfileByUsername = async function(
},
},
{
"$lookup": {
"from": 'users',
'$lookup': {
'from': 'users',
let: {
"idapp": "$idapp",
"user_name": "$aportador_solidario"
'idapp': '$idapp',
'user_name': '$aportador_solidario',
},
pipeline: [
{ "$match": {
"$expr": {
{
'$match': {
'$expr': {
$and: [
{ $eq: ['$username', '$$user_name'] },
{ $eq: ['$idapp','$$idapp'] }
]
}
}
}
{$eq: ['$username', '$$user_name']},
{$eq: ['$idapp', '$$idapp']},
],
},
},
},
],
as: 'useraport'
}
as: 'useraport',
},
},
{
$unwind:'$useraport'
$unwind:
{
path: '$useraport',
preserveNullAndEmptyArrays: true,
},
},
{
@@ -1833,17 +1857,20 @@ UserSchema.statics.setFriendsCmd = async function(req, idapp, usernameOrig, user
if (ris) {
// Send a notification to the DESTINATION!
// Sei stato segnalato da %s per comportamenti non idonei. Contatta %s per chiarimenti
await SendNotif.createNewNotifToSingleUser(req, null, {username_worked, usernameDest, username_action}, false, shared_consts.TypeNotifs.TYPEDIR_FRIENDS,
await SendNotif.createNewNotifToSingleUser(req, null, {username_worked, usernameDest, username_action}, false,
shared_consts.TypeNotifs.TYPEDIR_FRIENDS,
shared_consts.TypeNotifs.ID_FRIENDS_REPORTED);
// Send a notification to the SENDER !
// Hai segnalato %s da %s per comportamenti non idonei.
await SendNotif.createNewNotifToSingleUser(req, null, {username_worked, usernameDest: username_action, username_action}, false, shared_consts.TypeNotifs.TYPEDIR_FRIENDS,
await SendNotif.createNewNotifToSingleUser(req, null, {username_worked, usernameDest: username_action, username_action}, false,
shared_consts.TypeNotifs.TYPEDIR_FRIENDS,
shared_consts.TypeNotifs.ID_FRIENDS_REPORTED);
if (usernameOrig !== telegrambot.ADMIN_USER_SERVER) {
// Send a notification to the Admin
await SendNotif.createNewNotifToSingleUser(req, null, {username_worked, usernameDest: telegrambot.ADMIN_USER_SERVER, username_action, isAdmin: true}, false,
await SendNotif.createNewNotifToSingleUser(req, null,
{username_worked, usernameDest: telegrambot.ADMIN_USER_SERVER, username_action, isAdmin: true}, false,
shared_consts.TypeNotifs.TYPEDIR_FRIENDS,
shared_consts.TypeNotifs.ID_FRIENDS_REPORTED);
}
@@ -1862,7 +1889,8 @@ UserSchema.statics.setFriendsCmd = async function(req, idapp, usernameOrig, user
if (ris) {
// Send a notification to the DESTINATION!
await SendNotif.createNewNotifToSingleUser(req, null, {username_worked, usernameDest, username_action}, false, shared_consts.TypeNotifs.TYPEDIR_FRIENDS,
await SendNotif.createNewNotifToSingleUser(req, null, {username_worked, usernameDest, username_action}, false,
shared_consts.TypeNotifs.TYPEDIR_FRIENDS,
shared_consts.TypeNotifs.ID_FRIENDS_UNBLOCKED);
// Send a notification to the SENDER !
@@ -1873,7 +1901,8 @@ UserSchema.statics.setFriendsCmd = async function(req, idapp, usernameOrig, user
if (usernameOrig !== telegrambot.ADMIN_USER_SERVER) {
// Send a notification to the Admin
await SendNotif.createNewNotifToSingleUser(req, null, {username_worked, usernameDest: telegrambot.ADMIN_USER_SERVER, username_action, isAdmin: true}, false,
await SendNotif.createNewNotifToSingleUser(req, null,
{username_worked, usernameDest: telegrambot.ADMIN_USER_SERVER, username_action, isAdmin: true}, false,
shared_consts.TypeNotifs.TYPEDIR_FRIENDS,
shared_consts.TypeNotifs.ID_FRIENDS_UNBLOCKED);
}
@@ -1936,7 +1965,6 @@ UserSchema.statics.countUsersInCircuit = async function(idapp, circuitname) {
};
UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameDest, cmd, value, username_action) {
let ris = null;
@@ -2212,7 +2240,8 @@ UserSchema.statics.setCircuitCmd = async function(idapp, usernameOrig, circuitna
if (outres.cansend) {
// Invia una notifica di moneta alla persona
outres.result = await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, false, true, username_action, extrarec);
outres.result = await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, false, true, username_action,
extrarec);
} else {
outres.cansend = false;
}
@@ -2239,10 +2268,8 @@ UserSchema.statics.setCircuitCmd = async function(idapp, usernameOrig, circuitna
outres.cansend = true;
}
if (outres.cansend) {
// Invia una notifica di moneta alla persona
await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, false, true, username_action, extrarec);
}
// Invia una notifica di moneta (accettata o rifiutata) alla persona
await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, false, true, username_action, extrarec);
outres.recnotif = await SendNotif.getRecNotif(extrarec.notifId);
@@ -3772,9 +3799,13 @@ UserSchema.statics.addExtraInfo = async function(idapp, recUser) {
try {
if (recUser._doc.profile.notifs.length <= 0) {
recUser._doc.profile.notifs = shared_consts.DEFAULT_NOTIFS_USER;
await recUser.save();
try {
if (recUser._doc.profile && recUser._doc.profile.notifs && recUser._doc.profile.notifs.length <= 0) {
recUser._doc.profile.notifs = shared_consts.DEFAULT_NOTIFS_USER;
await recUser.save();
}
} catch (e) {
console.error('Err addExtraInfo notifs ', e);
}
const listSentMyRequestFriends = await User.find({
@@ -3841,10 +3872,12 @@ UserSchema.statics.addExtraInfo = async function(idapp, recUser) {
recUser._doc.profile = {...recUser._doc.profile, ...circuitobj, useraccounts};
recUser._doc.calcstat = await User.calculateStat(idapp, recUser.username);
return recUser._doc;
} catch (e) {
console.error('Err', e);
console.error('Err addExtraInfo', e);
}
return recUser;