stats
This commit is contained in:
47
lib/stats-service.ts
Normal file
47
lib/stats-service.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
export interface PlatformStats {
|
||||
orders: {
|
||||
completed: number;
|
||||
};
|
||||
vendors: {
|
||||
total: number;
|
||||
};
|
||||
transactions: {
|
||||
volume: number;
|
||||
averageOrderValue: number;
|
||||
};
|
||||
}
|
||||
|
||||
export async function fetchPlatformStats(): Promise<PlatformStats> {
|
||||
const BASE_API_URL = process.env.SERVER_API_URL || 'http://localhost:3001/api';
|
||||
|
||||
try {
|
||||
const response = await fetch(`${BASE_API_URL}/stats/platform`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
cache: 'no-store'
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`API error: ${response.status}`);
|
||||
}
|
||||
|
||||
return await response.json();
|
||||
} catch (error) {
|
||||
console.error('Error fetching platform stats:', error);
|
||||
// Return fallback data if API fails
|
||||
return {
|
||||
orders: {
|
||||
completed: 15800
|
||||
},
|
||||
vendors: {
|
||||
total: 2400
|
||||
},
|
||||
transactions: {
|
||||
volume: 3200000,
|
||||
averageOrderValue: 220
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user