refactor use cases
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
import type { Logger, UseCaseOutputPort } from '@core/shared/application';
|
||||
import type { Logger } from '@core/shared/application';
|
||||
import type { NotificationService } from '../../../notifications/application/ports/NotificationService';
|
||||
import type { NotificationType } from '../../../notifications/domain/types/NotificationTypes';
|
||||
import type { RaceEvent } from '../../domain/entities/RaceEvent';
|
||||
@@ -39,19 +39,16 @@ export type SendFinalResultsErrorCode =
|
||||
* in the main race session for a given race event.
|
||||
*/
|
||||
export class SendFinalResultsUseCase {
|
||||
constructor(
|
||||
private readonly notificationService: NotificationService,
|
||||
constructor(private readonly notificationService: NotificationService,
|
||||
private readonly raceEventRepository: IRaceEventRepository,
|
||||
private readonly resultRepository: IResultRepository,
|
||||
private readonly leagueRepository: ILeagueRepository,
|
||||
private readonly membershipRepository: ILeagueMembershipRepository,
|
||||
private readonly logger: Logger,
|
||||
private readonly output: UseCaseOutputPort<SendFinalResultsResult>,
|
||||
) {}
|
||||
private readonly logger: Logger) {}
|
||||
|
||||
async execute(
|
||||
input: SendFinalResultsInput,
|
||||
): Promise<Result<void, ApplicationErrorCode<SendFinalResultsErrorCode, { message: string }>>> {
|
||||
): Promise<Result<SendFinalResultsResult, ApplicationErrorCode<SendFinalResultsErrorCode, { message: string }>>> {
|
||||
try {
|
||||
const league = await this.leagueRepository.findById(input.leagueId);
|
||||
if (!league) {
|
||||
@@ -110,9 +107,7 @@ export class SendFinalResultsUseCase {
|
||||
notificationsSent,
|
||||
};
|
||||
|
||||
this.output.present(result);
|
||||
|
||||
return Result.ok(undefined);
|
||||
return Result.ok(result);
|
||||
} catch (error: unknown) {
|
||||
const message = error instanceof Error ? error.message : 'Failed to send final results';
|
||||
this.logger.error('SendFinalResultsUseCase.execute failed', error instanceof Error ? error : undefined);
|
||||
|
||||
Reference in New Issue
Block a user