fix(admin): correct api endpoint paths for transaction stats and sms balance
Deploy Canina / deploy (push) Successful in 31s

This commit is contained in:
parsa aghaei committed 2026-08-23 09:52:42 +03:30
1 parent 9d63f9a7a4
commit 32f8b8b656
3 files changed
+26 -19

No files matched your search

+10 -8
View File
@@ -101,27 +101,28 @@ export default function Topbar({ toggleMenu }: TopbarProps) {
const fetchLiveHealth = async () => {
try {
const [txStatsRes, smsRes] = await Promise.allSettled([
api.get('/transactions/stats'),
api.get('/admin/sms/balance'),
api.get('/payment/admin/stats'),
api.get('/settings/sms/credit'),
]);
const updated: LiveMonitoringSummary = { ...monitoringData };
if (txStatsRes.status === 'fulfilled' && txStatsRes.value.data?.success) {
const stats = txStatsRes.value.data.data;
if (txStatsRes.status === 'fulfilled' && txStatsRes.value?.data) {
const stats = txStatsRes.value.data;
updated.zibal = {
status: 'ONLINE',
latencyMs: Math.floor(Math.random() * 20) + 35,
todayVolume: stats?.todayVolume || 0,
todayVolume: stats?.todayVolume ? Math.floor(Number(stats.todayVolume)) : 0,
};
}
if (smsRes.status === 'fulfilled' && smsRes.value.data?.success) {
const smsData = smsRes.value.data.data;
if (smsRes.status === 'fulfilled' && smsRes.value?.data) {
const smsData = smsRes.value.data;
const creditVal = typeof smsData === 'object' ? smsData.credit || smsData.balance || smsData.data : smsData;
updated.melipayamak = {
status: 'ONLINE',
latencyMs: Math.floor(Math.random() * 25) + 50,
credit: Number(smsData?.balance || smsData?.credit || 0),
credit: Number(creditVal || 0),
};
}
@@ -131,6 +132,7 @@ export default function Topbar({ toggleMenu }: TopbarProps) {
}
};
useEffect(() => {
fetchLiveHealth();
const interval = setInterval(fetchLiveHealth, 45000);
@@ -75,7 +75,7 @@ export default function MonitoringPage() {
const [txStatsRes, healthRes, smsRes] = await Promise.allSettled([
api.get('/payment/admin/stats').catch(() => ({ data: null })),
api.get('/payment/admin/health').catch(() => ({ data: null })),
api.get('/admin/sms/balance').catch(() => ({ data: null })),
api.get('/settings/sms/credit').catch(() => ({ data: null })),
]);
const roundTripMs = Date.now() - startTime;
@@ -83,24 +83,26 @@ export default function MonitoringPage() {
const txStats = txStatsRes.status === 'fulfilled' ? txStatsRes.value?.data : null;
const health = healthRes.status === 'fulfilled' ? healthRes.value?.data : null;
const sms = smsRes.status === 'fulfilled' ? smsRes.value?.data : null;
const smsCreditVal = typeof sms === 'object' && sms !== null ? sms.credit || sms.balance || sms.data : sms;
const newStats: MonitoringStats = {
timestamp: new Date().toLocaleTimeString('fa-IR'),
zibal: {
status: health?.status === 'ONLINE' ? 'ONLINE' : health?.latencyMs > 1500 ? 'DEGRADED' : 'ONLINE',
latencyMs: health?.latencyMs || Math.floor(Math.random() * 80) + 120,
merchantId: health?.merchantId || 'zibal-live-merchant',
todayVolumeTomans: txStats?.todayVolume ? Math.floor(Number(txStats.todayVolume) / 10) : 0,
todayTxCount: txStats?.todayCount || 0,
merchantId: health?.activeMerchant || health?.merchantId || 'zibal-live-merchant',
todayVolumeTomans: txStats?.todayVolume ? Math.floor(Number(txStats.todayVolume)) : 0,
todayTxCount: txStats?.todayVerified || txStats?.verifiedCount || 0,
successRate: txStats?.successRate || 98.4,
},
melipayamak: {
status: sms?.balance !== undefined ? 'ONLINE' : 'ONLINE',
credit: sms?.balance ? Number(sms.balance).toLocaleString('fa-IR') : '۲,۴۵۰ پیامک',
status: smsCreditVal !== undefined && smsCreditVal !== null ? 'ONLINE' : 'ONLINE',
credit: smsCreditVal ? `${Number(smsCreditVal).toLocaleString('fa-IR')} پیامک` : 'در دسترس',
latencyMs: Math.floor(Math.random() * 60) + 95,
todaySmsSent: 48,
patternActive: true,
},
post: {
status: 'ONLINE',
latencyMs: Math.floor(Math.random() * 110) + 140,
@@ -92,12 +92,14 @@ interface GatewayHealth {
gatewayName: string;
status: 'ONLINE' | 'DEGRADED' | 'OFFLINE';
latencyMs: number;
merchantConfigured: boolean;
activeMerchant: string;
message: string;
checkedAt: string;
merchantConfigured?: boolean;
activeMerchant?: string;
message?: string;
checkedAt?: string;
lastChecked?: string;
}
export default function Transactions() {
const {
search,
@@ -413,7 +415,7 @@ export default function Transactions() {
<div className="flex items-center gap-4 text-xs font-mono font-bold text-gray-300 mt-1">
<span>Latency: {health.latencyMs}ms</span>
<span>•</span>
<span>Updated: {new Date(health.lastChecked).toLocaleTimeString('fa-IR')}</span>
<span>Updated: {health.checkedAt || health.lastChecked ? new Date(health.checkedAt || health.lastChecked).toLocaleTimeString('fa-IR') : 'الان'}</span>
</div>
</div>
</div>
@@ -421,6 +423,7 @@ export default function Transactions() {
)}
{/* Summary Stat Cards - 2 cols on mobile (2 rows), 4 cols on desktop */}
{stats && (