view data fixes
This commit is contained in:
@@ -1,37 +1,46 @@
|
||||
'use client';
|
||||
|
||||
import type { GetLeagueWalletOutputDTO } from '@/lib/types/generated/GetLeagueWalletOutputDTO';
|
||||
import type { LeagueWalletViewData } from '@/lib/view-data/LeagueWalletViewData';
|
||||
import type { WalletTransactionViewData } from '@/lib/view-data/WalletTransactionViewData';
|
||||
import type { ViewDataBuilder } from '@/lib/contracts/builders/ViewDataBuilder';
|
||||
import { NumberFormatter } from '@/lib/formatters/NumberFormatter';
|
||||
|
||||
import { ViewDataBuilder } from "../../contracts/builders/ViewDataBuilder";
|
||||
type LeagueWalletInputDTO = GetLeagueWalletOutputDTO & {
|
||||
leagueId: string;
|
||||
}
|
||||
|
||||
export class LeagueWalletViewDataBuilder implements ViewDataBuilder<any, any> {
|
||||
build(input: any): any {
|
||||
return LeagueWalletViewDataBuilder.build(input);
|
||||
}
|
||||
|
||||
static build(apiDto: GetLeagueWalletOutputDTO): LeagueWalletViewData {
|
||||
const transactions: WalletTransactionViewData[] = apiDto.transactions.map(t => ({
|
||||
export class LeagueWalletViewDataBuilder {
|
||||
public static build(apiDto: LeagueWalletInputDTO): LeagueWalletViewData {
|
||||
const transactions: WalletTransactionViewData[] = (apiDto.transactions || []).map(t => ({
|
||||
id: t.id,
|
||||
type: t.type as any,
|
||||
type: t.type as WalletTransactionViewData['type'],
|
||||
description: t.description,
|
||||
amount: t.amount,
|
||||
fee: t.fee,
|
||||
netAmount: t.netAmount,
|
||||
date: (t as any).createdAt || (t as any).date || new Date().toISOString(),
|
||||
status: t.status as any,
|
||||
date: t.date,
|
||||
status: t.status as WalletTransactionViewData['status'],
|
||||
reference: t.reference,
|
||||
}));
|
||||
|
||||
return {
|
||||
balance: apiDto.balance,
|
||||
leagueId: apiDto.leagueId,
|
||||
balance: apiDto.balance || 0,
|
||||
formattedBalance: NumberFormatter.formatCurrency(apiDto.balance || 0, apiDto.currency),
|
||||
totalRevenue: apiDto.totalRevenue || 0,
|
||||
formattedTotalRevenue: NumberFormatter.formatCurrency(apiDto.totalRevenue || 0, apiDto.currency),
|
||||
totalFees: apiDto.totalFees || 0,
|
||||
formattedTotalFees: NumberFormatter.formatCurrency(apiDto.totalFees || 0, apiDto.currency),
|
||||
totalWithdrawals: apiDto.totalWithdrawals || 0,
|
||||
pendingPayouts: apiDto.pendingPayouts || 0,
|
||||
formattedPendingPayouts: NumberFormatter.formatCurrency(apiDto.pendingPayouts || 0, apiDto.currency),
|
||||
currency: apiDto.currency,
|
||||
totalRevenue: apiDto.totalRevenue,
|
||||
totalFees: apiDto.totalFees,
|
||||
totalWithdrawals: apiDto.totalWithdrawals,
|
||||
pendingPayouts: apiDto.pendingPayouts,
|
||||
transactions,
|
||||
canWithdraw: apiDto.canWithdraw,
|
||||
canWithdraw: apiDto.canWithdraw || false,
|
||||
withdrawalBlockReason: apiDto.withdrawalBlockReason,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
LeagueWalletViewDataBuilder satisfies ViewDataBuilder<LeagueWalletInputDTO, LeagueWalletViewData>;
|
||||
|
||||
Reference in New Issue
Block a user