veza/apps/web/src/services/commerceService.ts

105 lines
2.5 KiB
TypeScript
Raw Normal View History

import { apiClient } from './api/client';
import { Purchase, Product } from '../types';
const MOCK_PURCHASES: Purchase[] = [
{
id: 'p1',
orderId: 'ORD-9921',
date: '2023-10-24',
price: 29.99,
status: 'completed',
downloadUrl: '#',
license: { id: 'l1', name: 'Standard', price: 29.99, features: [] },
product: {
id: 'prod1',
title: 'Cyberpunk 2077 Drums',
type: 'pack',
price: 29.99,
currency: 'USD',
rating: 5,
coverUrl: 'https://picsum.photos/id/120/100/100',
author: 'Neon Audio',
} as Partial<Product> as Product,
},
{
id: 'p2',
orderId: 'ORD-9850',
date: '2023-10-15',
price: 49.99,
status: 'completed',
downloadUrl: '#',
license: { id: 'l2', name: 'Premium', price: 49.99, features: [] },
product: {
id: 'prod2',
title: 'Ethereal Pads Vol. 1',
type: 'pack',
price: 49.99,
currency: 'USD',
rating: 4,
coverUrl: 'https://picsum.photos/id/140/100/100',
author: 'Soundscapes',
} as Partial<Product> as Product,
},
];
const RECENT_SALES = [
{
id: 's1',
product: 'Cyberpunk 2077 Drums',
date: '2 mins ago',
amount: 29.99,
buyer: 'User_992',
},
{
id: 's2',
product: 'Dark Techno Bunker',
date: '1 hour ago',
amount: 49.99,
buyer: 'TechnoFan',
},
{
id: 's3',
product: 'Ethereal Pads Vol. 1',
date: '3 hours ago',
amount: 14.99,
buyer: 'AmbientSoul',
},
{
id: 's4',
product: 'Cyberpunk 2077 Drums',
date: '5 hours ago',
amount: 29.99,
buyer: 'ProducerX',
},
];
export const commerceService = {
getPurchases: async () => {
await new Promise((resolve) => setTimeout(resolve, 600));
return MOCK_PURCHASES;
},
getSales: async () => {
await new Promise((resolve) => setTimeout(resolve, 500));
return RECENT_SALES;
},
getSellerStats: async () => {
const response = await apiClient.get<{ data?: { revenue?: number; sales?: number; sales_count?: number } }>(
'/sell/stats'
);
const data = (response.data?.data ?? response.data) as Record<string, unknown> | undefined;
return {
revenue: (data?.revenue as number) ?? 0,
sales: (data?.sales_count ?? data?.sales) as number ?? 0,
views: 0,
conversion: 0,
};
},
requestRefund: async (_orderId: string, _reason: string) => {
await new Promise((resolve) => setTimeout(resolve, 800));
return { success: true };
},
};