24 lines
828 B
TypeScript
24 lines
828 B
TypeScript
|
|
import { UniqueID } from "@common/domain";
|
||
|
|
import { Result } from "@common/helpers";
|
||
|
|
import { ITransactionManager } from "@common/infrastructure/database";
|
||
|
|
import { logger } from "@common/infrastructure/logger";
|
||
|
|
import { Account, IAccountService } from "@contexts/accounts/domain";
|
||
|
|
|
||
|
|
export class GetAccountsUseCase {
|
||
|
|
constructor(
|
||
|
|
private readonly accountService: IAccountService,
|
||
|
|
private readonly transactionManager: ITransactionManager
|
||
|
|
) {}
|
||
|
|
|
||
|
|
public execute(accountID: UniqueID): Promise<Result<Account, Error>> {
|
||
|
|
return this.transactionManager.complete(async (transaction) => {
|
||
|
|
try {
|
||
|
|
return await this.accountService.findAccountById(accountID, transaction);
|
||
|
|
} catch (error: unknown) {
|
||
|
|
logger.error(error as Error);
|
||
|
|
return Result.fail(error as Error);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|