refactor league module (wip)
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import type { UseCaseOutputPort } from '@core/shared/application';
|
||||
import type { GetLeagueWalletResult } from '@core/racing/application/use-cases/GetLeagueWalletUseCase';
|
||||
import { GetLeagueWalletOutputDTO, WalletTransactionDTO } from '../dtos/GetLeagueWalletOutputDTO';
|
||||
|
||||
export class GetLeagueWalletPresenter implements UseCaseOutputPort<GetLeagueWalletResult> {
|
||||
private model: GetLeagueWalletOutputDTO | null = null;
|
||||
|
||||
present(result: GetLeagueWalletResult): void {
|
||||
const transactions: WalletTransactionDTO[] = result.transactions.map(tx => ({
|
||||
id: tx.id.toString(),
|
||||
type: tx.type as 'sponsorship' | 'membership' | 'withdrawal' | 'prize',
|
||||
description: tx.description ?? '',
|
||||
amount: tx.amount.amount,
|
||||
fee: tx.platformFee.amount,
|
||||
netAmount: tx.netAmount.amount,
|
||||
date: tx.createdAt.toISOString(),
|
||||
status: tx.status === 'cancelled' ? 'failed' : tx.status,
|
||||
}));
|
||||
|
||||
this.model = {
|
||||
balance: result.aggregates.balance.amount,
|
||||
currency: result.aggregates.balance.currency,
|
||||
totalRevenue: result.aggregates.totalRevenue.amount,
|
||||
totalFees: result.aggregates.totalFees.amount,
|
||||
totalWithdrawals: result.aggregates.totalWithdrawals.amount,
|
||||
pendingPayouts: result.aggregates.pendingPayouts.amount,
|
||||
canWithdraw: result.wallet.canWithdraw(result.aggregates.balance),
|
||||
transactions,
|
||||
};
|
||||
}
|
||||
|
||||
getResponseModel(): GetLeagueWalletOutputDTO {
|
||||
if (!this.model) throw new Error('Presenter not presented');
|
||||
return this.model;
|
||||
}
|
||||
|
||||
get responseModel(): GetLeagueWalletOutputDTO {
|
||||
if (!this.model) throw new Error('Presenter not presented');
|
||||
return this.model;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import type { UseCaseOutputPort } from '@core/shared/application';
|
||||
import type { WithdrawFromLeagueWalletResult } from '@core/racing/application/use-cases/WithdrawFromLeagueWalletUseCase';
|
||||
import { WithdrawFromLeagueWalletOutputDTO } from '../dtos/WithdrawFromLeagueWalletOutputDTO';
|
||||
|
||||
export class WithdrawFromLeagueWalletPresenter implements UseCaseOutputPort<WithdrawFromLeagueWalletResult> {
|
||||
private model: WithdrawFromLeagueWalletOutputDTO | null = null;
|
||||
|
||||
present(result: WithdrawFromLeagueWalletResult): void {
|
||||
this.model = {
|
||||
success: true,
|
||||
message: `Successfully withdrew ${result.amount.amount} ${result.amount.currency} from league wallet. Transaction ID: ${result.transactionId}`,
|
||||
};
|
||||
}
|
||||
|
||||
getResponseModel(): WithdrawFromLeagueWalletOutputDTO {
|
||||
if (!this.model) throw new Error('Presenter not presented');
|
||||
return this.model;
|
||||
}
|
||||
|
||||
get responseModel(): WithdrawFromLeagueWalletOutputDTO {
|
||||
if (!this.model) throw new Error('Presenter not presented');
|
||||
return this.model;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user