refactor use cases
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import type { Logger, UseCaseOutputPort } from '@core/shared/application';
|
||||
import type { Logger } from '@core/shared/application';
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
import type { NotificationService } from '../../../notifications/application/ports/NotificationService';
|
||||
@@ -43,20 +43,17 @@ export type SendPerformanceSummaryErrorCode =
|
||||
* for a specific race event.
|
||||
*/
|
||||
export class SendPerformanceSummaryUseCase {
|
||||
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 driverRepository: IDriverRepository,
|
||||
private readonly logger: Logger,
|
||||
private readonly output: UseCaseOutputPort<SendPerformanceSummaryResult>,
|
||||
) {}
|
||||
private readonly logger: Logger) {}
|
||||
|
||||
async execute(
|
||||
input: SendPerformanceSummaryInput,
|
||||
): Promise<Result<void, ApplicationErrorCode<SendPerformanceSummaryErrorCode, { message: string }>>> {
|
||||
): Promise<Result<SendPerformanceSummaryResult, ApplicationErrorCode<SendPerformanceSummaryErrorCode, { message: string }>>> {
|
||||
try {
|
||||
const league = await this.leagueRepository.findById(input.leagueId);
|
||||
if (!league) {
|
||||
@@ -116,9 +113,7 @@ export class SendPerformanceSummaryUseCase {
|
||||
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 performance summary';
|
||||
this.logger.error('SendPerformanceSummaryUseCase.execute failed', error instanceof Error ? error : undefined);
|
||||
|
||||
Reference in New Issue
Block a user