refactor use cases
This commit is contained in:
@@ -8,7 +8,6 @@ import type { IWalletRepository, ITransactionRepository } from '../../domain/rep
|
||||
import type { Wallet, Transaction } from '../../domain/entities/Wallet';
|
||||
import { TransactionType, ReferenceType } 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';
|
||||
|
||||
@@ -29,15 +28,14 @@ export interface ProcessWalletTransactionResult {
|
||||
export type ProcessWalletTransactionErrorCode = 'MISSING_REQUIRED_FIELDS' | 'INVALID_TYPE' | 'INSUFFICIENT_BALANCE';
|
||||
|
||||
export class ProcessWalletTransactionUseCase
|
||||
implements UseCase<ProcessWalletTransactionInput, void, ProcessWalletTransactionErrorCode>
|
||||
implements UseCase<ProcessWalletTransactionInput, ProcessWalletTransactionResult, ProcessWalletTransactionErrorCode>
|
||||
{
|
||||
constructor(
|
||||
private readonly walletRepository: IWalletRepository,
|
||||
private readonly transactionRepository: ITransactionRepository,
|
||||
private readonly output: UseCaseOutputPort<ProcessWalletTransactionResult>,
|
||||
) {}
|
||||
|
||||
async execute(input: ProcessWalletTransactionInput): Promise<Result<void, ApplicationErrorCode<ProcessWalletTransactionErrorCode>>> {
|
||||
async execute(input: ProcessWalletTransactionInput): Promise<Result<ProcessWalletTransactionResult, ApplicationErrorCode<ProcessWalletTransactionErrorCode>>> {
|
||||
const { leagueId, type, amount, description, referenceId, referenceType } = input;
|
||||
|
||||
if (!leagueId || !type || amount === undefined || !description) {
|
||||
@@ -95,8 +93,6 @@ export class ProcessWalletTransactionUseCase
|
||||
|
||||
const updatedWallet = await this.walletRepository.update(wallet);
|
||||
|
||||
this.output.present({ wallet: updatedWallet, transaction: createdTransaction });
|
||||
|
||||
return Result.ok(undefined);
|
||||
return Result.ok({ wallet: updatedWallet, transaction: createdTransaction });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user