refactor use cases
This commit is contained in:
@@ -7,7 +7,6 @@
|
||||
import type { IWalletRepository, ITransactionRepository } from '../../domain/repositories/IWalletRepository';
|
||||
import type { Wallet, Transaction } from '../../domain/entities/Wallet';
|
||||
import type { UseCase } from '@core/shared/application/UseCase';
|
||||
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
|
||||
@@ -23,15 +22,14 @@ export interface GetWalletResult {
|
||||
}
|
||||
|
||||
export class GetWalletUseCase
|
||||
implements UseCase<GetWalletInput, void, GetWalletErrorCode>
|
||||
implements UseCase<GetWalletInput, GetWalletResult, GetWalletErrorCode>
|
||||
{
|
||||
constructor(
|
||||
private readonly walletRepository: IWalletRepository,
|
||||
private readonly transactionRepository: ITransactionRepository,
|
||||
private readonly output: UseCaseOutputPort<GetWalletResult>,
|
||||
) {}
|
||||
|
||||
async execute(input: GetWalletInput): Promise<Result<void, ApplicationErrorCode<GetWalletErrorCode>>> {
|
||||
async execute(input: GetWalletInput): Promise<Result<GetWalletResult, ApplicationErrorCode<GetWalletErrorCode>>> {
|
||||
const { leagueId } = input;
|
||||
|
||||
if (!leagueId) {
|
||||
@@ -58,8 +56,6 @@ export class GetWalletUseCase
|
||||
const transactions = await this.transactionRepository.findByWalletId(wallet.id);
|
||||
transactions.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
|
||||
|
||||
this.output.present({ wallet, transactions });
|
||||
|
||||
return Result.ok(undefined);
|
||||
return Result.ok({ wallet, transactions });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user