- Add saldo to member's list
This commit is contained in:
@@ -504,6 +504,86 @@ CircuitSchema.statics.getUserCircuits = async function(idapp, username) {
|
||||
|
||||
};
|
||||
|
||||
CircuitSchema.statics.getUsersSingleCircuit = async function(idapp, username, circuitname, circuitId) {
|
||||
|
||||
const {User} = require('../models/user');
|
||||
|
||||
try {
|
||||
let aggr1 = [
|
||||
{
|
||||
$match: {
|
||||
idapp: idapp,
|
||||
'profile.mycircuits': {
|
||||
$elemMatch: {circuitname: {$eq: circuitname}},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
/*{
|
||||
$lookup: {
|
||||
from: 'circuits',
|
||||
as: 'circuit',
|
||||
let: {circuitname: circuitname, idapp: '$idapp'},
|
||||
pipeline: [
|
||||
{
|
||||
$match:
|
||||
{
|
||||
$expr:
|
||||
{
|
||||
$and:
|
||||
[
|
||||
{$eq: ['$name', '$$circuitname']},
|
||||
{$eq: ['$idapp', '$$idapp']},
|
||||
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
},
|
||||
{$unwind: '$circuit'},
|
||||
*/
|
||||
{
|
||||
$project: {username: 1, profile: 1, idapp: 1 /*, 'circuit.name': 1, 'circuit._id': 1*/},
|
||||
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: 'accounts',
|
||||
as: 'account',
|
||||
let: {username: '$username', idapp: '$idapp', circuitId: circuitId /*, circuitId: '$circuit._id' */ },
|
||||
pipeline: [
|
||||
{
|
||||
$match:
|
||||
{
|
||||
$expr:
|
||||
{
|
||||
$and:
|
||||
[
|
||||
{$eq: ['$$username', '$username']},
|
||||
{$eq: ['$$idapp', '$idapp']},
|
||||
{$eq: ['$$circuitId', '$circuitId']},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{$unwind: '$account'},
|
||||
];
|
||||
|
||||
ris = await User.aggregate(aggr1);
|
||||
|
||||
return ris;
|
||||
} catch (e) {
|
||||
console.error('e', e);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
CircuitSchema.statics.getCircolanteSingolaTransaz = function(accountorigTable, accountdestTable) {
|
||||
|
||||
let circolante = 0;
|
||||
@@ -647,7 +727,7 @@ CircuitSchema.statics.updateData = async function(idapp, circuitname) {
|
||||
};
|
||||
const risult = await this.updateOne({idapp, name: circuitname}, {$set: paramstoupdate});
|
||||
|
||||
console.log('risult', risult)
|
||||
console.log('risult', risult);
|
||||
|
||||
} catch (e) {
|
||||
console.error('Err', e);
|
||||
|
||||
@@ -1238,15 +1238,21 @@ UserSchema.statics.createNewReqRegistrationGetLink = async function(idapp, usern
|
||||
});
|
||||
|
||||
if (user) {
|
||||
if (!user.date_tokenreg || (user.tokenreg && (user.date_tokenreg < new Date().getTime()))) {
|
||||
if (!user.date_tokenreg || (!user.tokenreg) || (user.tokenreg && (user.date_tokenreg < new Date().getTime()))) {
|
||||
// Se è scaduto, ne crea uno nuovo
|
||||
// Creo il tokenforgot
|
||||
user.tokenreg = jwt.sign(user._id.toHexString(), process.env.SIGNCODE).
|
||||
toString();
|
||||
|
||||
user.tokenreg = user.tokenreg.replaceAll('.', '');
|
||||
user.tokenreg = user.tokenreg.replaceAll('/', '');
|
||||
user.tokenreg = user.tokenreg.substring(1,8);
|
||||
if (user.tokenreg){
|
||||
try {
|
||||
user.tokenreg = user.tokenreg.replaceAll('.', '');
|
||||
user.tokenreg = user.tokenreg.replaceAll('/', '');
|
||||
user.tokenreg = user.tokenreg.substring(1,8);
|
||||
}catch (e) {
|
||||
console.error('err', e);
|
||||
}
|
||||
}
|
||||
|
||||
user.date_tokenreg = tools.AddDate(new Date(), 2);
|
||||
|
||||
|
||||
@@ -31,7 +31,6 @@ async function getCircuitRecAdminsInfo(idapp, data) {
|
||||
router.post('/load', authenticate, async (req, res) => {
|
||||
const idapp = req.body.idapp;
|
||||
const path = req.body.path;
|
||||
const circuitId = req.body.circuitId;
|
||||
const usernameOrig = req.user.username;
|
||||
|
||||
try {
|
||||
@@ -48,7 +47,7 @@ router.post('/load', authenticate, async (req, res) => {
|
||||
|
||||
const whatshowUsers = await User.getWhatToShow_IfFriends(idapp, req.user.username);
|
||||
|
||||
let users_in_circuit = [];
|
||||
/*let users_in_circuit = [];
|
||||
|
||||
if (data) {
|
||||
users_in_circuit = await User.find(
|
||||
@@ -61,6 +60,9 @@ router.post('/load', authenticate, async (req, res) => {
|
||||
whatshowUsers,
|
||||
).lean();
|
||||
}
|
||||
*/
|
||||
|
||||
const users_in_circuit = await Circuit.getUsersSingleCircuit(idapp, req.user.username, data.name, data._id);
|
||||
|
||||
data = await getCircuitRecAdminsInfo(idapp, data);
|
||||
|
||||
|
||||
@@ -426,6 +426,10 @@ router.post('/settable', authenticate, async (req, res) => {
|
||||
await SendNotif.createNewNotification(req, res, {groupnameDest, circuitnameDest}, params.table, myrec, typedir, typeid);
|
||||
}
|
||||
|
||||
if (params.table === 'circuits') {
|
||||
await Circuit.updateData(myrec.idapp, myrec.name);
|
||||
}
|
||||
|
||||
if (params.table === shared_consts.TAB_MYGROUPS && isnewrec) {
|
||||
// nuovo Record:
|
||||
// aggiungi il creatore al gruppo stesso
|
||||
@@ -789,6 +793,7 @@ router.patch('/chval', authenticate, async (req, res) => {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (mydata.table === 'users') {
|
||||
if (camporequisiti) {
|
||||
await User.checkIfSbloccatiRequisiti(idapp, allData, id);
|
||||
|
||||
@@ -436,6 +436,9 @@ async function inizia() {
|
||||
await telegrambot.sendMsgTelegramToTheAdminAllSites(`Ciao Admin\n` + `🔅🔅🔅 Il Server col BOT di {appname} è appena ripartito!`, false);
|
||||
|
||||
}
|
||||
|
||||
console.log(process.versions);
|
||||
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
|
||||
@@ -1867,6 +1867,11 @@ module.exports = {
|
||||
}
|
||||
}
|
||||
|
||||
if (params.filterextra) {
|
||||
if (params.filterextra.length > 0)
|
||||
query = [...params.filterextra];
|
||||
}
|
||||
|
||||
if (filtriadded) {
|
||||
if (filtriadded.length > 0)
|
||||
query.push({$match: {$and: filtriadded}});
|
||||
|
||||
177
src/server/tools/prova.js
Normal file
177
src/server/tools/prova.js
Normal file
@@ -0,0 +1,177 @@
|
||||
[
|
||||
{
|
||||
"0": {
|
||||
"$match": {
|
||||
"idapp": "13",
|
||||
"profile.mycircuits": {
|
||||
"$elemMatch": {
|
||||
"circuitname": {
|
||||
"$eq": "RISO Test"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"1": {
|
||||
"$lookup": {
|
||||
"from": "circuits",
|
||||
"as": "circuit",
|
||||
"let": {
|
||||
"circuitname": "RISO Test",
|
||||
"idapp": "$idapp"
|
||||
},
|
||||
"pipeline": [
|
||||
{
|
||||
"$match": {
|
||||
"$expr": {
|
||||
"$and": [
|
||||
{
|
||||
"$eq": [
|
||||
"$name",
|
||||
"$$circuitname"
|
||||
]
|
||||
},
|
||||
{
|
||||
"$eq": [
|
||||
"$idapp",
|
||||
"$$idapp"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"2": {
|
||||
"$unwind": "$circuit"
|
||||
},
|
||||
"3": {
|
||||
"$project": {
|
||||
"username": 1,
|
||||
"profile": 1,
|
||||
"idapp": 1,
|
||||
"circuit.name": 1,
|
||||
"circuit._id": 1
|
||||
}
|
||||
},
|
||||
"4": {
|
||||
"$lookup": {
|
||||
"from": "accounts",
|
||||
"as": "account",
|
||||
"let": {
|
||||
"username": "$username",
|
||||
"idapp": "$idapp",
|
||||
"circuitId": "$circuit._id"
|
||||
},
|
||||
"pipeline": [
|
||||
{
|
||||
"$match": {
|
||||
"$expr": {
|
||||
"$and": [
|
||||
{
|
||||
"$eq": [
|
||||
"$$username",
|
||||
"$username"
|
||||
]
|
||||
},
|
||||
{
|
||||
"$eq": [
|
||||
"$$idapp",
|
||||
"$idapp"
|
||||
]
|
||||
},
|
||||
{
|
||||
"$eq": [
|
||||
"$$circuitId",
|
||||
"$circuitId"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"5": {
|
||||
"$unwind": "$account"
|
||||
}
|
||||
},
|
||||
{
|
||||
"$match": {
|
||||
"idapp": "13"
|
||||
}
|
||||
},
|
||||
{
|
||||
"$sort": {
|
||||
"desc": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"$addFields": {
|
||||
"myId1": {
|
||||
"$toObjectId": "$userId"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"$lookup": {
|
||||
"from": "users",
|
||||
"localField": "myId1",
|
||||
"foreignField": "_id",
|
||||
"as": "user"
|
||||
}
|
||||
},
|
||||
{
|
||||
"$replaceRoot": {
|
||||
"newRoot": {
|
||||
"$mergeObjects": [
|
||||
{
|
||||
"$arrayElemAt": [
|
||||
"$user",
|
||||
0
|
||||
]
|
||||
},
|
||||
"$$ROOT"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"$project": {
|
||||
"username": 1,
|
||||
"profile.img": 1,
|
||||
"profile.mycircuits": 1,
|
||||
"profile.qualifica": 1,
|
||||
"account.saldo": 1,
|
||||
"reported": 1,
|
||||
"date_report": 1,
|
||||
"username_who_report": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"$group": {
|
||||
"_id": null,
|
||||
"count": {
|
||||
"$sum": 1
|
||||
},
|
||||
"results": {
|
||||
"$push": "$$ROOT"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"$project": {
|
||||
"count": 1,
|
||||
"rows": {
|
||||
"$slice": [
|
||||
"$results",
|
||||
0,
|
||||
10
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user