refactor use cases
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
import type { Team } from '../../domain/entities/Team';
|
||||
import type { ITeamMembershipRepository } from '../../domain/repositories/ITeamMembershipRepository';
|
||||
@@ -23,15 +22,12 @@ export type UpdateTeamResult = {
|
||||
export type UpdateTeamErrorCode = 'TEAM_NOT_FOUND' | 'PERMISSION_DENIED' | 'REPOSITORY_ERROR';
|
||||
|
||||
export class UpdateTeamUseCase {
|
||||
constructor(
|
||||
private readonly teamRepository: ITeamRepository,
|
||||
private readonly membershipRepository: ITeamMembershipRepository,
|
||||
private readonly output: UseCaseOutputPort<UpdateTeamResult>,
|
||||
) {}
|
||||
constructor(private readonly teamRepository: ITeamRepository,
|
||||
private readonly membershipRepository: ITeamMembershipRepository) {}
|
||||
|
||||
async execute(
|
||||
command: UpdateTeamInput,
|
||||
): Promise<Result<void, ApplicationErrorCode<UpdateTeamErrorCode, { message: string }>>> {
|
||||
): Promise<Result<UpdateTeamResult, ApplicationErrorCode<UpdateTeamErrorCode, { message: string }>>> {
|
||||
try {
|
||||
const { teamId, updatedBy, updates } = command;
|
||||
|
||||
@@ -64,9 +60,7 @@ export class UpdateTeamUseCase {
|
||||
|
||||
await this.teamRepository.update(updated);
|
||||
|
||||
this.output.present({ team: updated });
|
||||
|
||||
return Result.ok(undefined);
|
||||
return Result.ok({ team: updated });
|
||||
} catch (err) {
|
||||
const error = err as { message?: string } | undefined;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user