view models
This commit is contained in:
@@ -1,15 +1,21 @@
|
||||
import { MembershipFeeViewModel } from '@/lib/view-models/MembershipFeeViewModel';
|
||||
import { PaymentViewModel } from '@/lib/view-models/PaymentViewModel';
|
||||
import { PrizeViewModel } from '@/lib/view-models/PrizeViewModel';
|
||||
import { WalletViewModel } from '@/lib/view-models/WalletViewModel';
|
||||
import type { PaymentsApiClient } from '../../api/payments/PaymentsApiClient';
|
||||
import type { PaymentDto, MembershipFeeDto, PrizeDto } from '../../types/generated';
|
||||
import type { PaymentDTO } from '../../types/generated/PaymentDto';
|
||||
import type { PrizeDto } from '../../types/generated/PrizeDto';
|
||||
|
||||
// TODO: Move these types to apps/website/lib/types/generated when available
|
||||
type CreatePaymentInputDto = { amount: number; leagueId: string; driverId: string; description: string };
|
||||
type CreatePaymentOutputDto = { id: string; success: boolean };
|
||||
import {
|
||||
PaymentViewModel,
|
||||
MembershipFeeViewModel,
|
||||
PrizeViewModel,
|
||||
WalletViewModel,
|
||||
} from '../../view-models';
|
||||
type CreatePaymentInputDto = {
|
||||
type: 'sponsorship' | 'membership_fee';
|
||||
amount: number;
|
||||
payerId: string;
|
||||
payerType: 'sponsor' | 'driver';
|
||||
leagueId: string;
|
||||
seasonId?: string;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Payment Service
|
||||
@@ -27,7 +33,7 @@ export class PaymentService {
|
||||
*/
|
||||
async getPayments(leagueId?: string, driverId?: string): Promise<PaymentViewModel[]> {
|
||||
const dto = await this.apiClient.getPayments(leagueId, driverId);
|
||||
return dto.payments.map((payment: PaymentDto) => new PaymentViewModel(payment));
|
||||
return dto.payments.map((payment: PaymentDTO) => new PaymentViewModel(payment));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -36,7 +42,7 @@ export class PaymentService {
|
||||
async getPayment(paymentId: string): Promise<PaymentViewModel> {
|
||||
// Note: Assuming the API returns a single payment from the list
|
||||
const dto = await this.apiClient.getPayments();
|
||||
const payment = dto.payments.find((p: PaymentDto) => p.id === paymentId);
|
||||
const payment = dto.payments.find((p: PaymentDTO) => p.id === paymentId);
|
||||
if (!payment) {
|
||||
throw new Error(`Payment with ID ${paymentId} not found`);
|
||||
}
|
||||
@@ -46,16 +52,17 @@ export class PaymentService {
|
||||
/**
|
||||
* Create a new payment
|
||||
*/
|
||||
async createPayment(input: CreatePaymentInputDto): Promise<CreatePaymentOutputDto> {
|
||||
return await this.apiClient.createPayment(input);
|
||||
async createPayment(input: CreatePaymentInputDto): Promise<PaymentViewModel> {
|
||||
const dto = await this.apiClient.createPayment(input);
|
||||
return new PaymentViewModel(dto.payment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get membership fees for a league
|
||||
*/
|
||||
async getMembershipFees(leagueId: string): Promise<MembershipFeeViewModel[]> {
|
||||
async getMembershipFees(leagueId: string): Promise<MembershipFeeViewModel | null> {
|
||||
const dto = await this.apiClient.getMembershipFees(leagueId);
|
||||
return dto.fees.map((fee: MembershipFeeDto) => new MembershipFeeViewModel(fee));
|
||||
return dto.fee ? new MembershipFeeViewModel(dto.fee) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,14 +78,7 @@ export class PaymentService {
|
||||
*/
|
||||
async getWallet(driverId: string): Promise<WalletViewModel> {
|
||||
const dto = await this.apiClient.getWallet(driverId);
|
||||
return new WalletViewModel(dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process a payment (alias for createPayment)
|
||||
*/
|
||||
async processPayment(input: CreatePaymentInputDto): Promise<CreatePaymentOutputDto> {
|
||||
return await this.createPayment(input);
|
||||
return new WalletViewModel({ ...dto.wallet, transactions: dto.transactions });
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user