resolve manual DTOs

This commit is contained in:
2025-12-18 22:19:40 +01:00
parent 4a3087ae35
commit d617654928
179 changed files with 3716 additions and 1257 deletions

View File

@@ -1,7 +1,8 @@
import { BaseApiClient } from '../base/BaseApiClient';
import type { PaymentDto, MembershipFeeDto, MemberPaymentDto, PrizeDto, WalletDto, TransactionDto, UpdatePaymentStatusInputDTO } from '../types/generated';
// TODO: Import these types from apps/website/lib/types/generated when available
type GetPaymentsOutputDto = { payments: import('../types/generated').PaymentDto[] };
// Define missing types that are not fully generated
type GetPaymentsOutputDto = { payments: PaymentDto[] };
type CreatePaymentInputDto = {
type: 'sponsorship' | 'membership_fee';
amount: number;
@@ -10,15 +11,15 @@ type CreatePaymentInputDto = {
leagueId: string;
seasonId?: string;
};
type CreatePaymentOutputDto = { payment: import('../types/generated').PaymentDto };
type CreatePaymentOutputDto = { payment: PaymentDto };
type GetMembershipFeesOutputDto = {
fee: import('../types/generated').MembershipFeeDto | null;
payments: import('../types/generated').MemberPaymentDto[]
fee: MembershipFeeDto | null;
payments: MemberPaymentDto[]
};
type GetPrizesOutputDto = { prizes: import('../types/generated').PrizeDto[] };
type GetPrizesOutputDto = { prizes: PrizeDto[] };
type GetWalletOutputDto = {
wallet: import('../types/generated').WalletDto;
transactions: import('../types/generated').TransactionDto[]
wallet: WalletDto;
transactions: TransactionDto[]
};
type ProcessWalletTransactionInputDto = {
leagueId: string;
@@ -29,8 +30,8 @@ type ProcessWalletTransactionInputDto = {
referenceType?: 'sponsorship' | 'membership_fee' | 'prize';
};
type ProcessWalletTransactionOutputDto = {
wallet: import('../types/generated').WalletDto;
transaction: import('../types/generated').TransactionDto
wallet: WalletDto;
transaction: TransactionDto
};
type UpdateMemberPaymentInputDto = {
feeId: string;
@@ -38,8 +39,33 @@ type UpdateMemberPaymentInputDto = {
status?: 'pending' | 'paid' | 'overdue';
paidAt?: Date | string;
};
type UpdateMemberPaymentOutputDto = { payment: import('../types/generated').MemberPaymentDto };
type GetWalletTransactionsOutputDto = { transactions: import('../types/generated').TransactionDto[] };
type UpdateMemberPaymentOutputDto = { payment: MemberPaymentDto };
type GetWalletTransactionsOutputDto = { transactions: TransactionDto[] };
type UpdatePaymentStatusOutputDto = { payment: PaymentDto };
type UpsertMembershipFeeInputDto = {
leagueId: string;
seasonId?: string;
type: 'season' | 'monthly' | 'per_race';
amount: number;
};
type UpsertMembershipFeeOutputDto = { fee: MembershipFeeDto };
type CreatePrizeInputDto = {
leagueId: string;
seasonId: string;
position: number;
name: string;
amount: number;
type: 'cash' | 'merchandise' | 'other';
description?: string;
};
type CreatePrizeOutputDto = { prize: PrizeDto };
type AwardPrizeInputDto = {
prizeId: string;
driverId: string;
};
type AwardPrizeOutputDto = { prize: PrizeDto };
type DeletePrizeInputDto = { prizeId: string };
type DeletePrizeOutputDto = { success: boolean };
/**
* Payments API Client
@@ -48,12 +74,14 @@ type GetWalletTransactionsOutputDto = { transactions: import('../types/generated
*/
export class PaymentsApiClient extends BaseApiClient {
/** Get payments */
getPayments(leagueId?: string, driverId?: string): Promise<GetPaymentsOutputDto> {
getPayments(query?: { leagueId?: string; payerId?: string; type?: 'sponsorship' | 'membership_fee'; status?: 'pending' | 'completed' | 'failed' | 'refunded' }): Promise<GetPaymentsOutputDto> {
const params = new URLSearchParams();
if (leagueId) params.append('leagueId', leagueId);
if (driverId) params.append('driverId', driverId);
const query = params.toString();
return this.get<GetPaymentsOutputDto>(`/payments${query ? `?${query}` : ''}`);
if (query?.leagueId) params.append('leagueId', query.leagueId);
if (query?.payerId) params.append('payerId', query.payerId);
if (query?.type) params.append('type', query.type);
if (query?.status) params.append('status', query.status);
const queryString = params.toString();
return this.get<GetPaymentsOutputDto>(`/payments${queryString ? `?${queryString}` : ''}`);
}
/** Create a payment */
@@ -62,21 +90,63 @@ export class PaymentsApiClient extends BaseApiClient {
}
/** Get membership fees */
getMembershipFees(leagueId: string): Promise<GetMembershipFeesOutputDto> {
return this.get<GetMembershipFeesOutputDto>(`/payments/membership-fees?leagueId=${leagueId}`);
getMembershipFees(query: { leagueId: string; driverId?: string }): Promise<GetMembershipFeesOutputDto> {
const params = new URLSearchParams();
params.append('leagueId', query.leagueId);
if (query.driverId) params.append('driverId', query.driverId);
const queryString = params.toString();
return this.get<GetMembershipFeesOutputDto>(`/payments/membership-fees?${queryString}`);
}
/** Get prizes */
getPrizes(leagueId?: string, seasonId?: string): Promise<GetPrizesOutputDto> {
getPrizes(query?: { leagueId?: string; seasonId?: string }): Promise<GetPrizesOutputDto> {
const params = new URLSearchParams();
if (leagueId) params.append('leagueId', leagueId);
if (seasonId) params.append('seasonId', seasonId);
const query = params.toString();
return this.get<GetPrizesOutputDto>(`/payments/prizes${query ? `?${query}` : ''}`);
if (query?.leagueId) params.append('leagueId', query.leagueId);
if (query?.seasonId) params.append('seasonId', query.seasonId);
const queryString = params.toString();
return this.get<GetPrizesOutputDto>(`/payments/prizes${queryString ? `?${queryString}` : ''}`);
}
/** Get wallet */
getWallet(driverId: string): Promise<GetWalletOutputDto> {
return this.get<GetWalletOutputDto>(`/payments/wallets?driverId=${driverId}`);
getWallet(query?: { leagueId?: string }): Promise<GetWalletOutputDto> {
const params = new URLSearchParams();
if (query?.leagueId) params.append('leagueId', query.leagueId);
const queryString = params.toString();
return this.get<GetWalletOutputDto>(`/payments/wallets${queryString ? `?${queryString}` : ''}`);
}
/** Update payment status */
updatePaymentStatus(input: UpdatePaymentStatusInputDTO): Promise<UpdatePaymentStatusOutputDto> {
return this.patch<UpdatePaymentStatusOutputDto>('/payments/status', input);
}
/** Upsert membership fee */
upsertMembershipFee(input: UpsertMembershipFeeInputDto): Promise<UpsertMembershipFeeOutputDto> {
return this.post<UpsertMembershipFeeOutputDto>('/payments/membership-fees', input);
}
/** Update member payment */
updateMemberPayment(input: UpdateMemberPaymentInputDto): Promise<UpdateMemberPaymentOutputDto> {
return this.patch<UpdateMemberPaymentOutputDto>('/payments/membership-fees/member-payment', input);
}
/** Create prize */
createPrize(input: CreatePrizeInputDto): Promise<CreatePrizeOutputDto> {
return this.post<CreatePrizeOutputDto>('/payments/prizes', input);
}
/** Award prize */
awardPrize(input: AwardPrizeInputDto): Promise<AwardPrizeOutputDto> {
return this.patch<AwardPrizeOutputDto>('/payments/prizes/award', input);
}
/** Delete prize */
deletePrize(prizeId: string): Promise<DeletePrizeOutputDto> {
return this.delete<DeletePrizeOutputDto>(`/payments/prizes?prizeId=${prizeId}`);
}
/** Process wallet transaction */
processWalletTransaction(input: ProcessWalletTransactionInputDto): Promise<ProcessWalletTransactionOutputDto> {
return this.post<ProcessWalletTransactionOutputDto>('/payments/wallets/transactions', input);
}
}