website refactor
This commit is contained in:
@@ -1,16 +1,65 @@
|
||||
import { Result } from '@/lib/contracts/Result';
|
||||
import { DomainError, Service } from '@/lib/contracts/services/Service';
|
||||
import { injectable, unmanaged } from 'inversify';
|
||||
import { PaymentsApiClient } from '@/lib/api/payments/PaymentsApiClient';
|
||||
import { PaymentViewModel } from '@/lib/view-models/PaymentViewModel';
|
||||
import { MembershipFeeViewModel } from '@/lib/view-models/MembershipFeeViewModel';
|
||||
import { PrizeViewModel } from '@/lib/view-models/PrizeViewModel';
|
||||
import { WalletViewModel } from '@/lib/view-models/WalletViewModel';
|
||||
import { getWebsiteApiBaseUrl } from '@/lib/config/apiBaseUrl';
|
||||
import { ConsoleLogger } from '@/lib/infrastructure/logging/ConsoleLogger';
|
||||
import { EnhancedErrorReporter } from '@/lib/infrastructure/EnhancedErrorReporter';
|
||||
import { Service } from '@/lib/contracts/services/Service';
|
||||
|
||||
/**
|
||||
* Payment Service - DTO Only
|
||||
*
|
||||
* Returns raw API DTOs. No ViewModels or UX logic.
|
||||
* All client-side presentation logic must be handled by hooks/components.
|
||||
*/
|
||||
@injectable()
|
||||
export class PaymentService implements Service {
|
||||
constructor() {}
|
||||
private readonly apiClient: PaymentsApiClient;
|
||||
|
||||
async getPaymentById(paymentId: string): Promise<Result<{ id: string; amount: number }, DomainError>> {
|
||||
return Result.ok({ id: paymentId, amount: 0 });
|
||||
constructor(@unmanaged() apiClient?: PaymentsApiClient) {
|
||||
if (apiClient) {
|
||||
this.apiClient = apiClient;
|
||||
} else {
|
||||
const baseUrl = getWebsiteApiBaseUrl();
|
||||
const logger = new ConsoleLogger();
|
||||
const errorReporter = new EnhancedErrorReporter(logger);
|
||||
this.apiClient = new PaymentsApiClient(baseUrl, errorReporter, logger);
|
||||
}
|
||||
}
|
||||
|
||||
async getPayments(leagueId?: string, payerId?: string): Promise<PaymentViewModel[]> {
|
||||
const query: any = {};
|
||||
if (leagueId) query.leagueId = leagueId;
|
||||
if (payerId) query.payerId = payerId;
|
||||
const data = await this.apiClient.getPayments(Object.keys(query).length > 0 ? query : undefined);
|
||||
return data.payments.map(p => new PaymentViewModel(p));
|
||||
}
|
||||
|
||||
async getPayment(id: string): Promise<PaymentViewModel> {
|
||||
const data = await this.apiClient.getPayments();
|
||||
const payment = data.payments.find(p => p.id === id);
|
||||
if (!payment) throw new Error(`Payment with ID ${id} not found`);
|
||||
return new PaymentViewModel(payment);
|
||||
}
|
||||
|
||||
async createPayment(input: any): Promise<PaymentViewModel> {
|
||||
const data = await this.apiClient.createPayment(input);
|
||||
return new PaymentViewModel(data.payment);
|
||||
}
|
||||
|
||||
async getMembershipFees(leagueId: string): Promise<MembershipFeeViewModel | null> {
|
||||
const data = await this.apiClient.getMembershipFees({ leagueId });
|
||||
if (!data.fee) return null;
|
||||
return new MembershipFeeViewModel(data.fee);
|
||||
}
|
||||
|
||||
async getPrizes(leagueId?: string, seasonId?: string): Promise<PrizeViewModel[]> {
|
||||
const query: any = {};
|
||||
if (leagueId) query.leagueId = leagueId;
|
||||
if (seasonId) query.seasonId = seasonId;
|
||||
const data = await this.apiClient.getPrizes(Object.keys(query).length > 0 ? query : undefined);
|
||||
return data.prizes.map(p => new PrizeViewModel(p));
|
||||
}
|
||||
|
||||
async getWallet(leagueId: string): Promise<WalletViewModel> {
|
||||
const data = await this.apiClient.getWallet({ leagueId });
|
||||
return new WalletViewModel({ ...data.wallet, transactions: data.transactions });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user