forked from MyZubster-Ecosystem/myzubster
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadminDashboardController.js
More file actions
79 lines (74 loc) 路 3.18 KB
/
Copy pathadminDashboardController.js
File metadata and controls
79 lines (74 loc) 路 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const mongoose = require('mongoose');
// #218: Admin Dashboard - Monitoraggio Lavori e Pagamenti
// Uses existing models (Dashboard, Wallet, Escrow, Dispute, etc.)
// Get system overview
exports.getOverview = async (req, res) => {
try {
const Dashboard = mongoose.model('Dashboard');
const Wallet = mongoose.model('Wallet');
const totalUsers = await Dashboard.countDocuments();
const totalWallets = await Wallet.countDocuments();
const dashboard = await Dashboard.aggregate([{$group: {_id: null, totalMYZ: {$sum: '$balanceMYZ'}, totalXMR: {$sum: '$balanceXMR'}}}]);
const wallets = await Wallet.aggregate([{$group: {_id: null, totalMYZ: {$sum: '$balanceMYZ'}, totalXMR: {$sum: '$balanceXMR'}}}]);
res.json({
totalUsers,
totalWallets,
totalMYZInCirculation: (dashboard[0]?.totalMYZ || 0) + (wallets[0]?.totalMYZ || 0),
totalXMRInCirculation: (dashboard[0]?.totalXMR || 0) + (wallets[0]?.totalXMR || 0)
});
} catch (e) { res.status(500).json({ error: e.message }); }
};
// Get payment monitoring
exports.getPaymentMonitoring = async (req, res) => {
try {
const Wallet = mongoose.model('Wallet');
const wallets = await Wallet.find({});
const allTxs = wallets.flatMap(w => w.transactions);
const today = new Date().toISOString().slice(0,10);
const todayTxs = allTxs.filter(t => new Date(t.timestamp).toISOString().slice(0,10) === today);
const pending = allTxs.filter(t => t.status === 'pending');
const failed = allTxs.filter(t => t.status === 'failed');
const totalVolume = allTxs.reduce((s, t) => s + t.amount, 0);
res.json({
totalTransactions: allTxs.length,
todayTransactions: todayTxs.length,
pendingTransactions: pending.length,
failedTransactions: failed.length,
totalVolume
});
} catch (e) { res.status(500).json({ error: e.message }); }
};
// Get job monitoring
exports.getJobMonitoring = async (req, res) => {
try {
const Dashboard = mongoose.model('Dashboard');
const dashboards = await Dashboard.find({ robotId: { $ne: null } });
const totalRobots = dashboards.length;
const totalJobs = dashboards.reduce((s, d) => s + d.jobsCompleted, 0);
const totalEarnings = dashboards.reduce((s, d) => s + d.totalEarnings, 0);
res.json({
totalRobots,
totalJobsCompleted: totalJobs,
totalRobotEarnings: totalEarnings,
robots: dashboards.map(d => ({robotId: d.robotId, jobsCompleted: d.jobsCompleted, totalEarnings: d.totalEarnings, balanceMYZ: d.balanceMYZ}))
});
} catch (e) { res.status(500).json({ error: e.message }); }
};
// Get system health
exports.getSystemHealth = async (req, res) => {
try {
const dbState = mongoose.connection.readyState === 1 ? 'connected' : 'disconnected';
const memUsage = process.memoryUsage();
res.json({
status: 'ok',
uptime: process.uptime(),
database: dbState,
memory: {
rss: Math.round(memUsage.rss / 1024 / 1024) + 'MB',
heapUsed: Math.round(memUsage.heapUsed / 1024 / 1024) + 'MB',
heapTotal: Math.round(memUsage.heapTotal / 1024 / 1024) + 'MB'
},
timestamp: new Date().toISOString()
});
} catch (e) { res.status(500).json({ error: e.message }); }
};