This commit is contained in:
2025-12-21 17:05:36 +01:00
parent 08b0d59e45
commit f2d8a23583
66 changed files with 1131 additions and 1342 deletions

View File

@@ -14,7 +14,7 @@ import { SeasonStewardingConfig } from '../../domain/value-objects/SeasonSteward
import { WeekdaySet } from '../../domain/value-objects/WeekdaySet';
import type { LeagueConfigFormModel } from '../dto/LeagueConfigFormDTO';
// TODO The whole file mixes a lot of concerns...
// TODO The whole file mixes a lot of concerns...should be resolved into use cases or is it obsolet?
export interface CreateSeasonForLeagueCommand {
leagueId: string;

View File

@@ -9,7 +9,6 @@ import type { IFeedRepository } from '@core/social/domain/repositories/IFeedRepo
import type { ISocialGraphRepository } from '@core/social/domain/repositories/ISocialGraphRepository';
import { Result } from '@core/shared/application/Result';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
import { League } from '../../domain/entities/League';
import { Race } from '../../domain/entities/Race';
import { Result as RaceResult } from '../../domain/entities/Result';
@@ -97,14 +96,13 @@ export class DashboardOverviewUseCase {
private readonly getDriverStats: (
driverId: string,
) => DashboardDriverStatsAdapter | null,
private readonly output: UseCaseOutputPort<DashboardOverviewResult>,
) {}
async execute(
input: DashboardOverviewInput,
): Promise<
Result<
void,
DashboardOverviewResult,
ApplicationErrorCode<'DRIVER_NOT_FOUND' | 'REPOSITORY_ERROR', { message: string }>
>
> {
@@ -209,9 +207,7 @@ export class DashboardOverviewUseCase {
friends: friendsSummary,
};
this.output.present(result);
return Result.ok(undefined);
return Result.ok(result);
} catch (error) {
return Result.err({
code: 'REPOSITORY_ERROR',

View File

@@ -27,14 +27,14 @@ export class GetAllLeaguesWithCapacityUseCase {
constructor(
private readonly leagueRepository: ILeagueRepository,
private readonly leagueMembershipRepository: ILeagueMembershipRepository,
private readonly output: UseCaseOutputPort<GetAllLeaguesWithCapacityResult>,
private readonly outputPort: UseCaseOutputPort<GetAllLeaguesWithCapacityResult, GetAllLeaguesWithCapacityErrorCode>,
) {}
async execute(
_input: GetAllLeaguesWithCapacityInput = {},
): Promise<
Result<
void,
GetAllLeaguesWithCapacityResult,
ApplicationErrorCode<GetAllLeaguesWithCapacityErrorCode, { message: string }>
>
> {
@@ -44,15 +44,15 @@ export class GetAllLeaguesWithCapacityUseCase {
const summaries: LeagueCapacitySummary[] = [];
for (const league of leagues) {
const members = await this.leagueMembershipRepository.getLeagueMembers(league.id);
const members = await this.leagueMembershipRepository.getLeagueMembers(league.id.toString());
const currentDrivers = members.filter(
(m) =>
m.status === 'active' &&
(m.role === 'owner' ||
m.role === 'admin' ||
m.role === 'steward' ||
m.role === 'member'),
m.status.toString() === 'active' &&
(m.role.toString() === 'owner' ||
m.role.toString() === 'admin' ||
m.role.toString() === 'steward' ||
m.role.toString() === 'member'),
).length;
const maxDrivers = league.settings.maxDrivers ?? 0;
@@ -60,9 +60,7 @@ export class GetAllLeaguesWithCapacityUseCase {
summaries.push({ league, currentDrivers, maxDrivers });
}
this.output.present({ leagues: summaries });
return Result.ok(undefined);
return Result.ok({ leagues: summaries });
} catch (error: unknown) {
const message =
error instanceof Error && error.message

View File

@@ -52,7 +52,7 @@ export class GetDriversLeaderboardUseCase {
async execute(
_input: GetDriversLeaderboardInput,
): Promise<Result<void, ApplicationErrorCode<GetDriversLeaderboardErrorCode, { message: string }>>> {
): Promise<Result<GetDriversLeaderboardResult, ApplicationErrorCode<GetDriversLeaderboardErrorCode, { message: string }>>> {
this.logger.debug('Executing GetDriversLeaderboardUseCase');
try {
const drivers = await this.driverRepository.findAll();
@@ -90,14 +90,12 @@ export class GetDriversLeaderboardUseCase {
this.logger.debug('Successfully retrieved drivers leaderboard.');
this.output.present({
return Result.ok({
items: items.sort((a, b) => b.rating - a.rating),
totalRaces,
totalWins,
activeCount,
});
return Result.ok(undefined);
} catch (error) {
this.logger.error(
'Error executing GetDriversLeaderboardUseCase',