- Statistiche
- Menu e Sottomenu - Lista ultimi Movimenti
This commit is contained in:
44879
docs/test.js
Normal file
44879
docs/test.js
Normal file
File diff suppressed because one or more lines are too long
12
logtrans.txt
12
logtrans.txt
@@ -245,3 +245,15 @@ Mer 03/07 ORE 13:20: [<b>Circuito RIS Bologna</b>]: Inviate Monete da pontiUmani
|
||||
Saldi:
|
||||
pontiUmani (paoloar77): -349.00 RIS]
|
||||
SuryaArena: 18.00 RIS]
|
||||
Mer 18/09 ORE 15:38: [<b>Circuito RIS Rimini</b>]: Inviate Monete da paoloar77 a TestTransazPao 1 RIS [causale: ]
|
||||
Saldi:
|
||||
paoloar77: -2.00 RIS]
|
||||
TestTransazPao: 1.00 RIS]
|
||||
Mer 18/09 ORE 15:41: [<b>Circuito RIS Rimini</b>]: Inviate Monete da marco.bi a TestTransazPao 5 RIS [causale: ]
|
||||
Saldi:
|
||||
marco.bi: -5.00 RIS]
|
||||
TestTransazPao: 6.00 RIS]
|
||||
Mer 18/09 ORE 15:43: [<b>Circuito RIS Rimini</b>]: Inviate Monete da marco.bi a TestTransazPao 2 RIS [causale: ]
|
||||
Saldi:
|
||||
marco.bi: -7.00 RIS]
|
||||
TestTransazPao: 8.00 RIS]
|
||||
@@ -1637,6 +1637,34 @@ CircuitSchema.statics.replaceAllCircuitNames = async function (idapp) {
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
CircuitSchema.statics.getnumCircuits = async function (idapp) {
|
||||
const Circuit = this;
|
||||
|
||||
const numcirc = await Circuit.countDocuments(
|
||||
{
|
||||
idapp,
|
||||
transactionsEnabled: true,
|
||||
});
|
||||
|
||||
return numcirc;
|
||||
|
||||
};
|
||||
|
||||
CircuitSchema.statics.getnumActiveCircuits = async function (idapp) {
|
||||
const Circuit = this;
|
||||
|
||||
const numcirc = await Circuit.countDocuments(
|
||||
{
|
||||
idapp,
|
||||
transactionsEnabled: true,
|
||||
totTransato: { $gt: 1 },
|
||||
});
|
||||
|
||||
return numcirc;
|
||||
|
||||
};
|
||||
|
||||
CircuitSchema.statics.addMovementByOrdersCart = async function (ordersCart, usernameDest, groupDest) {
|
||||
|
||||
const { User } = require('../models/user');
|
||||
|
||||
@@ -671,6 +671,48 @@ MovementSchema.statics.getQueryAllUsersMovsByCircuitId = async function (idapp,
|
||||
return [];
|
||||
};
|
||||
|
||||
MovementSchema.statics.getTotal_Transactions = async function (idapp) {
|
||||
const MyMovement = this;
|
||||
|
||||
const numtransac = await MyMovement.countDocuments(
|
||||
{
|
||||
idapp,
|
||||
});
|
||||
|
||||
return numtransac;
|
||||
|
||||
};
|
||||
|
||||
MovementSchema.statics.getTot_RIS_Transati = async function (idapp) {
|
||||
const MyMovement = this;
|
||||
|
||||
// Utilizza l'aggregazione per sommare tutti gli 'amount' per un dato 'idapp'
|
||||
const numtot = await MyMovement.aggregate([
|
||||
{
|
||||
$match: { idapp } // Filtra i documenti per 'idapp'
|
||||
},
|
||||
{
|
||||
$sort: {
|
||||
transactionDate: -1,
|
||||
}
|
||||
},
|
||||
{
|
||||
$group: {
|
||||
_id: null,
|
||||
totalAmount: { $sum: "$amount" } // Somma tutti gli 'amount'
|
||||
}
|
||||
}
|
||||
]);
|
||||
|
||||
try {
|
||||
return numtot.length > 0 ? numtot[0].totalAmount : 0;
|
||||
} catch (e) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
MovementSchema.statics.getMovsByCircuitId = async function (idapp, username, circuitId) {
|
||||
const MyMovement = this;
|
||||
|
||||
@@ -699,6 +741,284 @@ MovementSchema.statics.checkIfCoinsAlreadySent = async function (notifId) {
|
||||
|
||||
};
|
||||
|
||||
MovementSchema.statics.getLastN_Transactions = async function (idapp, numtransaz = 10) {
|
||||
const MyMovement = this;
|
||||
|
||||
// get last "numtransaz" transactions
|
||||
|
||||
|
||||
let aggr1 = [
|
||||
{
|
||||
$match: {
|
||||
idapp,
|
||||
},
|
||||
},
|
||||
{
|
||||
$sort: {
|
||||
transactionDate: -1,
|
||||
}
|
||||
},
|
||||
{ $limit: numtransaz },
|
||||
{
|
||||
$lookup: {
|
||||
from: 'accounts',
|
||||
localField: 'accountFromId',
|
||||
foreignField: '_id',
|
||||
as: 'accfrom',
|
||||
},
|
||||
},
|
||||
{ $unwind: '$accfrom' },
|
||||
{
|
||||
$lookup: {
|
||||
from: 'users',
|
||||
let: { username: '$accfrom.username', idapp: '$accfrom.idapp' },
|
||||
pipeline: [
|
||||
{
|
||||
$match:
|
||||
{
|
||||
$expr:
|
||||
{
|
||||
$and:
|
||||
[
|
||||
{ $eq: ['$$username', '$username'] },
|
||||
{ $eq: ['$$idapp', '$idapp'] },
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
as: 'userfrom',
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: {
|
||||
path: '$userfrom',
|
||||
preserveNullAndEmptyArrays: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: 'mygroups',
|
||||
let: { groupname: '$accfrom.groupname', idapp: '$accfrom.idapp' },
|
||||
pipeline: [
|
||||
{
|
||||
$match:
|
||||
{
|
||||
$expr:
|
||||
{
|
||||
$and:
|
||||
[
|
||||
{ $eq: ['$$groupname', '$groupname'] },
|
||||
{ $eq: ['$$idapp', '$idapp'] },
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
as: 'groupfrom',
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: {
|
||||
path: '$groupfrom',
|
||||
preserveNullAndEmptyArrays: true,
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
$lookup: {
|
||||
from: 'circuits',
|
||||
let: { contocom: '$accfrom.contocom', idapp: '$accfrom.idapp' },
|
||||
pipeline: [
|
||||
{
|
||||
$match:
|
||||
{
|
||||
$expr:
|
||||
{
|
||||
$and:
|
||||
[
|
||||
{ $eq: ['$$contocom', '$path'] },
|
||||
{ $eq: ['$$idapp', '$idapp'] },
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
as: 'contocomfrom',
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: {
|
||||
path: '$contocomfrom',
|
||||
preserveNullAndEmptyArrays: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: 'accounts',
|
||||
localField: 'accountToId',
|
||||
foreignField: '_id',
|
||||
as: 'accto',
|
||||
},
|
||||
},
|
||||
{ $unwind: '$accto' },
|
||||
{
|
||||
$lookup: {
|
||||
from: 'circuits',
|
||||
localField: 'accfrom.circuitId',
|
||||
foreignField: '_id',
|
||||
as: 'circuitfrom',
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: '$circuitfrom',
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: 'circuits',
|
||||
localField: 'accto.circuitId',
|
||||
foreignField: '_id',
|
||||
as: 'circuitto',
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: '$circuitto',
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: 'users',
|
||||
let: { username: '$accto.username', idapp: '$accto.idapp' },
|
||||
pipeline: [
|
||||
{
|
||||
$match:
|
||||
{
|
||||
$expr:
|
||||
{
|
||||
$and:
|
||||
[
|
||||
{ $eq: ['$$username', '$username'] },
|
||||
{ $eq: ['$$idapp', '$idapp'] },
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
as: 'userto',
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: {
|
||||
path: '$userto',
|
||||
preserveNullAndEmptyArrays: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: 'mygroups',
|
||||
let: { groupname: '$accto.groupname', idapp: '$accto.idapp' },
|
||||
pipeline: [
|
||||
{
|
||||
$match:
|
||||
{
|
||||
$expr:
|
||||
{
|
||||
$and:
|
||||
[
|
||||
{ $eq: ['$$groupname', '$groupname'] },
|
||||
{ $eq: ['$$idapp', '$idapp'] },
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
as: 'groupto',
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: {
|
||||
path: '$groupto',
|
||||
preserveNullAndEmptyArrays: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: 'circuits',
|
||||
let: { contocom: '$accto.contocom', idapp: '$accto.idapp' },
|
||||
pipeline: [
|
||||
{
|
||||
$match:
|
||||
{
|
||||
$expr:
|
||||
{
|
||||
$and:
|
||||
[
|
||||
{ $eq: ['$$contocom', '$path'] },
|
||||
{ $eq: ['$$idapp', '$idapp'] },
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
as: 'contocomto',
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: {
|
||||
path: '$contocomto',
|
||||
preserveNullAndEmptyArrays: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
$project:
|
||||
{
|
||||
transactionDate: 1,
|
||||
amount: 1,
|
||||
causal: 1,
|
||||
notifId: 1,
|
||||
'circuitfrom.symbol': 1,
|
||||
'circuitfrom.name': 1,
|
||||
'circuitto.symbol': 1,
|
||||
'circuitto.name': 1,
|
||||
'userfrom.verified_by_aportador': 1,
|
||||
'userfrom.username': 1,
|
||||
'userfrom.profile.img': 1,
|
||||
'userto.username': 1,
|
||||
'userto.profile.img': 1,
|
||||
'userto.verified_by_aportador': 1,
|
||||
'groupfrom.groupname': 1,
|
||||
'groupfrom.verified_by_aportador': 1,
|
||||
'groupfrom.title': 1,
|
||||
'groupfrom.photos': 1,
|
||||
'groupto.groupname': 1,
|
||||
'groupto.title': 1,
|
||||
'groupto.photos': 1,
|
||||
'groupto.verified_by_aportador': 1,
|
||||
'contocomfrom.path': 1,
|
||||
'contocomfrom.name': 1,
|
||||
'contocomto.path': 1,
|
||||
'contocomto.name': 1,
|
||||
},
|
||||
},
|
||||
|
||||
];
|
||||
|
||||
const lastNtransac = await MyMovement.aggregate(aggr1);
|
||||
|
||||
/*
|
||||
transacDate: Date
|
||||
mitt_username: string
|
||||
mitt_group: string
|
||||
dest_username: string
|
||||
dest_group: string
|
||||
circuito: string
|
||||
amount: number
|
||||
causale: string
|
||||
|
||||
*/
|
||||
|
||||
|
||||
return lastNtransac;
|
||||
};
|
||||
|
||||
const Movement = mongoose.model('Movement', MovementSchema);
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ const myCard = new Schema(
|
||||
color: String,
|
||||
content: String,
|
||||
colorsub: String,
|
||||
link: String,
|
||||
}
|
||||
)
|
||||
const animation = new Schema(
|
||||
@@ -173,6 +174,8 @@ const MyElemSchema = new Schema({
|
||||
vers_img: {
|
||||
type: Number,
|
||||
},
|
||||
titleBanner: String,
|
||||
classBanner: String,
|
||||
listcards: [myCard],
|
||||
catalogo: catalogo,
|
||||
list: [
|
||||
|
||||
@@ -130,7 +130,13 @@ const MyPageSchema = new Schema({
|
||||
},
|
||||
showFooter: {
|
||||
type: Boolean,
|
||||
}
|
||||
},
|
||||
mainMenu: {
|
||||
type: Boolean,
|
||||
},
|
||||
sottoMenu: [{
|
||||
type: String
|
||||
}],
|
||||
});
|
||||
|
||||
MyPageSchema.statics.getFieldsForSearch = function () {
|
||||
@@ -169,10 +175,11 @@ MyPageSchema.statics.findOnlyStruttRec = async function (idapp) {
|
||||
});
|
||||
|
||||
const arrfixed = await MyPage.find(
|
||||
{ idapp,
|
||||
{
|
||||
idapp,
|
||||
$or: [
|
||||
{loadFirst: {$exists: false}},
|
||||
{loadFirst: {$exists: true, $eq: false}}],
|
||||
{ loadFirst: { $exists: false } },
|
||||
{ loadFirst: { $exists: true, $eq: false } }],
|
||||
}
|
||||
, {
|
||||
title: 1,
|
||||
@@ -190,6 +197,8 @@ MyPageSchema.statics.findOnlyStruttRec = async function (idapp) {
|
||||
iconsize: 1,
|
||||
extraclass: 1,
|
||||
loadFirst: 1,
|
||||
mainMenu: 1,
|
||||
sottoMenu: 1,
|
||||
}, (err, arrrec) => {
|
||||
return arrrec
|
||||
});
|
||||
|
||||
@@ -1132,7 +1132,7 @@ module.exports.getmsgorderTelegram = async function (ordersCart) {
|
||||
msg += '<br>Note: ' + ordersCart.note;
|
||||
|
||||
|
||||
msg += '<br><br>Lista Prodotti: (🍊🥑🍋)';
|
||||
msg += '<br><br>Lista Prodotti:'; // 🍊🥑🍋
|
||||
for (const ord of ordersCart.items) {
|
||||
msg += '<br>';
|
||||
let qtystr = ''
|
||||
|
||||
181
src/server/models/stat.js
Executable file
181
src/server/models/stat.js
Executable file
@@ -0,0 +1,181 @@
|
||||
const mongoose = require('mongoose').set('debug', false);
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
mongoose.Promise = global.Promise;
|
||||
mongoose.level = 'F';
|
||||
|
||||
const tools = require('../tools/general');
|
||||
|
||||
const { User } = require('../models/user');
|
||||
const { Movement } = require('../models/movement');
|
||||
const { Circuit } = require('../models/circuit');
|
||||
const { MyGroup } = require('../models/mygroup');
|
||||
const { Settings } = require('../models/settings');
|
||||
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
const { ObjectID } = require('mongodb');
|
||||
|
||||
// Resolving error Unknown modifier: $pushAll
|
||||
mongoose.plugin(schema => {
|
||||
schema.options.usePushEach = true;
|
||||
});
|
||||
|
||||
const StatSchema = new Schema({
|
||||
...{
|
||||
_id: {
|
||||
type: String,
|
||||
},
|
||||
idapp: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
num_reg: {
|
||||
type: Number,
|
||||
},
|
||||
date_created: {
|
||||
type: Date,
|
||||
default: Date.now,
|
||||
},
|
||||
num_reg: Number,
|
||||
num_reg_today: Number,
|
||||
online_today: Number,
|
||||
activeusers: Number,
|
||||
num_teleg_attivo: Number,
|
||||
num_autorizzati: Number,
|
||||
num_autorizzare: Number,
|
||||
num_teleg_pending: Number,
|
||||
arr_nations: [],
|
||||
numreg_untilday: Number,
|
||||
reg_daily: [],
|
||||
reg_weekly: [],
|
||||
lastsreg: [],
|
||||
lastsonline: [],
|
||||
lastssharedlink: [],
|
||||
diffusorilist: [],
|
||||
receiveRislist: [],
|
||||
receiveRislistgroup: [],
|
||||
strettelist: [],
|
||||
num_transaz_tot: Number,
|
||||
tot_RIS_transati: Number,
|
||||
num_circuiti: Number,
|
||||
num_circuiti_attivi: Number,
|
||||
num_annunci: Number,
|
||||
last_transactions: [],
|
||||
},
|
||||
});
|
||||
|
||||
StatSchema.statics.updateStats = async function (datastat) {
|
||||
|
||||
datastat.last_transactions.forEach(function (mov) {
|
||||
let ris = tools.getStringaConto(mov)
|
||||
mov.myfrom = ris.myfrom
|
||||
mov.myto = ris.myto
|
||||
mov.tipocontofrom = ris.tipocontofrom
|
||||
mov.tipocontoto = ris.tipocontoto
|
||||
});
|
||||
|
||||
|
||||
return datastat;
|
||||
};
|
||||
|
||||
StatSchema.statics.calculateStats = async function (idapp) {
|
||||
const Stat = this;
|
||||
|
||||
try {
|
||||
|
||||
let datastat = {
|
||||
idapp,
|
||||
num_reg: await User.getUsersRegistered(idapp),
|
||||
num_reg_today: await User.getUsersRegisteredToday(idapp),
|
||||
online_today: await User.getUsersOnLineToday(idapp),
|
||||
activeusers: await User.getUsersOnLineActive(idapp),
|
||||
num_teleg_attivo: await User.getUsersTelegramAttivo(idapp),
|
||||
num_autorizzati: await User.getUsersAutorizzati(idapp),
|
||||
num_autorizzare: await User.getUsersAutorizzare(idapp),
|
||||
num_teleg_pending: await User.getUsersTelegramPending(idapp),
|
||||
arr_nations: await User.findAllDistinctNationality(idapp),
|
||||
numreg_untilday: await User.calcnumRegUntilDay(idapp),
|
||||
reg_daily: await User.calcRegDaily(idapp),
|
||||
reg_weekly: await User.calcRegWeekly(idapp),
|
||||
lastsreg: await User.getLastUsers(idapp),
|
||||
lastsonline: await User.getLastOnlineUsers(idapp),
|
||||
lastssharedlink: await User.getLastSharedLink(idapp),
|
||||
diffusorilist: await User.getDiffusoriUsers(idapp),
|
||||
receiveRislist: await User.getReceiveRISUsers(idapp),
|
||||
receiveRislistgroup: await MyGroup.getReceiveRISGroups(idapp),
|
||||
strettelist: await User.getBestStretteDiManoUsers(idapp),
|
||||
num_transaz_tot: await Movement.getTotal_Transactions(idapp),
|
||||
tot_RIS_transati: await Movement.getTot_RIS_Transati(idapp),
|
||||
num_circuiti: await Circuit.getnumCircuits(idapp),
|
||||
num_circuiti_attivi: await Circuit.getnumActiveCircuits(idapp),
|
||||
num_annunci: await User.getnumAnnunci(idapp),
|
||||
last_transactions: await Movement.getLastN_Transactions(idapp, 10),
|
||||
};
|
||||
|
||||
// Trova il record di oggi:
|
||||
const trova_se_oggi = await Stat.findOne({ idapp, date_created: { $gte: new Date(new Date().setHours(0, 0, 0, 0)) } });
|
||||
|
||||
if (trova_se_oggi) {
|
||||
// Aggiorna il record di oggi:
|
||||
await Stat.updateOne({ _id: trova_se_oggi._id }, { $set: datastat });
|
||||
} else {
|
||||
// Aggiungi un nuovo record:
|
||||
await Stat.insertMany([datastat]);
|
||||
}
|
||||
|
||||
return datastat;
|
||||
|
||||
} catch (e) {
|
||||
console.error('Error', e);
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
StatSchema.statics.getStats = async function (idapp) {
|
||||
const Stat = this;
|
||||
|
||||
const minuti = await Settings.getValDbSettings(idapp, 'NUMMINUTI_STAT', 30);
|
||||
|
||||
// Ottieni l'ultimo record salvato:
|
||||
const rec = await Stat.findOne({ idapp })
|
||||
.sort({ date_created: -1 })
|
||||
.lean();
|
||||
|
||||
let isOld = true;
|
||||
|
||||
if (rec) {
|
||||
// se rec.date_created è più vecchio di minuti fa, allora ricalcola.
|
||||
const dateCreated = new Date(rec.date_created);
|
||||
const now = new Date();
|
||||
|
||||
// Calcola la differenza in millisecondi
|
||||
const difference = now - dateCreated; // Differenza in millisecondi
|
||||
|
||||
// Controlla se la differenza è maggiore di 10 minuti (10 * 60 * 1000 ms)
|
||||
isOld = (difference > minuti * 60 * 1000);
|
||||
}
|
||||
|
||||
let datastat = null;
|
||||
|
||||
if (isOld) {
|
||||
datastat = await Stat.calculateStats(idapp);
|
||||
|
||||
} else {
|
||||
datastat = rec;
|
||||
}
|
||||
|
||||
datastat = await Stat.updateStats(datastat);
|
||||
|
||||
return datastat;
|
||||
|
||||
};
|
||||
|
||||
|
||||
const Stat = mongoose.model('Stat', StatSchema);
|
||||
|
||||
Stat.createIndexes((err) => {
|
||||
if (err) throw err;
|
||||
});
|
||||
|
||||
module.exports = { Stat };
|
||||
@@ -4263,6 +4263,25 @@ UserSchema.statics.getUsersOnLineToday = async function (idapp) {
|
||||
return await User.countDocuments(myfind);
|
||||
};
|
||||
|
||||
|
||||
UserSchema.statics.getUsersOnLineActive = async function (idapp) {
|
||||
const User = this;
|
||||
|
||||
const numgiorni_attivi = await Settings.getValDbSettings(idapp, 'SHOW_LAST_ACTIVE_USERS', 90);
|
||||
|
||||
let daytocheck = new Date();
|
||||
daytocheck.setDate(daytocheck.getDate() - numgiorni_attivi);
|
||||
daytocheck.setHours(0, 0, 0, 0);
|
||||
|
||||
const myfind = {
|
||||
idapp,
|
||||
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
|
||||
lasttimeonline: { $gt: daytocheck },
|
||||
};
|
||||
|
||||
return await User.countDocuments(myfind);
|
||||
};
|
||||
|
||||
/*
|
||||
UserSchema.statics.getUsersQualified = async function (idapp, numinvitati) {
|
||||
const User = this;
|
||||
@@ -4465,7 +4484,7 @@ UserSchema.statics.getLastUsers = async function (idapp) {
|
||||
date_reg: 1,
|
||||
index: 1,
|
||||
'profile.nationality': 1,
|
||||
}).sort({ date_reg: -1 }).limit(lastn).then((arr) => {
|
||||
}).sort({ date_reg: -1 }).limit(lastn).lean().then((arr) => {
|
||||
//return JSON.stringify(arr)
|
||||
return arr;
|
||||
});
|
||||
@@ -4494,7 +4513,7 @@ UserSchema.statics.getLastOnlineUsers = async function (idapp) {
|
||||
idMyGroup: 1,
|
||||
'profile.img': 1,
|
||||
index: 1,
|
||||
}).sort({ lasttimeonline: -1 }).limit(lastn).then((arr) => {
|
||||
}).sort({ lasttimeonline: -1 }).limit(lastn).lean().then((arr) => {
|
||||
//return JSON.stringify(arr)
|
||||
return arr;
|
||||
});
|
||||
@@ -4523,7 +4542,7 @@ UserSchema.statics.getLastSharedLink = async function (idapp) {
|
||||
date_reg: 1,
|
||||
'profile.img': 1,
|
||||
index: 1,
|
||||
}).sort({ date_tokenreg: -1 }).limit(lastn).then((arr) => {
|
||||
}).sort({ date_tokenreg: -1 }).limit(lastn).lean().then((arr) => {
|
||||
return arr;
|
||||
});
|
||||
|
||||
@@ -4534,7 +4553,7 @@ UserSchema.statics.getDiffusoriUsers = async function (idapp) {
|
||||
|
||||
const lastn = 10;
|
||||
|
||||
return await User.aggregate(User.getQueryUsersDiffusori(idapp)).then(ris => {
|
||||
return await User.aggregate(await User.getQueryUsersDiffusori(idapp)).then(ris => {
|
||||
// console.table(ris);
|
||||
return ris;
|
||||
});
|
||||
@@ -4546,7 +4565,7 @@ UserSchema.statics.getBestStretteDiManoUsers = async function (idapp) {
|
||||
|
||||
const lastn = 10;
|
||||
|
||||
return await User.aggregate(User.getQueryUsersStretteDiMano(idapp)).then(ris => {
|
||||
return await User.aggregate(await User.getQueryUsersStretteDiMano(idapp)).then(ris => {
|
||||
// console.table(ris);
|
||||
return ris;
|
||||
});
|
||||
@@ -4715,7 +4734,9 @@ UserSchema.statics.getUsersRegDailyAverage = function (idapp, nrec) {
|
||||
return query;
|
||||
};
|
||||
|
||||
UserSchema.statics.getQueryUsersDiffusori = function (idapp) {
|
||||
UserSchema.statics.getQueryUsersDiffusori = async function (idapp) {
|
||||
|
||||
const lastn = await Settings.getValDbSettings(idapp, 'SHOW_LAST_N_USERS', 20);
|
||||
|
||||
const query = [
|
||||
{
|
||||
@@ -4752,7 +4773,7 @@ UserSchema.statics.getQueryUsersDiffusori = function (idapp) {
|
||||
count: -1,
|
||||
},
|
||||
},
|
||||
{ $limit: 20 },
|
||||
{ $limit: lastn },
|
||||
{
|
||||
$lookup: {
|
||||
from: "users",
|
||||
@@ -4805,15 +4826,17 @@ UserSchema.statics.getQueryUsersDiffusori = function (idapp) {
|
||||
date_reg: 1,
|
||||
idapp: 1,
|
||||
"profile.img": 1,
|
||||
'profile.mycircuits': 1,
|
||||
'profile.handshake': 1,
|
||||
// 'profile.mycircuits': 1,
|
||||
// 'profile.handshake': 1,
|
||||
},
|
||||
},
|
||||
];
|
||||
return query;
|
||||
};
|
||||
|
||||
UserSchema.statics.getQueryUsersStretteDiMano = function (idapp) {
|
||||
UserSchema.statics.getQueryUsersStretteDiMano = async function (idapp) {
|
||||
|
||||
const lastn = await Settings.getValDbSettings(idapp, 'SHOW_LAST_N_USERS', 20);
|
||||
|
||||
const query = [
|
||||
{
|
||||
@@ -4845,7 +4868,7 @@ UserSchema.statics.getQueryUsersStretteDiMano = function (idapp) {
|
||||
}
|
||||
},
|
||||
{ $sort: { count: -1 } },
|
||||
{ $limit: 20 },
|
||||
{ $limit: lastn },
|
||||
{
|
||||
$lookup: {
|
||||
from: "users",
|
||||
@@ -4898,8 +4921,8 @@ UserSchema.statics.getQueryUsersStretteDiMano = function (idapp) {
|
||||
date_reg: 1,
|
||||
idapp: 1,
|
||||
"profile.img": 1,
|
||||
'profile.handshake': 1,
|
||||
'profile.mycircuits': 1,
|
||||
// 'profile.handshake': 1,
|
||||
// 'profile.mycircuits': 1,
|
||||
},
|
||||
},
|
||||
];
|
||||
@@ -5870,6 +5893,30 @@ UserSchema.statics.renameCircuitName = async function (idapp, oldcircuitname, ne
|
||||
return await User.updateMany({ idapp, 'profile.mycircuits.circuitname': oldcircuitname }, { $set: { 'profile.mycircuits.$.circuitname': newcircuitname } });
|
||||
};
|
||||
|
||||
UserSchema.statics.getnumAnnunci = async function (idapp) {
|
||||
|
||||
const { MySkill } = require('../models/myskill');
|
||||
const { MyGood } = require('../models/mygood');
|
||||
const { MyBacheca } = require('../models/mybacheca');
|
||||
const { MyHosp } = require('../models/myhosp');
|
||||
|
||||
let num = 0;
|
||||
|
||||
try {
|
||||
|
||||
num += await MySkill.countDocuments({ idapp });
|
||||
num += await MyGood.countDocuments({ idapp });
|
||||
num += await MyBacheca.countDocuments({ idapp });
|
||||
num += await MyHosp.countDocuments({ idapp });
|
||||
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
|
||||
return num;
|
||||
|
||||
};
|
||||
|
||||
UserSchema.statics.createNewSubRecord = async function (idapp, req) {
|
||||
const User = this;
|
||||
|
||||
|
||||
@@ -8,13 +8,11 @@ const server_constants = require('../tools/server_constants');
|
||||
const { authenticate } = require('../middleware/authenticate');
|
||||
|
||||
const { MyGroup } = require('../models/mygroup');
|
||||
const { User } = require('../models/user');
|
||||
const { Stat } = require('../models/stat');
|
||||
|
||||
const mongoose = require('mongoose').set('debug', false)
|
||||
|
||||
const { User } = require('../models/user');
|
||||
// const { Nave } = require('../models/nave');
|
||||
// const { ListaIngresso } = require('../models/listaingresso');
|
||||
|
||||
const _ = require('lodash');
|
||||
|
||||
const { ObjectID } = require('mongodb');
|
||||
@@ -25,45 +23,19 @@ router.post('/load', async (req, res) => {
|
||||
const idapp = req.body.idapp;
|
||||
const username = req.body.username;
|
||||
|
||||
try {
|
||||
let datastat = await Stat.getStats(idapp);
|
||||
|
||||
let datastat = {
|
||||
num_reg: await User.getUsersRegistered(idapp),
|
||||
num_reg_today: await User.getUsersRegisteredToday(idapp),
|
||||
online_today: await User.getUsersOnLineToday(idapp),
|
||||
// num_passeggeri: await 0,
|
||||
// num_imbarcati: 0,
|
||||
// email_non_verif: await User.getEmailNotVerified(idapp),
|
||||
num_teleg_attivo: await User.getUsersTelegramAttivo(idapp),
|
||||
num_autorizzati: await User.getUsersAutorizzati(idapp),
|
||||
num_autorizzare: await User.getUsersAutorizzare(idapp),
|
||||
num_teleg_pending: await User.getUsersTelegramPending(idapp),
|
||||
// num_qualificati: await User.getNumUsersQualified(idapp, 2),
|
||||
// num_requisiti: await User.getNumUsersQualified(idapp, 0),
|
||||
// num_modalita_pagamento: await User.getnumPaymentOk(idapp),
|
||||
// num_part_zoom: await User.getUsersZoom(idapp),
|
||||
// num_part_accepted: await User.getSaw_and_Accepted(idapp),
|
||||
arr_nations: await User.findAllDistinctNationality(idapp),
|
||||
numreg_untilday: await User.calcnumRegUntilDay(idapp),
|
||||
reg_daily: await User.calcRegDaily(idapp),
|
||||
// imbarcati_daily: 0,
|
||||
// imbarcati_weekly: 0,
|
||||
reg_weekly: await User.calcRegWeekly(idapp),
|
||||
lastsreg: await User.getLastUsers(idapp),
|
||||
lastsonline: await User.getLastOnlineUsers(idapp),
|
||||
lastssharedlink: await User.getLastSharedLink(idapp),
|
||||
diffusorilist: await User.getDiffusoriUsers(idapp),
|
||||
receiveRislist: await User.getReceiveRISUsers(idapp),
|
||||
// receiveRislist: await User.find({idapp}).limit(20),
|
||||
receiveRislistgroup: await MyGroup.getReceiveRISGroups(idapp),
|
||||
strettelist: await User.getBestStretteDiManoUsers(idapp),
|
||||
checkuser: await User.checkUser(idapp, username),
|
||||
// navi_partite: await Nave.getNaviPartite(idapp),
|
||||
// navi_in_partenza: await Nave.getNaviInPartenza(idapp),
|
||||
};
|
||||
if (datastat) {
|
||||
datastat.checkuser = await User.checkUser(idapp, username);
|
||||
}
|
||||
|
||||
res.send({ datastat });
|
||||
|
||||
} catch (e) {
|
||||
console.error('Error', e);
|
||||
}
|
||||
|
||||
// console.table(datastat.lastsreg);
|
||||
|
||||
/*
|
||||
let datastat = {
|
||||
@@ -80,7 +52,6 @@ router.post('/load', async (req, res) => {
|
||||
};
|
||||
*/
|
||||
|
||||
res.send({ datastat });
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
||||
@@ -5569,6 +5569,44 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
|
||||
getStringaConto(mov) {
|
||||
|
||||
let mystr = ''
|
||||
let myfrom = ''
|
||||
let myto = ''
|
||||
|
||||
let tipocontofrom = shared_consts.AccountType.USER
|
||||
let tipocontoto = shared_consts.AccountType.USER
|
||||
|
||||
if (mov.contocomfrom && mov.contocomfrom.name) {
|
||||
myfrom += mov.contocomfrom.name + ' '
|
||||
tipocontofrom = shared_consts.AccountType.COMMUNITY_ACCOUNT
|
||||
}
|
||||
if (mov.groupfrom) {
|
||||
myfrom += mov.groupfrom.groupname + ' '
|
||||
tipocontofrom = shared_consts.AccountType.COLLECTIVE_ACCOUNT
|
||||
}
|
||||
if (mov.userfrom) {
|
||||
myfrom += mov.userfrom.username + ' '
|
||||
}
|
||||
|
||||
if (mov.contocomto && mov.contocomto.name) {
|
||||
myto += mov.contocomto.name + ' '
|
||||
tipocontoto = shared_consts.AccountType.COMMUNITY_ACCOUNT
|
||||
}
|
||||
if (mov.groupto) {
|
||||
myto += mov.groupto.groupname + ' '
|
||||
tipocontoto = shared_consts.AccountType.COLLECTIVE_ACCOUNT
|
||||
}
|
||||
if (mov.userto) {
|
||||
myto += mov.userto.username + ' '
|
||||
}
|
||||
|
||||
// mystr = t('movement.from') + myfrom + ' ' + t('movement.to') + myto
|
||||
|
||||
return { myfrom, myto, tipocontofrom, tipocontoto }
|
||||
},
|
||||
|
||||
ImageDownloader,
|
||||
|
||||
|
||||
|
||||
@@ -177,7 +177,7 @@ module.exports = {
|
||||
mytable = Newstosent;
|
||||
else if (tablename === 'gallery')
|
||||
mytable = Gallery;
|
||||
else if (tablename === 'mypage')
|
||||
else if ((tablename === 'mypages') || (tablename === 'mypage'))
|
||||
mytable = MyPage;
|
||||
else if (tablename === 'myelems')
|
||||
mytable = MyElem;
|
||||
|
||||
@@ -1114,6 +1114,12 @@ module.exports = {
|
||||
|
||||
},
|
||||
|
||||
AccountType: {
|
||||
USER: 0,
|
||||
COLLECTIVE_ACCOUNT: 1,
|
||||
COMMUNITY_ACCOUNT: 2,
|
||||
},
|
||||
|
||||
// Download, DVD, Epub, Mobi, Nuovo, PDF, Streaming, Usato
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user