fix(mining-admin): transform dashboard API response to match frontend expected format

Frontend expects flat DashboardStats and RealtimeData interfaces.
Transform backend nested response to:
- totalUsers, adoptedUsers, networkEffectiveContribution, etc.
- currentMinuteDistribution, activeOrders, pendingTrades, etc.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-01-14 02:23:54 -08:00
parent d6064294d7
commit a2adddbf3d
1 changed files with 34 additions and 3 deletions

View File

@ -16,19 +16,50 @@ export class DashboardController {
@Get() @Get()
@ApiOperation({ summary: '获取仪表盘统计数据' }) @ApiOperation({ summary: '获取仪表盘统计数据' })
async getStats() { async getStats() {
return this.dashboardService.getDashboardStats(); const raw = await this.dashboardService.getDashboardStats();
// 计算24小时价格变化
let priceChange24h = 0;
if (raw.latestPrice) {
const open = parseFloat(raw.latestPrice.open) || 1;
const close = parseFloat(raw.latestPrice.close) || 1;
priceChange24h = (close - open) / open;
}
// 转换为前端期望的格式
return {
totalUsers: raw.users?.total || 0,
adoptedUsers: raw.users?.adopted || 0,
networkEffectiveContribution: raw.contribution?.effectiveContribution || '0',
totalDistributed: raw.mining?.totalMined || '0',
totalBurned: raw.mining?.latestDailyStat?.totalBurned || '0',
circulationPool: raw.trading?.circulationPool?.totalShares || '0',
currentPrice: raw.latestPrice?.close || '1',
priceChange24h,
totalOrders: raw.trading?.totalAccounts || 0,
totalTrades: raw.trading?.totalAccounts || 0,
};
} }
@Get('stats') @Get('stats')
@ApiOperation({ summary: '获取仪表盘统计数据(别名)' }) @ApiOperation({ summary: '获取仪表盘统计数据(别名)' })
async getStatsAlias() { async getStatsAlias() {
return this.dashboardService.getDashboardStats(); return this.getStats();
} }
@Get('realtime') @Get('realtime')
@ApiOperation({ summary: '获取实时数据' }) @ApiOperation({ summary: '获取实时数据' })
async getRealtimeStats() { async getRealtimeStats() {
return this.dashboardService.getRealtimeStats(); const raw = await this.dashboardService.getRealtimeStats();
// 转换为前端期望的格式
return {
currentMinuteDistribution: raw.minuteDistribution || '0',
currentMinuteBurn: '0', // 暂无实时销毁数据
activeOrders: 0, // 暂无实时订单数据
pendingTrades: 0, // 暂无待处理交易数据
lastPriceUpdateAt: raw.timestamp,
};
} }
@Get('reports') @Get('reports')