This commit is contained in:
2025-12-11 00:57:32 +01:00
parent 1303a14493
commit 6a427eab57
112 changed files with 6148 additions and 2272 deletions

View File

@@ -113,52 +113,66 @@ import {
AcceptSponsorshipRequestUseCase,
RejectSponsorshipRequestUseCase,
} from '@gridpilot/racing/application';
import { IsDriverRegisteredForRaceUseCase } from '@gridpilot/racing/application/use-cases/IsDriverRegisteredForRaceQuery';
import { GetRaceRegistrationsUseCase } from '@gridpilot/racing/application/use-cases/GetRaceRegistrationsQuery';
import { GetRaceWithSOFUseCase } from '@gridpilot/racing/application/use-cases/GetRaceWithSOFQuery';
import { GetRaceProtestsUseCase } from '@gridpilot/racing/application/use-cases/GetRaceProtestsQuery';
import { GetRacePenaltiesUseCase } from '@gridpilot/racing/application/use-cases/GetRacePenaltiesQuery';
import { GetLeagueStandingsUseCase } from '@gridpilot/racing/application/use-cases/GetLeagueStandingsQuery';
import { GetLeagueDriverSeasonStatsUseCase } from '@gridpilot/racing/application/use-cases/GetLeagueDriverSeasonStatsQuery';
import { GetAllLeaguesWithCapacityUseCase } from '@gridpilot/racing/application/use-cases/GetAllLeaguesWithCapacityQuery';
import { GetAllLeaguesWithCapacityAndScoringUseCase } from '@gridpilot/racing/application/use-cases/GetAllLeaguesWithCapacityAndScoringQuery';
import { ListLeagueScoringPresetsUseCase } from '@gridpilot/racing/application/use-cases/ListLeagueScoringPresetsQuery';
import { GetLeagueScoringConfigUseCase } from '@gridpilot/racing/application/use-cases/GetLeagueScoringConfigQuery';
import { GetLeagueFullConfigUseCase } from '@gridpilot/racing/application/use-cases/GetLeagueFullConfigQuery';
import { GetLeagueStatsUseCase } from '@gridpilot/racing/application/use-cases/GetLeagueStatsQuery';
import { GetDashboardOverviewUseCase } from '@gridpilot/racing/application/use-cases/GetDashboardOverviewUseCase';
import { GetProfileOverviewUseCase } from '@gridpilot/racing/application/use-cases/GetProfileOverviewUseCase';
import { UpdateDriverProfileUseCase } from '@gridpilot/racing/application/use-cases/UpdateDriverProfileUseCase';
import { IsDriverRegisteredForRaceUseCase } from '@gridpilot/racing/application/use-cases/IsDriverRegisteredForRaceUseCase';
import { GetRaceRegistrationsUseCase } from '@gridpilot/racing/application/use-cases/GetRaceRegistrationsUseCase';
import { GetRaceWithSOFUseCase } from '@gridpilot/racing/application/use-cases/GetRaceWithSOFUseCase';
import { GetRaceProtestsUseCase } from '@gridpilot/racing/application/use-cases/GetRaceProtestsUseCase';
import { GetRacePenaltiesUseCase } from '@gridpilot/racing/application/use-cases/GetRacePenaltiesUseCase';
import { GetLeagueStandingsUseCase } from '@gridpilot/racing/application/use-cases/GetLeagueStandingsUseCase';
import { GetLeagueDriverSeasonStatsUseCase } from '@gridpilot/racing/application/use-cases/GetLeagueDriverSeasonStatsUseCase';
import { GetAllLeaguesWithCapacityUseCase } from '@gridpilot/racing/application/use-cases/GetAllLeaguesWithCapacityUseCase';
import { GetAllLeaguesWithCapacityAndScoringUseCase } from '@gridpilot/racing/application/use-cases/GetAllLeaguesWithCapacityAndScoringUseCase';
import { ListLeagueScoringPresetsUseCase } from '@gridpilot/racing/application/use-cases/ListLeagueScoringPresetsUseCase';
import { GetLeagueScoringConfigUseCase } from '@gridpilot/racing/application/use-cases/GetLeagueScoringConfigUseCase';
import { GetLeagueFullConfigUseCase } from '@gridpilot/racing/application/use-cases/GetLeagueFullConfigUseCase';
import { GetLeagueStatsUseCase } from '@gridpilot/racing/application/use-cases/GetLeagueStatsUseCase';
import { GetRacesPageDataUseCase } from '@gridpilot/racing/application/use-cases/GetRacesPageDataUseCase';
import { GetRaceDetailUseCase } from '@gridpilot/racing/application/use-cases/GetRaceDetailUseCase';
import { GetRaceResultsDetailUseCase } from '@gridpilot/racing/application/use-cases/GetRaceResultsDetailUseCase';
import { GetAllRacesPageDataUseCase } from '@gridpilot/racing/application/use-cases/GetAllRacesPageDataUseCase';
import { GetDriversLeaderboardUseCase } from '@gridpilot/racing/application/use-cases/GetDriversLeaderboardUseCase';
import { GetTeamsLeaderboardUseCase } from '@gridpilot/racing/application/use-cases/GetTeamsLeaderboardUseCase';
import { TransferLeagueOwnershipUseCase } from '@gridpilot/racing/application/use-cases/TransferLeagueOwnershipUseCase';
import { DriversLeaderboardPresenter } from '../../lib/presenters/DriversLeaderboardPresenter';
import { TeamsLeaderboardPresenter } from '../../lib/presenters/TeamsLeaderboardPresenter';
import { RacesPagePresenter } from '../../lib/presenters/RacesPagePresenter';
import { AllTeamsPresenter } from '../../lib/presenters/AllTeamsPresenter';
import { TeamDetailsPresenter } from '../../lib/presenters/TeamDetailsPresenter';
import { TeamMembersPresenter } from '../../lib/presenters/TeamMembersPresenter';
import { TeamJoinRequestsPresenter } from '../../lib/presenters/TeamJoinRequestsPresenter';
import { DriverTeamPresenter } from '../../lib/presenters/DriverTeamPresenter';
import { AllLeaguesWithCapacityPresenter } from '../../lib/presenters/AllLeaguesWithCapacityPresenter';
import { AllLeaguesWithCapacityAndScoringPresenter } from '../../lib/presenters/AllLeaguesWithCapacityAndScoringPresenter';
import { LeagueStatsPresenter } from '../../lib/presenters/LeagueStatsPresenter';
import { LeagueScoringConfigPresenter } from '../../lib/presenters/LeagueScoringConfigPresenter';
import { LeagueFullConfigPresenter } from '../../lib/presenters/LeagueFullConfigPresenter';
import { LeagueDriverSeasonStatsPresenter } from '../../lib/presenters/LeagueDriverSeasonStatsPresenter';
import { LeagueStandingsPresenter } from '../../lib/presenters/LeagueStandingsPresenter';
import { LeagueScoringPresetsPresenter } from '../../lib/presenters/LeagueScoringPresetsPresenter';
import { RaceWithSOFPresenter } from '../../lib/presenters/RaceWithSOFPresenter';
import { RaceProtestsPresenter } from '../../lib/presenters/RaceProtestsPresenter';
import { RacePenaltiesPresenter } from '../../lib/presenters/RacePenaltiesPresenter';
import { RaceRegistrationsPresenter } from '../../lib/presenters/RaceRegistrationsPresenter';
import { DriverRegistrationStatusPresenter } from '../../lib/presenters/DriverRegistrationStatusPresenter';
import { CancelRaceUseCase } from '@gridpilot/racing/application/use-cases/CancelRaceUseCase';
import { ImportRaceResultsUseCase } from '@gridpilot/racing/application/use-cases/ImportRaceResultsUseCase';
import { DriversLeaderboardPresenter } from './presenters/DriversLeaderboardPresenter';
import { TeamsLeaderboardPresenter } from './presenters/TeamsLeaderboardPresenter';
import { RacesPagePresenter } from './presenters/RacesPagePresenter';
import { AllRacesPagePresenter } from './presenters/AllRacesPagePresenter';
import { AllTeamsPresenter } from './presenters/AllTeamsPresenter';
import { TeamDetailsPresenter } from './presenters/TeamDetailsPresenter';
import { TeamMembersPresenter } from './presenters/TeamMembersPresenter';
import { TeamJoinRequestsPresenter } from './presenters/TeamJoinRequestsPresenter';
import { DriverTeamPresenter } from './presenters/DriverTeamPresenter';
import { AllLeaguesWithCapacityPresenter } from './presenters/AllLeaguesWithCapacityPresenter';
import { AllLeaguesWithCapacityAndScoringPresenter } from './presenters/AllLeaguesWithCapacityAndScoringPresenter';
import { LeagueStatsPresenter } from './presenters/LeagueStatsPresenter';
import { LeagueScoringConfigPresenter } from './presenters/LeagueScoringConfigPresenter';
import { LeagueFullConfigPresenter } from './presenters/LeagueFullConfigPresenter';
import { LeagueDriverSeasonStatsPresenter } from './presenters/LeagueDriverSeasonStatsPresenter';
import { LeagueStandingsPresenter } from './presenters/LeagueStandingsPresenter';
import { LeagueScoringPresetsPresenter } from './presenters/LeagueScoringPresetsPresenter';
import { RaceWithSOFPresenter } from './presenters/RaceWithSOFPresenter';
import { RaceProtestsPresenter } from './presenters/RaceProtestsPresenter';
import { RacePenaltiesPresenter } from './presenters/RacePenaltiesPresenter';
import { RaceRegistrationsPresenter } from './presenters/RaceRegistrationsPresenter';
import { DriverRegistrationStatusPresenter } from './presenters/DriverRegistrationStatusPresenter';
import { RaceDetailPresenter } from './presenters/RaceDetailPresenter';
import { RaceResultsDetailPresenter } from './presenters/RaceResultsDetailPresenter';
import { ImportRaceResultsPresenter } from './presenters/ImportRaceResultsPresenter';
import type { DriverRatingProvider } from '@gridpilot/racing/application';
import type { LeagueScoringPresetProvider } from '@gridpilot/racing/application/ports/LeagueScoringPresetProvider';
import { PreviewLeagueScheduleUseCase } from '@gridpilot/racing/application';
import { SponsorDashboardPresenter } from '../../lib/presenters/SponsorDashboardPresenter';
import { SponsorSponsorshipsPresenter } from '../../lib/presenters/SponsorSponsorshipsPresenter';
import { PendingSponsorshipRequestsPresenter } from '../../lib/presenters/PendingSponsorshipRequestsPresenter';
import { EntitySponsorshipPricingPresenter } from '../../lib/presenters/EntitySponsorshipPricingPresenter';
import { LeagueSchedulePreviewPresenter } from '../../lib/presenters/LeagueSchedulePreviewPresenter';
import { SponsorDashboardPresenter } from './presenters/SponsorDashboardPresenter';
import { SponsorSponsorshipsPresenter } from './presenters/SponsorSponsorshipsPresenter';
import { PendingSponsorshipRequestsPresenter } from './presenters/PendingSponsorshipRequestsPresenter';
import { EntitySponsorshipPricingPresenter } from './presenters/EntitySponsorshipPricingPresenter';
import { LeagueSchedulePreviewPresenter } from './presenters/LeagueSchedulePreviewPresenter';
import { DashboardOverviewPresenter } from './presenters/DashboardOverviewPresenter';
import { ProfileOverviewPresenter } from './presenters/ProfileOverviewPresenter';
// Testing support
import {
@@ -759,6 +773,8 @@ export function configureDIContainer(): void {
const gameRepository = container.resolve<IGameRepository>(DI_TOKENS.GameRepository);
const notificationRepository = container.resolve<INotificationRepository>(DI_TOKENS.NotificationRepository);
const notificationPreferenceRepository = container.resolve<INotificationPreferenceRepository>(DI_TOKENS.NotificationPreferenceRepository);
const feedRepository = container.resolve<IFeedRepository>(DI_TOKENS.FeedRepository);
const socialRepository = container.resolve<ISocialGraphRepository>(DI_TOKENS.SocialRepository);
// Register use cases - Racing
container.registerInstance(
@@ -770,12 +786,17 @@ export function configureDIContainer(): void {
DI_TOKENS.RegisterForRaceUseCase,
new RegisterForRaceUseCase(raceRegistrationRepository, leagueMembershipRepository)
);
container.registerInstance(
DI_TOKENS.WithdrawFromRaceUseCase,
new WithdrawFromRaceUseCase(raceRegistrationRepository)
);
container.registerInstance(
DI_TOKENS.CancelRaceUseCase,
new CancelRaceUseCase(raceRepository)
);
container.registerInstance(
DI_TOKENS.CreateLeagueWithSeasonAndScoringUseCase,
new CreateLeagueWithSeasonAndScoringUseCase(
@@ -1004,6 +1025,53 @@ export function configureDIContainer(): void {
new GetRacesPageDataUseCase(raceRepository, leagueRepository, racesPresenter)
);
const allRacesPagePresenter = new AllRacesPagePresenter();
container.registerInstance(
DI_TOKENS.GetAllRacesPageDataUseCase,
new GetAllRacesPageDataUseCase(raceRepository, leagueRepository, allRacesPagePresenter)
);
const raceDetailPresenter = new RaceDetailPresenter();
container.registerInstance(
DI_TOKENS.GetRaceDetailUseCase,
new GetRaceDetailUseCase(
raceRepository,
leagueRepository,
driverRepository,
raceRegistrationRepository,
resultRepository,
leagueMembershipRepository,
driverRatingProvider,
imageService,
raceDetailPresenter
)
);
const raceResultsDetailPresenter = new RaceResultsDetailPresenter();
container.registerInstance(
DI_TOKENS.GetRaceResultsDetailUseCase,
new GetRaceResultsDetailUseCase(
raceRepository,
leagueRepository,
resultRepository,
driverRepository,
penaltyRepository,
raceResultsDetailPresenter
)
);
const importRaceResultsPresenter = new ImportRaceResultsPresenter();
container.registerInstance(
DI_TOKENS.ImportRaceResultsUseCase,
new ImportRaceResultsUseCase(
raceRepository,
leagueRepository,
resultRepository,
standingRepository,
importRaceResultsPresenter
)
);
// Create services for driver leaderboard query
const rankingService = {
getAllDriverRankings: () => {
@@ -1060,6 +1128,78 @@ export function configureDIContainer(): void {
)
);
const getDriverStatsForDashboard = (driverId: string) => {
const stats = getDIContainer().resolve<Record<string, any>>(DI_TOKENS.DriverStats);
const stat = stats[driverId];
if (!stat) return null;
return {
rating: stat.rating ?? null,
wins: stat.wins ?? 0,
podiums: stat.podiums ?? 0,
totalRaces: stat.totalRaces ?? 0,
overallRank: stat.overallRank ?? null,
consistency: stat.consistency ?? null,
};
};
const getDriverStatsForProfile = (driverId: string) => {
const stats = getDIContainer().resolve<Record<string, any>>(DI_TOKENS.DriverStats);
const stat = stats[driverId];
if (!stat) return null;
return {
rating: stat.rating ?? null,
wins: stat.wins ?? 0,
podiums: stat.podiums ?? 0,
dnfs: stat.dnfs ?? 0,
totalRaces: stat.totalRaces ?? 0,
avgFinish: stat.avgFinish ?? null,
bestFinish: stat.bestFinish ?? null,
worstFinish: stat.worstFinish ?? null,
overallRank: stat.overallRank ?? null,
consistency: stat.consistency ?? null,
percentile: stat.percentile ?? null,
};
};
const dashboardOverviewPresenter = new DashboardOverviewPresenter();
container.registerInstance(
DI_TOKENS.GetDashboardOverviewUseCase,
new GetDashboardOverviewUseCase(
driverRepository,
raceRepository,
resultRepository,
leagueRepository,
standingRepository,
leagueMembershipRepository,
raceRegistrationRepository,
feedRepository,
socialRepository,
imageService,
getDriverStatsForDashboard,
dashboardOverviewPresenter
)
);
const profileOverviewPresenter = new ProfileOverviewPresenter();
container.registerInstance(
DI_TOKENS.GetProfileOverviewUseCase,
new GetProfileOverviewUseCase(
driverRepository,
teamRepository,
teamMembershipRepository,
socialRepository,
imageService,
getDriverStatsForProfile,
rankingService.getAllDriverRankings,
profileOverviewPresenter
)
);
container.registerInstance(
DI_TOKENS.UpdateDriverProfileUseCase,
new UpdateDriverProfileUseCase(driverRepository)
);
// Register use cases - Teams (Query-like with Presenters)
const allTeamsPresenter = new AllTeamsPresenter();
container.registerInstance(

View File

@@ -66,22 +66,29 @@ import type {
GetPendingSponsorshipRequestsUseCase,
GetEntitySponsorshipPricingUseCase,
} from '@gridpilot/racing/application';
import type { IsDriverRegisteredForRaceUseCase } from '@gridpilot/racing/application/use-cases/IsDriverRegisteredForRaceQuery';
import type { GetRaceRegistrationsUseCase } from '@gridpilot/racing/application/use-cases/GetRaceRegistrationsQuery';
import type { GetRaceWithSOFUseCase } from '@gridpilot/racing/application/use-cases/GetRaceWithSOFQuery';
import type { GetRaceProtestsUseCase } from '@gridpilot/racing/application/use-cases/GetRaceProtestsQuery';
import type { GetRacePenaltiesUseCase } from '@gridpilot/racing/application/use-cases/GetRacePenaltiesQuery';
import type { IsDriverRegisteredForRaceUseCase } from '@gridpilot/racing/application/use-cases/IsDriverRegisteredForRaceUseCase';
import type { GetRaceRegistrationsUseCase } from '@gridpilot/racing/application/use-cases/GetRaceRegistrationsUseCase';
import type { GetRaceWithSOFUseCase } from '@gridpilot/racing/application/use-cases/GetRaceWithSOFUseCase';
import type { GetRaceProtestsUseCase } from '@gridpilot/racing/application/use-cases/GetRaceProtestsUseCase';
import type { GetRacePenaltiesUseCase } from '@gridpilot/racing/application/use-cases/GetRacePenaltiesUseCase';
import type { GetRacesPageDataUseCase } from '@gridpilot/racing/application/use-cases/GetRacesPageDataUseCase';
import type { GetRaceDetailUseCase } from '@gridpilot/racing/application/use-cases/GetRaceDetailUseCase';
import type { GetRaceResultsDetailUseCase } from '@gridpilot/racing/application/use-cases/GetRaceResultsDetailUseCase';
import type { GetAllRacesPageDataUseCase } from '@gridpilot/racing/application/use-cases/GetAllRacesPageDataUseCase';
import type { GetProfileOverviewUseCase } from '@gridpilot/racing/application/use-cases/GetProfileOverviewUseCase';
import type { UpdateDriverProfileUseCase } from '@gridpilot/racing/application/use-cases/UpdateDriverProfileUseCase';
import type { GetDriversLeaderboardUseCase } from '@gridpilot/racing/application/use-cases/GetDriversLeaderboardUseCase';
import type { GetTeamsLeaderboardUseCase } from '@gridpilot/racing/application/use-cases/GetTeamsLeaderboardUseCase';
import type { GetLeagueStandingsUseCase } from '@gridpilot/racing/application/use-cases/GetLeagueStandingsQuery';
import type { GetLeagueDriverSeasonStatsUseCase } from '@gridpilot/racing/application/use-cases/GetLeagueDriverSeasonStatsQuery';
import type { GetAllLeaguesWithCapacityUseCase } from '@gridpilot/racing/application/use-cases/GetAllLeaguesWithCapacityQuery';
import type { GetAllLeaguesWithCapacityAndScoringUseCase } from '@gridpilot/racing/application/use-cases/GetAllLeaguesWithCapacityAndScoringQuery';
import type { ListLeagueScoringPresetsUseCase } from '@gridpilot/racing/application/use-cases/ListLeagueScoringPresetsQuery';
import type { GetLeagueScoringConfigUseCase } from '@gridpilot/racing/application/use-cases/GetLeagueScoringConfigQuery';
import type { GetLeagueFullConfigUseCase } from '@gridpilot/racing/application/use-cases/GetLeagueFullConfigQuery';
import type { GetLeagueStatsUseCase } from '@gridpilot/racing/application/use-cases/GetLeagueStatsQuery';
import type { GetLeagueStandingsUseCase } from '@gridpilot/racing/application/use-cases/GetLeagueStandingsUseCase';
import type { GetLeagueDriverSeasonStatsUseCase } from '@gridpilot/racing/application/use-cases/GetLeagueDriverSeasonStatsUseCase';
import type { GetAllLeaguesWithCapacityUseCase } from '@gridpilot/racing/application/use-cases/GetAllLeaguesWithCapacityUseCase';
import type { GetAllLeaguesWithCapacityAndScoringUseCase } from '@gridpilot/racing/application/use-cases/GetAllLeaguesWithCapacityAndScoringUseCase';
import type { ListLeagueScoringPresetsUseCase } from '@gridpilot/racing/application/use-cases/ListLeagueScoringPresetsUseCase';
import type { GetLeagueScoringConfigUseCase } from '@gridpilot/racing/application/use-cases/GetLeagueScoringConfigUseCase';
import type { GetLeagueFullConfigUseCase } from '@gridpilot/racing/application/use-cases/GetLeagueFullConfigUseCase';
import type { GetLeagueStatsUseCase } from '@gridpilot/racing/application/use-cases/GetLeagueStatsUseCase';
import type { CancelRaceUseCase } from '@gridpilot/racing/application/use-cases/CancelRaceUseCase';
import type { ImportRaceResultsUseCase } from '@gridpilot/racing/application/use-cases/ImportRaceResultsUseCase';
import type { ISponsorRepository } from '@gridpilot/racing/domain/repositories/ISponsorRepository';
import type { ISeasonSponsorshipRepository } from '@gridpilot/racing/domain/repositories/ISeasonSponsorshipRepository';
import type { ISponsorshipRequestRepository } from '@gridpilot/racing/domain/repositories/ISponsorshipRequestRepository';
@@ -90,6 +97,7 @@ import type { TransferLeagueOwnershipUseCase } from '@gridpilot/racing/applicati
import type { DriverRatingProvider } from '@gridpilot/racing/application';
import type { PreviewLeagueScheduleUseCase } from '@gridpilot/racing/application';
import type { LeagueScoringPresetProvider } from '@gridpilot/racing/application/ports/LeagueScoringPresetProvider';
import type { GetDashboardOverviewUseCase } from '@gridpilot/racing/application/use-cases/GetDashboardOverviewUseCase';
import { createDemoDriverStats, getDemoLeagueRankings, type DriverStats } from '@gridpilot/testing-support';
/**
@@ -279,6 +287,21 @@ class DIContainer {
return getDIContainer().resolve<GetRacesPageDataUseCase>(DI_TOKENS.GetRacesPageDataUseCase);
}
get getAllRacesPageDataUseCase(): GetAllRacesPageDataUseCase {
this.ensureInitialized();
return getDIContainer().resolve<GetAllRacesPageDataUseCase>(DI_TOKENS.GetAllRacesPageDataUseCase);
}
get getRaceDetailUseCase(): GetRaceDetailUseCase {
this.ensureInitialized();
return getDIContainer().resolve<GetRaceDetailUseCase>(DI_TOKENS.GetRaceDetailUseCase);
}
get getRaceResultsDetailUseCase(): GetRaceResultsDetailUseCase {
this.ensureInitialized();
return getDIContainer().resolve<GetRaceResultsDetailUseCase>(DI_TOKENS.GetRaceResultsDetailUseCase);
}
get getDriversLeaderboardUseCase(): GetDriversLeaderboardUseCase {
this.ensureInitialized();
return getDIContainer().resolve<GetDriversLeaderboardUseCase>(DI_TOKENS.GetDriversLeaderboardUseCase);
@@ -289,11 +312,36 @@ class DIContainer {
return getDIContainer().resolve<GetTeamsLeaderboardUseCase>(DI_TOKENS.GetTeamsLeaderboardUseCase);
}
get getDashboardOverviewUseCase(): GetDashboardOverviewUseCase {
this.ensureInitialized();
return getDIContainer().resolve<GetDashboardOverviewUseCase>(DI_TOKENS.GetDashboardOverviewUseCase);
}
get getProfileOverviewUseCase(): GetProfileOverviewUseCase {
this.ensureInitialized();
return getDIContainer().resolve<GetProfileOverviewUseCase>(DI_TOKENS.GetProfileOverviewUseCase);
}
get updateDriverProfileUseCase(): UpdateDriverProfileUseCase {
this.ensureInitialized();
return getDIContainer().resolve<UpdateDriverProfileUseCase>(DI_TOKENS.UpdateDriverProfileUseCase);
}
get driverRatingProvider(): DriverRatingProvider {
this.ensureInitialized();
return getDIContainer().resolve<DriverRatingProvider>(DI_TOKENS.DriverRatingProvider);
}
get cancelRaceUseCase(): CancelRaceUseCase {
this.ensureInitialized();
return getDIContainer().resolve<CancelRaceUseCase>(DI_TOKENS.CancelRaceUseCase);
}
get importRaceResultsUseCase(): ImportRaceResultsUseCase {
this.ensureInitialized();
return getDIContainer().resolve<ImportRaceResultsUseCase>(DI_TOKENS.ImportRaceResultsUseCase);
}
get createLeagueWithSeasonAndScoringUseCase(): CreateLeagueWithSeasonAndScoringUseCase {
this.ensureInitialized();
return getDIContainer().resolve<CreateLeagueWithSeasonAndScoringUseCase>(DI_TOKENS.CreateLeagueWithSeasonAndScoringUseCase);
@@ -605,6 +653,14 @@ export function getCreateLeagueWithSeasonAndScoringUseCase(): CreateLeagueWithSe
return DIContainer.getInstance().createLeagueWithSeasonAndScoringUseCase;
}
export function getCancelRaceUseCase(): CancelRaceUseCase {
return DIContainer.getInstance().cancelRaceUseCase;
}
export function getImportRaceResultsUseCase(): ImportRaceResultsUseCase {
return DIContainer.getInstance().importRaceResultsUseCase;
}
export function getGetRaceWithSOFUseCase(): GetRaceWithSOFUseCase {
return DIContainer.getInstance().getRaceWithSOFUseCase;
}
@@ -617,6 +673,18 @@ export function getGetRacesPageDataUseCase(): GetRacesPageDataUseCase {
return DIContainer.getInstance().getRacesPageDataUseCase;
}
export function getGetAllRacesPageDataUseCase(): GetAllRacesPageDataUseCase {
return DIContainer.getInstance().getAllRacesPageDataUseCase;
}
export function getGetRaceDetailUseCase(): GetRaceDetailUseCase {
return DIContainer.getInstance().getRaceDetailUseCase;
}
export function getGetRaceResultsDetailUseCase(): GetRaceResultsDetailUseCase {
return DIContainer.getInstance().getRaceResultsDetailUseCase;
}
export function getGetDriversLeaderboardUseCase(): GetDriversLeaderboardUseCase {
return DIContainer.getInstance().getDriversLeaderboardUseCase;
}
@@ -625,6 +693,18 @@ export function getGetTeamsLeaderboardUseCase(): GetTeamsLeaderboardUseCase {
return DIContainer.getInstance().getTeamsLeaderboardUseCase;
}
export function getGetDashboardOverviewUseCase(): GetDashboardOverviewUseCase {
return DIContainer.getInstance().getDashboardOverviewUseCase;
}
export function getGetProfileOverviewUseCase(): GetProfileOverviewUseCase {
return DIContainer.getInstance().getProfileOverviewUseCase;
}
export function getUpdateDriverProfileUseCase(): UpdateDriverProfileUseCase {
return DIContainer.getInstance().updateDriverProfileUseCase;
}
export function getDriverRatingProvider(): DriverRatingProvider {
return DIContainer.getInstance().driverRatingProvider;
}

View File

@@ -43,7 +43,13 @@ export const DI_TOKENS = {
WithdrawFromRaceUseCase: Symbol.for('WithdrawFromRaceUseCase'),
CreateLeagueWithSeasonAndScoringUseCase: Symbol.for('CreateLeagueWithSeasonAndScoringUseCase'),
TransferLeagueOwnershipUseCase: Symbol.for('TransferLeagueOwnershipUseCase'),
CancelRaceUseCase: Symbol.for('CancelRaceUseCase'),
ImportRaceResultsUseCase: Symbol.for('ImportRaceResultsUseCase'),
// Queries - Dashboard
GetDashboardOverviewUseCase: Symbol.for('GetDashboardOverviewUseCase'),
GetProfileOverviewUseCase: Symbol.for('GetProfileOverviewUseCase'),
// Use Cases - Teams
CreateTeamUseCase: Symbol.for('CreateTeamUseCase'),
JoinTeamUseCase: Symbol.for('JoinTeamUseCase'),
@@ -77,6 +83,9 @@ export const DI_TOKENS = {
GetRaceWithSOFUseCase: Symbol.for('GetRaceWithSOFUseCase'),
GetLeagueStatsUseCase: Symbol.for('GetLeagueStatsUseCase'),
GetRacesPageDataUseCase: Symbol.for('GetRacesPageDataUseCase'),
GetAllRacesPageDataUseCase: Symbol.for('GetAllRacesPageDataUseCase'),
GetRaceDetailUseCase: Symbol.for('GetRaceDetailUseCase'),
GetRaceResultsDetailUseCase: Symbol.for('GetRaceResultsDetailUseCase'),
GetDriversLeaderboardUseCase: Symbol.for('GetDriversLeaderboardUseCase'),
GetTeamsLeaderboardUseCase: Symbol.for('GetTeamsLeaderboardUseCase'),
@@ -105,6 +114,9 @@ export const DI_TOKENS = {
AcceptSponsorshipRequestUseCase: Symbol.for('AcceptSponsorshipRequestUseCase'),
RejectSponsorshipRequestUseCase: Symbol.for('RejectSponsorshipRequestUseCase'),
// Use Cases - Driver Profile
UpdateDriverProfileUseCase: Symbol.for('UpdateDriverProfileUseCase'),
// Data
DriverStats: Symbol.for('DriverStats'),
@@ -114,6 +126,11 @@ export const DI_TOKENS = {
RacePenaltiesPresenter: Symbol.for('IRacePenaltiesPresenter'),
RaceRegistrationsPresenter: Symbol.for('IRaceRegistrationsPresenter'),
DriverRegistrationStatusPresenter: Symbol.for('IDriverRegistrationStatusPresenter'),
RaceDetailPresenter: Symbol.for('IRaceDetailPresenter'),
RaceResultsDetailPresenter: Symbol.for('IRaceResultsDetailPresenter'),
ImportRaceResultsPresenter: Symbol.for('IImportRaceResultsPresenter'),
DashboardOverviewPresenter: Symbol.for('IDashboardOverviewPresenter'),
ProfileOverviewPresenter: Symbol.for('IProfileOverviewPresenter'),
// Presenters - Sponsors
SponsorDashboardPresenter: Symbol.for('ISponsorDashboardPresenter'),

View File

@@ -0,0 +1,16 @@
import type {
IAllRacesPagePresenter,
AllRacesPageViewModel,
} from '@gridpilot/racing/application/presenters/IAllRacesPagePresenter';
export class AllRacesPagePresenter implements IAllRacesPagePresenter {
private viewModel: AllRacesPageViewModel | null = null;
present(viewModel: AllRacesPageViewModel): void {
this.viewModel = viewModel;
}
getViewModel(): AllRacesPageViewModel | null {
return this.viewModel;
}
}

View File

@@ -0,0 +1,16 @@
import type {
IDashboardOverviewPresenter,
DashboardOverviewViewModel,
} from '@gridpilot/racing/application/presenters/IDashboardOverviewPresenter';
export class DashboardOverviewPresenter implements IDashboardOverviewPresenter {
private viewModel: DashboardOverviewViewModel | null = null;
present(viewModel: DashboardOverviewViewModel): void {
this.viewModel = viewModel;
}
getViewModel(): DashboardOverviewViewModel | null {
return this.viewModel;
}
}

View File

@@ -1,5 +1,5 @@
import type { IEntitySponsorshipPricingPresenter } from '@racing/application/presenters/IEntitySponsorshipPricingPresenter';
import type { GetEntitySponsorshipPricingResultDTO } from '@racing/application/use-cases/GetEntitySponsorshipPricingQuery';
import type { GetEntitySponsorshipPricingResultDTO } from '@racing/application/use-cases/GetEntitySponsorshipPricingUseCase';
export class EntitySponsorshipPricingPresenter implements IEntitySponsorshipPricingPresenter {
private data: GetEntitySponsorshipPricingResultDTO | null = null;

View File

@@ -0,0 +1,17 @@
import type {
IImportRaceResultsPresenter,
ImportRaceResultsSummaryViewModel,
} from '@gridpilot/racing/application/presenters/IImportRaceResultsPresenter';
export class ImportRaceResultsPresenter implements IImportRaceResultsPresenter {
private viewModel: ImportRaceResultsSummaryViewModel | null = null;
present(viewModel: ImportRaceResultsSummaryViewModel): ImportRaceResultsSummaryViewModel {
this.viewModel = viewModel;
return this.viewModel;
}
getViewModel(): ImportRaceResultsSummaryViewModel | null {
return this.viewModel;
}
}

View File

@@ -0,0 +1,292 @@
import type { League } from '@gridpilot/racing/domain/entities/League';
import type { Protest } from '@gridpilot/racing/domain/entities/Protest';
import type { Race } from '@gridpilot/racing/domain/entities/Race';
import type { DriverDTO } from '@gridpilot/racing/application/dto/DriverDTO';
import type { LeagueConfigFormModel } from '@gridpilot/racing/application';
import type { MembershipRole } from '@/lib/leagueMembership';
import { EntityMappers } from '@gridpilot/racing/application/mappers/EntityMappers';
import {
getLeagueMembershipRepository,
getDriverRepository,
getGetLeagueFullConfigUseCase,
getRaceRepository,
getProtestRepository,
getDriverStats,
getAllDriverRankings,
} from '@/lib/di-container';
export interface LeagueJoinRequestViewModel {
id: string;
leagueId: string;
driverId: string;
requestedAt: Date;
message?: string;
driver?: DriverDTO;
}
export interface ProtestDriverSummary {
[driverId: string]: DriverDTO;
}
export interface ProtestRaceSummary {
[raceId: string]: Race;
}
export interface LeagueOwnerSummaryViewModel {
driver: DriverDTO;
rating: number | null;
rank: number | null;
}
export interface LeagueAdminProtestsViewModel {
protests: Protest[];
racesById: ProtestRaceSummary;
driversById: ProtestDriverSummary;
}
export interface LeagueAdminConfigViewModel {
form: LeagueConfigFormModel | null;
}
export interface LeagueAdminPermissionsViewModel {
canRemoveMember: boolean;
canUpdateRoles: boolean;
}
export interface LeagueAdminViewModel {
joinRequests: LeagueJoinRequestViewModel[];
ownerSummary: LeagueOwnerSummaryViewModel | null;
config: LeagueAdminConfigViewModel;
protests: LeagueAdminProtestsViewModel;
}
/**
* Load join requests plus requester driver DTOs for a league.
*/
export async function loadLeagueJoinRequests(leagueId: string): Promise<LeagueJoinRequestViewModel[]> {
const membershipRepo = getLeagueMembershipRepository();
const requests = await membershipRepo.getJoinRequests(leagueId);
const driverRepo = getDriverRepository();
const uniqueDriverIds = Array.from(new Set(requests.map((r) => r.driverId)));
const driverEntities = await Promise.all(uniqueDriverIds.map((id) => driverRepo.findById(id)));
const driverDtos = driverEntities
.map((driver) => (driver ? EntityMappers.toDriverDTO(driver) : null))
.filter((dto): dto is DriverDTO => dto !== null);
const driversById: Record<string, DriverDTO> = {};
for (const dto of driverDtos) {
driversById[dto.id] = dto;
}
return requests.map((request) => ({
id: request.id,
leagueId: request.leagueId,
driverId: request.driverId,
requestedAt: request.requestedAt,
message: request.message,
driver: driversById[request.driverId],
}));
}
/**
* Approve a league join request and return updated join requests.
*/
export async function approveLeagueJoinRequest(
leagueId: string,
requestId: string
): Promise<LeagueJoinRequestViewModel[]> {
const membershipRepo = getLeagueMembershipRepository();
const requests = await membershipRepo.getJoinRequests(leagueId);
const request = requests.find((r) => r.id === requestId);
if (!request) {
throw new Error('Join request not found');
}
await membershipRepo.saveMembership({
leagueId: request.leagueId,
driverId: request.driverId,
role: 'member',
status: 'active',
joinedAt: new Date(),
});
await membershipRepo.removeJoinRequest(requestId);
return loadLeagueJoinRequests(leagueId);
}
/**
* Reject a league join request (alpha: just remove).
*/
export async function rejectLeagueJoinRequest(
leagueId: string,
requestId: string
): Promise<LeagueJoinRequestViewModel[]> {
const membershipRepo = getLeagueMembershipRepository();
await membershipRepo.removeJoinRequest(requestId);
return loadLeagueJoinRequests(leagueId);
}
/**
* Compute permissions for a performer on league membership actions.
*/
export async function getLeagueAdminPermissions(
leagueId: string,
performerDriverId: string
): Promise<LeagueAdminPermissionsViewModel> {
const membershipRepo = getLeagueMembershipRepository();
const performer = await membershipRepo.getMembership(leagueId, performerDriverId);
const isOwner = performer?.role === 'owner';
const isAdmin = performer?.role === 'admin';
return {
canRemoveMember: Boolean(isOwner || isAdmin),
canUpdateRoles: Boolean(isOwner),
};
}
/**
* Remove a member from the league, enforcing simple role rules.
*/
export async function removeLeagueMember(
leagueId: string,
performerDriverId: string,
targetDriverId: string
): Promise<void> {
const membershipRepo = getLeagueMembershipRepository();
const performer = await membershipRepo.getMembership(leagueId, performerDriverId);
if (!performer || (performer.role !== 'owner' && performer.role !== 'admin')) {
throw new Error('Only owners or admins can remove members');
}
const membership = await membershipRepo.getMembership(leagueId, targetDriverId);
if (!membership) {
throw new Error('Member not found');
}
if (membership.role === 'owner') {
throw new Error('Cannot remove the league owner');
}
await membershipRepo.removeMembership(leagueId, targetDriverId);
}
/**
* Update a member's role, enforcing simple owner-only rules.
*/
export async function updateLeagueMemberRole(
leagueId: string,
performerDriverId: string,
targetDriverId: string,
newRole: MembershipRole
): Promise<void> {
const membershipRepo = getLeagueMembershipRepository();
const performer = await membershipRepo.getMembership(leagueId, performerDriverId);
if (!performer || performer.role !== 'owner') {
throw new Error('Only the league owner can update roles');
}
const membership = await membershipRepo.getMembership(leagueId, targetDriverId);
if (!membership) {
throw new Error('Member not found');
}
if (membership.role === 'owner') {
throw new Error('Cannot change the owner role');
}
await membershipRepo.saveMembership({
...membership,
role: newRole,
});
}
/**
* Load owner summary (DTO + rating/rank) for a league.
*/
export async function loadLeagueOwnerSummary(league: League): Promise<LeagueOwnerSummaryViewModel | null> {
const driverRepo = getDriverRepository();
const entity = await driverRepo.findById(league.ownerId);
if (!entity) return null;
const ownerDriver = EntityMappers.toDriverDTO(entity);
const stats = getDriverStats(ownerDriver.id);
const allRankings = getAllDriverRankings();
let rating: number | null = stats?.rating ?? null;
let rank: number | null = null;
if (stats) {
if (typeof stats.overallRank === 'number' && stats.overallRank > 0) {
rank = stats.overallRank;
} else {
const indexInGlobal = allRankings.findIndex((stat) => stat.driverId === stats.driverId);
if (indexInGlobal !== -1) {
rank = indexInGlobal + 1;
}
}
if (rating === null) {
const globalEntry = allRankings.find((stat) => stat.driverId === stats.driverId);
if (globalEntry) {
rating = globalEntry.rating;
}
}
}
return {
driver: ownerDriver,
rating,
rank,
};
}
/**
* Load league full config form.
*/
export async function loadLeagueConfig(leagueId: string): Promise<LeagueAdminConfigViewModel> {
const useCase = getGetLeagueFullConfigUseCase();
const form = await useCase.execute({ leagueId });
return { form };
}
/**
* Load protests, related races and driver DTOs for a league.
*/
export async function loadLeagueProtests(leagueId: string): Promise<LeagueAdminProtestsViewModel> {
const raceRepo = getRaceRepository();
const protestRepo = getProtestRepository();
const driverRepo = getDriverRepository();
const leagueRaces = await raceRepo.findByLeagueId(leagueId);
const allProtests: Protest[] = [];
const racesById: Record<string, Race> = {};
for (const race of leagueRaces) {
racesById[race.id] = race;
const raceProtests = await protestRepo.findByRaceId(race.id);
allProtests.push(...raceProtests);
}
const driverIds = new Set<string>();
allProtests.forEach((p) => {
driverIds.add(p.protestingDriverId);
driverIds.add(p.accusedDriverId);
});
const driverEntities = await Promise.all(Array.from(driverIds).map((id) => driverRepo.findById(id)));
const driverDtos = driverEntities
.map((driver) => (driver ? EntityMappers.toDriverDTO(driver) : null))
.filter((dto): dto is DriverDTO => dto !== null);
const driversById: Record<string, DriverDTO> = {};
for (const dto of driverDtos) {
driversById[dto.id] = dto;
}
return {
protests: allProtests,
racesById,
driversById,
};
}

View File

@@ -0,0 +1,107 @@
import type { Race } from '@gridpilot/racing/domain/entities/Race';
import {
getRaceRepository,
getIsDriverRegisteredForRaceQuery,
getRegisterForRaceUseCase,
getWithdrawFromRaceUseCase,
} from '@/lib/di-container';
export interface LeagueScheduleRaceItemViewModel {
id: string;
leagueId: string;
track: string;
car: string;
sessionType: string;
scheduledAt: Date;
status: Race['status'];
isUpcoming: boolean;
isPast: boolean;
isRegistered: boolean;
}
export interface LeagueScheduleViewModel {
races: LeagueScheduleRaceItemViewModel[];
}
/**
* Load league schedule with registration status for a given driver.
*/
export async function loadLeagueSchedule(
leagueId: string,
driverId: string,
): Promise<LeagueScheduleViewModel> {
const raceRepo = getRaceRepository();
const isRegisteredQuery = getIsDriverRegisteredForRaceQuery();
const allRaces = await raceRepo.findAll();
const leagueRaces = allRaces
.filter((race) => race.leagueId === leagueId)
.sort(
(a, b) =>
new Date(a.scheduledAt).getTime() - new Date(b.scheduledAt).getTime(),
);
const now = new Date();
const registrationStates: Record<string, boolean> = {};
await Promise.all(
leagueRaces.map(async (race) => {
const registered = await isRegisteredQuery.execute({
raceId: race.id,
driverId,
});
registrationStates[race.id] = registered;
}),
);
const races: LeagueScheduleRaceItemViewModel[] = leagueRaces.map((race) => {
const raceDate = new Date(race.scheduledAt);
const isPast = race.status === 'completed' || raceDate <= now;
const isUpcoming = race.status === 'scheduled' && raceDate > now;
return {
id: race.id,
leagueId: race.leagueId,
track: race.track,
car: race.car,
sessionType: race.sessionType,
scheduledAt: raceDate,
status: race.status,
isUpcoming,
isPast,
isRegistered: registrationStates[race.id] ?? false,
};
});
return { races };
}
/**
* Register the driver for a race.
*/
export async function registerForRace(
raceId: string,
leagueId: string,
driverId: string,
): Promise<void> {
const useCase = getRegisterForRaceUseCase();
await useCase.execute({
raceId,
leagueId,
driverId,
});
}
/**
* Withdraw the driver from a race.
*/
export async function withdrawFromRace(
raceId: string,
driverId: string,
): Promise<void> {
const useCase = getWithdrawFromRaceUseCase();
await useCase.execute({
raceId,
driverId,
});
}

View File

@@ -1,5 +1,5 @@
import type { IPendingSponsorshipRequestsPresenter } from '@racing/application/presenters/IPendingSponsorshipRequestsPresenter';
import type { GetPendingSponsorshipRequestsResultDTO } from '@racing/application/use-cases/GetPendingSponsorshipRequestsQuery';
import type { GetPendingSponsorshipRequestsResultDTO } from '@racing/application/use-cases/GetPendingSponsorshipRequestsUseCase';
export class PendingSponsorshipRequestsPresenter implements IPendingSponsorshipRequestsPresenter {
private data: GetPendingSponsorshipRequestsResultDTO | null = null;

View File

@@ -0,0 +1,16 @@
import type {
IProfileOverviewPresenter,
ProfileOverviewViewModel,
} from '@gridpilot/racing/application/presenters/IProfileOverviewPresenter';
export class ProfileOverviewPresenter implements IProfileOverviewPresenter {
private viewModel: ProfileOverviewViewModel | null = null;
present(viewModel: ProfileOverviewViewModel): void {
this.viewModel = viewModel;
}
getViewModel(): ProfileOverviewViewModel | null {
return this.viewModel;
}
}

View File

@@ -0,0 +1,17 @@
import type {
IRaceDetailPresenter,
RaceDetailViewModel,
} from '@gridpilot/racing/application/presenters/IRaceDetailPresenter';
export class RaceDetailPresenter implements IRaceDetailPresenter {
private viewModel: RaceDetailViewModel | null = null;
present(viewModel: RaceDetailViewModel): RaceDetailViewModel {
this.viewModel = viewModel;
return this.viewModel;
}
getViewModel(): RaceDetailViewModel | null {
return this.viewModel;
}
}

View File

@@ -0,0 +1,17 @@
import type {
IRaceResultsDetailPresenter,
RaceResultsDetailViewModel,
} from '@gridpilot/racing/application/presenters/IRaceResultsDetailPresenter';
export class RaceResultsDetailPresenter implements IRaceResultsDetailPresenter {
private viewModel: RaceResultsDetailViewModel | null = null;
present(viewModel: RaceResultsDetailViewModel): RaceResultsDetailViewModel {
this.viewModel = viewModel;
return this.viewModel;
}
getViewModel(): RaceResultsDetailViewModel | null {
return this.viewModel;
}
}

View File

@@ -0,0 +1,71 @@
import { Race } from '@gridpilot/racing/domain/entities/Race';
import { InMemoryRaceRepository } from '@gridpilot/racing/infrastructure/repositories/InMemoryRaceRepository';
import { getRaceRepository, getLeagueRepository } from '@/lib/di-container';
export type SessionType = 'practice' | 'qualifying' | 'race';
export interface ScheduleRaceFormData {
leagueId: string;
track: string;
car: string;
sessionType: SessionType;
scheduledDate: string;
scheduledTime: string;
}
export interface ScheduledRaceViewModel {
id: string;
leagueId: string;
track: string;
car: string;
sessionType: SessionType;
scheduledAt: Date;
status: string;
}
export interface LeagueOptionViewModel {
id: string;
name: string;
}
/**
* Presenter/Facade for the schedule race form.
* Encapsulates all domain/repository access so the component can stay purely presentational.
*/
export async function loadScheduleRaceFormLeagues(): Promise<LeagueOptionViewModel[]> {
const leagueRepo = getLeagueRepository();
const allLeagues = await leagueRepo.findAll();
return allLeagues.map((league) => ({
id: league.id,
name: league.name,
}));
}
export async function scheduleRaceFromForm(
formData: ScheduleRaceFormData
): Promise<ScheduledRaceViewModel> {
const raceRepo = getRaceRepository();
const scheduledAt = new Date(`${formData.scheduledDate}T${formData.scheduledTime}`);
const race = Race.create({
id: InMemoryRaceRepository.generateId(),
leagueId: formData.leagueId,
track: formData.track.trim(),
car: formData.car.trim(),
sessionType: formData.sessionType,
scheduledAt,
status: 'scheduled',
});
const createdRace = await raceRepo.create(race);
return {
id: createdRace.id,
leagueId: createdRace.leagueId,
track: createdRace.track,
car: createdRace.car,
sessionType: createdRace.sessionType as SessionType,
scheduledAt: createdRace.scheduledAt,
status: createdRace.status,
};
}

View File

@@ -1,5 +1,5 @@
import type { ISponsorDashboardPresenter } from '@racing/application/presenters/ISponsorDashboardPresenter';
import type { SponsorDashboardDTO } from '@racing/application/use-cases/GetSponsorDashboardQuery';
import type { SponsorDashboardDTO } from '@racing/application/use-cases/GetSponsorDashboardUseCase';
export class SponsorDashboardPresenter implements ISponsorDashboardPresenter {
private data: SponsorDashboardDTO | null = null;

View File

@@ -1,5 +1,5 @@
import type { ISponsorSponsorshipsPresenter } from '@racing/application/presenters/ISponsorSponsorshipsPresenter';
import type { SponsorSponsorshipsDTO } from '@racing/application/use-cases/GetSponsorSponsorshipsQuery';
import type { SponsorSponsorshipsDTO } from '@racing/application/use-cases/GetSponsorSponsorshipsUseCase';
export class SponsorSponsorshipsPresenter implements ISponsorSponsorshipsPresenter {
private data: SponsorSponsorshipsDTO | null = null;

View File

@@ -0,0 +1,59 @@
import type { TeamMembership, TeamRole } from '@gridpilot/racing';
import type { DriverDTO } from '@gridpilot/racing/application/dto/DriverDTO';
import { EntityMappers } from '@gridpilot/racing/application/mappers/EntityMappers';
import { getDriverRepository, getDriverStats } from '@/lib/di-container';
export interface TeamRosterMemberViewModel {
driver: DriverDTO;
role: TeamRole;
joinedAt: string;
rating: number | null;
overallRank: number | null;
}
export interface TeamRosterViewModel {
members: TeamRosterMemberViewModel[];
averageRating: number;
}
/**
* Presenter/facade for team roster.
* Encapsulates repository and stats access so the TeamRoster component can remain a pure view.
*/
export async function getTeamRosterViewModel(
memberships: TeamMembership[]
): Promise<TeamRosterViewModel> {
const driverRepo = getDriverRepository();
const allDrivers = await driverRepo.findAll();
const members: TeamRosterMemberViewModel[] = [];
for (const membership of memberships) {
const driver = allDrivers.find((d) => d.id === membership.driverId);
if (!driver) continue;
const dto = EntityMappers.toDriverDTO(driver);
if (!dto) continue;
const stats = getDriverStats(membership.driverId);
members.push({
driver: dto,
role: membership.role,
joinedAt: membership.joinedAt.toISOString(),
rating: stats?.rating ?? null,
overallRank: typeof stats?.overallRank === 'number' ? stats.overallRank : null,
});
}
const averageRating =
members.length > 0
? Math.round(
members.reduce((sum, m) => sum + (m.rating ?? 0), 0) / members.length
)
: 0;
return {
members,
averageRating,
};
}

View File

@@ -9,9 +9,35 @@ export class TeamsLeaderboardPresenter implements ITeamsLeaderboardPresenter {
private viewModel: TeamsLeaderboardViewModel | null = null;
present(teams: any[], recruitingCount: number): void {
const transformedTeams = teams.map((team) => this.transformTeam(team));
const groupsBySkillLevel = transformedTeams.reduce<Record<SkillLevel, TeamLeaderboardItemViewModel[]>>(
(acc, team) => {
if (!acc[team.performanceLevel]) {
acc[team.performanceLevel] = [];
}
acc[team.performanceLevel]!.push(team);
return acc;
},
{
beginner: [],
intermediate: [],
advanced: [],
pro: [],
},
);
const topTeams = transformedTeams
.filter((t) => t.rating !== null)
.slice()
.sort((a, b) => (b.rating ?? 0) - (a.rating ?? 0))
.slice(0, 5);
this.viewModel = {
teams: teams.map((team) => this.transformTeam(team)),
teams: transformedTeams,
recruitingCount,
groupsBySkillLevel,
topTeams,
};
}