refactor driver module (wip)
This commit is contained in:
@@ -128,7 +128,7 @@ export const DriverProviders: Provider[] = [
|
||||
driverStatsService: IDriverStatsService,
|
||||
imageService: IImageServicePort,
|
||||
logger: Logger,
|
||||
) => new GetDriversLeaderboardUseCase(driverRepo, rankingService, driverStatsService, imageService, logger),
|
||||
) => new GetDriversLeaderboardUseCase(driverRepo, rankingService, driverStatsService, (driverId: string) => Promise.resolve(imageService.getDriverAvatar(driverId)), logger),
|
||||
inject: [DRIVER_REPOSITORY_TOKEN, RANKING_SERVICE_TOKEN, DRIVER_STATS_SERVICE_TOKEN, IMAGE_SERVICE_PORT_TOKEN, LOGGER_TOKEN],
|
||||
},
|
||||
{
|
||||
@@ -169,7 +169,7 @@ export const DriverProviders: Provider[] = [
|
||||
teamRepository,
|
||||
teamMembershipRepository,
|
||||
socialRepository,
|
||||
(driverId: string) => Promise.resolve(imageService.getDriverAvatar(driverId)),
|
||||
imageService,
|
||||
driverExtendedProfileProvider,
|
||||
(driverId: string) => {
|
||||
const stats = driverStatsService.getDriverStats(driverId);
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
export enum DriverProfileAchievementRarity {
|
||||
COMMON = 'common',
|
||||
RARE = 'rare',
|
||||
EPIC = 'epic',
|
||||
LEGENDARY = 'legendary',
|
||||
}
|
||||
|
||||
export class DriverProfileAchievementDTO {
|
||||
@ApiProperty()
|
||||
id!: string;
|
||||
|
||||
@ApiProperty()
|
||||
title!: string;
|
||||
|
||||
@ApiProperty()
|
||||
description!: string;
|
||||
|
||||
@ApiProperty({ enum: ['trophy', 'medal', 'star', 'crown', 'target', 'zap'] })
|
||||
icon!: 'trophy' | 'medal' | 'star' | 'crown' | 'target' | 'zap';
|
||||
|
||||
@ApiProperty({ enum: DriverProfileAchievementRarity })
|
||||
rarity!: DriverProfileAchievementRarity;
|
||||
|
||||
@ApiProperty()
|
||||
earnedAt!: string;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
export class DriverProfileDriverSummaryDTO {
|
||||
@ApiProperty()
|
||||
id!: string;
|
||||
|
||||
@ApiProperty()
|
||||
name!: string;
|
||||
|
||||
@ApiProperty()
|
||||
country!: string;
|
||||
|
||||
@ApiProperty()
|
||||
avatarUrl!: string;
|
||||
|
||||
@ApiProperty({ nullable: true })
|
||||
iracingId!: string | null;
|
||||
|
||||
@ApiProperty()
|
||||
joinedAt!: string;
|
||||
|
||||
@ApiProperty({ nullable: true })
|
||||
rating!: number | null;
|
||||
|
||||
@ApiProperty({ nullable: true })
|
||||
globalRank!: number | null;
|
||||
|
||||
@ApiProperty({ nullable: true })
|
||||
consistency!: number | null;
|
||||
|
||||
@ApiProperty({ nullable: true })
|
||||
bio!: string | null;
|
||||
|
||||
@ApiProperty({ nullable: true })
|
||||
totalDrivers!: number | null;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
import { DriverProfileSocialHandleDTO } from './DriverProfileSocialHandleDTO';
|
||||
|
||||
import { DriverProfileAchievementDTO } from './DriverProfileAchievementDTO';
|
||||
|
||||
export class DriverProfileExtendedProfileDTO {
|
||||
@ApiProperty({ type: [DriverProfileSocialHandleDTO] })
|
||||
socialHandles!: DriverProfileSocialHandleDTO[];
|
||||
|
||||
@ApiProperty({ type: [DriverProfileAchievementDTO] })
|
||||
achievements!: DriverProfileAchievementDTO[];
|
||||
|
||||
@ApiProperty()
|
||||
racingStyle!: string;
|
||||
|
||||
@ApiProperty()
|
||||
favoriteTrack!: string;
|
||||
|
||||
@ApiProperty()
|
||||
favoriteCar!: string;
|
||||
|
||||
@ApiProperty()
|
||||
timezone!: string;
|
||||
|
||||
@ApiProperty()
|
||||
availableHours!: string;
|
||||
|
||||
@ApiProperty()
|
||||
lookingForTeam!: boolean;
|
||||
|
||||
@ApiProperty()
|
||||
openToRequests!: boolean;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
export class DriverProfileFinishDistributionDTO {
|
||||
@ApiProperty()
|
||||
totalRaces!: number;
|
||||
|
||||
@ApiProperty()
|
||||
wins!: number;
|
||||
|
||||
@ApiProperty()
|
||||
podiums!: number;
|
||||
|
||||
@ApiProperty()
|
||||
topTen!: number;
|
||||
|
||||
@ApiProperty()
|
||||
dnfs!: number;
|
||||
|
||||
@ApiProperty()
|
||||
other!: number;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
export class DriverProfileSocialFriendSummaryDTO {
|
||||
@ApiProperty()
|
||||
id!: string;
|
||||
|
||||
@ApiProperty()
|
||||
name!: string;
|
||||
|
||||
@ApiProperty()
|
||||
country!: string;
|
||||
|
||||
@ApiProperty()
|
||||
avatarUrl!: string;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
export type DriverProfileSocialPlatform = 'twitter' | 'youtube' | 'twitch' | 'discord';
|
||||
|
||||
export class DriverProfileSocialHandleDTO {
|
||||
@ApiProperty({ enum: ['twitter', 'youtube', 'twitch', 'discord'] })
|
||||
platform!: DriverProfileSocialPlatform;
|
||||
|
||||
@ApiProperty()
|
||||
handle!: string;
|
||||
|
||||
@ApiProperty()
|
||||
url!: string;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
import { DriverProfileSocialFriendSummaryDTO } from './DriverProfileSocialFriendSummaryDTO';
|
||||
|
||||
export class DriverProfileSocialSummaryDTO {
|
||||
@ApiProperty()
|
||||
friendsCount!: number;
|
||||
|
||||
@ApiProperty({ type: [DriverProfileSocialFriendSummaryDTO] })
|
||||
friends!: DriverProfileSocialFriendSummaryDTO[];
|
||||
}
|
||||
45
apps/api/src/domain/driver/dtos/DriverProfileStatsDTO.ts
Normal file
45
apps/api/src/domain/driver/dtos/DriverProfileStatsDTO.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
export class DriverProfileStatsDTO {
|
||||
@ApiProperty()
|
||||
totalRaces!: number;
|
||||
|
||||
@ApiProperty()
|
||||
wins!: number;
|
||||
|
||||
@ApiProperty()
|
||||
podiums!: number;
|
||||
|
||||
@ApiProperty()
|
||||
dnfs!: number;
|
||||
|
||||
@ApiProperty({ nullable: true })
|
||||
avgFinish!: number | null;
|
||||
|
||||
@ApiProperty({ nullable: true })
|
||||
bestFinish!: number | null;
|
||||
|
||||
@ApiProperty({ nullable: true })
|
||||
worstFinish!: number | null;
|
||||
|
||||
@ApiProperty({ nullable: true })
|
||||
finishRate!: number | null;
|
||||
|
||||
@ApiProperty({ nullable: true })
|
||||
winRate!: number | null;
|
||||
|
||||
@ApiProperty({ nullable: true })
|
||||
podiumRate!: number | null;
|
||||
|
||||
@ApiProperty({ nullable: true })
|
||||
percentile!: number | null;
|
||||
|
||||
@ApiProperty({ nullable: true })
|
||||
rating!: number | null;
|
||||
|
||||
@ApiProperty({ nullable: true })
|
||||
consistency!: number | null;
|
||||
|
||||
@ApiProperty({ nullable: true })
|
||||
overallRank!: number | null;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
export class DriverProfileTeamMembershipDTO {
|
||||
@ApiProperty()
|
||||
teamId!: string;
|
||||
|
||||
@ApiProperty()
|
||||
teamName!: string;
|
||||
|
||||
@ApiProperty({ nullable: true })
|
||||
teamTag!: string | null;
|
||||
|
||||
@ApiProperty()
|
||||
role!: string;
|
||||
|
||||
@ApiProperty()
|
||||
joinedAt!: string;
|
||||
|
||||
@ApiProperty()
|
||||
isCurrent!: boolean;
|
||||
}
|
||||
@@ -1,231 +1,28 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
export class DriverProfileDriverSummaryDTO {
|
||||
@ApiProperty()
|
||||
id!: string;
|
||||
|
||||
@ApiProperty()
|
||||
name!: string;
|
||||
|
||||
@ApiProperty()
|
||||
country!: string;
|
||||
|
||||
@ApiProperty()
|
||||
avatarUrl!: string;
|
||||
|
||||
@ApiProperty({ nullable: true })
|
||||
iracingId!: string | null;
|
||||
|
||||
@ApiProperty()
|
||||
joinedAt!: string;
|
||||
|
||||
@ApiProperty({ nullable: true })
|
||||
rating!: number | null;
|
||||
|
||||
@ApiProperty({ nullable: true })
|
||||
globalRank!: number | null;
|
||||
|
||||
@ApiProperty({ nullable: true })
|
||||
consistency!: number | null;
|
||||
|
||||
@ApiProperty({ nullable: true })
|
||||
bio!: string | null;
|
||||
|
||||
@ApiProperty({ nullable: true })
|
||||
totalDrivers!: number | null;
|
||||
}
|
||||
|
||||
export class DriverProfileStatsDTO {
|
||||
@ApiProperty()
|
||||
totalRaces!: number;
|
||||
|
||||
@ApiProperty()
|
||||
wins!: number;
|
||||
|
||||
@ApiProperty()
|
||||
podiums!: number;
|
||||
|
||||
@ApiProperty()
|
||||
dnfs!: number;
|
||||
|
||||
@ApiProperty({ nullable: true })
|
||||
avgFinish!: number | null;
|
||||
|
||||
@ApiProperty({ nullable: true })
|
||||
bestFinish!: number | null;
|
||||
|
||||
@ApiProperty({ nullable: true })
|
||||
worstFinish!: number | null;
|
||||
|
||||
@ApiProperty({ nullable: true })
|
||||
finishRate!: number | null;
|
||||
|
||||
@ApiProperty({ nullable: true })
|
||||
winRate!: number | null;
|
||||
|
||||
@ApiProperty({ nullable: true })
|
||||
podiumRate!: number | null;
|
||||
|
||||
@ApiProperty({ nullable: true })
|
||||
percentile!: number | null;
|
||||
|
||||
@ApiProperty({ nullable: true })
|
||||
rating!: number | null;
|
||||
|
||||
@ApiProperty({ nullable: true })
|
||||
consistency!: number | null;
|
||||
|
||||
@ApiProperty({ nullable: true })
|
||||
overallRank!: number | null;
|
||||
}
|
||||
|
||||
export class DriverProfileFinishDistributionDTO {
|
||||
@ApiProperty()
|
||||
totalRaces: number;
|
||||
|
||||
@ApiProperty()
|
||||
wins: number;
|
||||
|
||||
@ApiProperty()
|
||||
podiums: number;
|
||||
|
||||
@ApiProperty()
|
||||
topTen: number;
|
||||
|
||||
@ApiProperty()
|
||||
dnfs: number;
|
||||
|
||||
@ApiProperty()
|
||||
other: number;
|
||||
}
|
||||
|
||||
export class DriverProfileTeamMembershipDTO {
|
||||
@ApiProperty()
|
||||
teamId: string;
|
||||
|
||||
@ApiProperty()
|
||||
teamName: string;
|
||||
|
||||
@ApiProperty({ nullable: true })
|
||||
teamTag: string | null;
|
||||
|
||||
@ApiProperty()
|
||||
role: string;
|
||||
|
||||
@ApiProperty()
|
||||
joinedAt: string;
|
||||
|
||||
@ApiProperty()
|
||||
isCurrent: boolean;
|
||||
}
|
||||
|
||||
export class DriverProfileSocialFriendSummaryDTO {
|
||||
@ApiProperty()
|
||||
id: string;
|
||||
|
||||
@ApiProperty()
|
||||
name: string;
|
||||
|
||||
@ApiProperty()
|
||||
country: string;
|
||||
|
||||
@ApiProperty()
|
||||
avatarUrl: string;
|
||||
}
|
||||
|
||||
export class DriverProfileSocialSummaryDTO {
|
||||
@ApiProperty()
|
||||
friendsCount: number;
|
||||
|
||||
@ApiProperty({ type: [DriverProfileSocialFriendSummaryDTO] })
|
||||
friends: DriverProfileSocialFriendSummaryDTO[];
|
||||
}
|
||||
|
||||
export type DriverProfileSocialPlatform = 'twitter' | 'youtube' | 'twitch' | 'discord';
|
||||
|
||||
export enum DriverProfileAchievementRarity {
|
||||
COMMON = 'common',
|
||||
RARE = 'rare',
|
||||
EPIC = 'epic',
|
||||
LEGENDARY = 'legendary',
|
||||
}
|
||||
|
||||
export class DriverProfileAchievementDTO {
|
||||
@ApiProperty()
|
||||
id: string;
|
||||
|
||||
@ApiProperty()
|
||||
title: string;
|
||||
|
||||
@ApiProperty()
|
||||
description: string;
|
||||
|
||||
@ApiProperty({ enum: ['trophy', 'medal', 'star', 'crown', 'target', 'zap'] })
|
||||
icon: 'trophy' | 'medal' | 'star' | 'crown' | 'target' | 'zap';
|
||||
|
||||
@ApiProperty({ enum: DriverProfileAchievementRarity })
|
||||
rarity: DriverProfileAchievementRarity;
|
||||
|
||||
@ApiProperty()
|
||||
earnedAt: string;
|
||||
}
|
||||
|
||||
export class DriverProfileSocialHandleDTO {
|
||||
@ApiProperty({ enum: DriverProfileSocialPlatform })
|
||||
platform: DriverProfileSocialPlatform;
|
||||
|
||||
@ApiProperty()
|
||||
handle: string;
|
||||
|
||||
@ApiProperty()
|
||||
url: string;
|
||||
}
|
||||
|
||||
export class DriverProfileExtendedProfileDTO {
|
||||
@ApiProperty({ type: [DriverProfileSocialHandleDTO] })
|
||||
socialHandles: DriverProfileSocialHandleDTO[];
|
||||
|
||||
@ApiProperty({ type: [DriverProfileAchievementDTO] })
|
||||
achievements: DriverProfileAchievementDTO[];
|
||||
|
||||
@ApiProperty()
|
||||
racingStyle: string;
|
||||
|
||||
@ApiProperty()
|
||||
favoriteTrack: string;
|
||||
|
||||
@ApiProperty()
|
||||
favoriteCar: string;
|
||||
|
||||
@ApiProperty()
|
||||
timezone: string;
|
||||
|
||||
@ApiProperty()
|
||||
availableHours: string;
|
||||
|
||||
@ApiProperty()
|
||||
lookingForTeam: boolean;
|
||||
|
||||
@ApiProperty()
|
||||
openToRequests: boolean;
|
||||
}
|
||||
import { DriverProfileDriverSummaryDTO } from './DriverProfileDriverSummaryDTO';
|
||||
import { DriverProfileStatsDTO } from './DriverProfileStatsDTO';
|
||||
import { DriverProfileFinishDistributionDTO } from './DriverProfileFinishDistributionDTO';
|
||||
import { DriverProfileTeamMembershipDTO } from './DriverProfileTeamMembershipDTO';
|
||||
import { DriverProfileSocialSummaryDTO } from './DriverProfileSocialSummaryDTO';
|
||||
import { DriverProfileExtendedProfileDTO } from './DriverProfileExtendedProfileDTO';
|
||||
|
||||
export class GetDriverProfileOutputDTO {
|
||||
@ApiProperty({ type: DriverProfileDriverSummaryDTO, nullable: true })
|
||||
currentDriver: DriverProfileDriverSummaryDTO | null;
|
||||
currentDriver!: DriverProfileDriverSummaryDTO | null;
|
||||
|
||||
@ApiProperty({ type: DriverProfileStatsDTO, nullable: true })
|
||||
stats: DriverProfileStatsDTO | null;
|
||||
stats!: DriverProfileStatsDTO | null;
|
||||
|
||||
@ApiProperty({ type: DriverProfileFinishDistributionDTO, nullable: true })
|
||||
finishDistribution: DriverProfileFinishDistributionDTO | null;
|
||||
finishDistribution!: DriverProfileFinishDistributionDTO | null;
|
||||
|
||||
@ApiProperty({ type: [DriverProfileTeamMembershipDTO] })
|
||||
teamMemberships: DriverProfileTeamMembershipDTO[];
|
||||
teamMemberships!: DriverProfileTeamMembershipDTO[];
|
||||
|
||||
@ApiProperty({ type: DriverProfileSocialSummaryDTO })
|
||||
socialSummary: DriverProfileSocialSummaryDTO;
|
||||
socialSummary!: DriverProfileSocialSummaryDTO;
|
||||
|
||||
@ApiProperty({ type: DriverProfileExtendedProfileDTO, nullable: true })
|
||||
extendedProfile: DriverProfileExtendedProfileDTO | null;
|
||||
extendedProfile!: DriverProfileExtendedProfileDTO | null;
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
import type {
|
||||
GetProfileOverviewResult,
|
||||
} from '@core/racing/application/use-cases/GetProfileOverviewUseCase';
|
||||
import type { GetDriverProfileOutputDTO, DriverProfileExtendedProfileDTO } from '../dtos/GetDriverProfileOutputDTO';
|
||||
import type { GetDriverProfileOutputDTO } from '../dtos/GetDriverProfileOutputDTO';
|
||||
import type { DriverProfileExtendedProfileDTO } from '../dtos/DriverProfileExtendedProfileDTO';
|
||||
|
||||
export class DriverProfilePresenter
|
||||
{
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest';
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
import { DriverStatsPresenter } from './DriverStatsPresenter';
|
||||
import type { GetTotalDriversResult } from '../../../../../core/racing/application/use-cases/GetTotalDriversUseCase';
|
||||
import type { GetTotalDriversResult } from '@core/racing/application/use-cases/GetTotalDriversUseCase';
|
||||
|
||||
describe('DriverStatsPresenter', () => {
|
||||
let presenter: DriverStatsPresenter;
|
||||
@@ -16,31 +15,13 @@ describe('DriverStatsPresenter', () => {
|
||||
totalDrivers: 42,
|
||||
};
|
||||
|
||||
const result = Result.ok<GetTotalDriversResult, never>(output);
|
||||
presenter.present(output);
|
||||
|
||||
presenter.present(result);
|
||||
|
||||
const response = presenter.responseModel;
|
||||
const response = presenter.getResponseModel();
|
||||
|
||||
expect(response).toEqual({
|
||||
totalDrivers: 42,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('reset', () => {
|
||||
it('should reset the result', () => {
|
||||
const output: GetTotalDriversResult = {
|
||||
totalDrivers: 10,
|
||||
};
|
||||
|
||||
const result = Result.ok<GetTotalDriversResult, never>(output);
|
||||
|
||||
presenter.present(result);
|
||||
expect(presenter.responseModel).toBeDefined();
|
||||
|
||||
presenter.reset();
|
||||
expect(() => presenter.responseModel).toThrow('Presenter not presented');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -2,6 +2,8 @@ import { GetDriversLeaderboardResult } from '@core/racing/application/use-cases/
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
import { beforeEach, describe, expect, it } from 'vitest';
|
||||
import { DriversLeaderboardPresenter } from './DriversLeaderboardPresenter';
|
||||
import type { Driver } from '@core/racing/domain/entities/Driver';
|
||||
import type { SkillLevel } from '@core/racing/domain/services/SkillLevelService';
|
||||
|
||||
// TODO fix eslint issues
|
||||
|
||||
@@ -19,11 +21,11 @@ describe('DriversLeaderboardPresenter', () => {
|
||||
{
|
||||
driver: {
|
||||
id: 'driver-1',
|
||||
name: 'Driver One' as unknown,
|
||||
country: 'US' as unknown,
|
||||
} as unknown,
|
||||
name: 'Driver One',
|
||||
country: 'US',
|
||||
} as unknown as Driver,
|
||||
rating: 2500,
|
||||
skillLevel: 'advanced' as unknown,
|
||||
skillLevel: 'advanced' as unknown as SkillLevel,
|
||||
racesCompleted: 50,
|
||||
wins: 10,
|
||||
podiums: 20,
|
||||
@@ -34,11 +36,11 @@ describe('DriversLeaderboardPresenter', () => {
|
||||
{
|
||||
driver: {
|
||||
id: 'driver-2',
|
||||
name: 'Driver Two' as unknown,
|
||||
country: 'DE' as unknown,
|
||||
} as unknown,
|
||||
name: 'Driver Two',
|
||||
country: 'DE',
|
||||
} as unknown as Driver,
|
||||
rating: 2400,
|
||||
skillLevel: 'intermediate' as unknown,
|
||||
skillLevel: 'intermediate' as unknown as SkillLevel,
|
||||
racesCompleted: 40,
|
||||
wins: 5,
|
||||
podiums: 15,
|
||||
@@ -56,9 +58,10 @@ describe('DriversLeaderboardPresenter', () => {
|
||||
|
||||
presenter.present(result);
|
||||
|
||||
const output = presenter.getResponseModel();
|
||||
|
||||
expect(result.drivers).toHaveLength(2);
|
||||
expect(result.drivers[0]).toEqual({
|
||||
expect(output.drivers).toHaveLength(2);
|
||||
expect(output.drivers[0]).toEqual({
|
||||
id: 'driver-1',
|
||||
name: 'Driver One',
|
||||
rating: 2500,
|
||||
@@ -71,7 +74,7 @@ describe('DriversLeaderboardPresenter', () => {
|
||||
rank: 1,
|
||||
avatarUrl: 'https://example.com/avatar1.png',
|
||||
});
|
||||
expect(result.drivers[1]).toEqual({
|
||||
expect(output.drivers[1]).toEqual({
|
||||
id: 'driver-2',
|
||||
name: 'Driver Two',
|
||||
rating: 2400,
|
||||
@@ -84,126 +87,10 @@ describe('DriversLeaderboardPresenter', () => {
|
||||
rank: 2,
|
||||
avatarUrl: 'https://example.com/avatar2.png',
|
||||
});
|
||||
expect(result.totalRaces).toBe(90);
|
||||
expect(result.totalWins).toBe(15);
|
||||
expect(result.activeCount).toBe(2);
|
||||
expect(output.totalRaces).toBe(90);
|
||||
expect(output.totalWins).toBe(15);
|
||||
expect(output.activeCount).toBe(2);
|
||||
});
|
||||
|
||||
it('should sort drivers by rating descending', () => {
|
||||
const dto: DriversLeaderboardResultDTO = {
|
||||
drivers: [
|
||||
{
|
||||
id: 'driver-1',
|
||||
name: 'Driver One',
|
||||
country: 'US',
|
||||
iracingId: '12345',
|
||||
joinedAt: new Date(),
|
||||
},
|
||||
{
|
||||
id: 'driver-2',
|
||||
name: 'Driver Two',
|
||||
country: 'DE',
|
||||
iracingId: '67890',
|
||||
joinedAt: new Date(),
|
||||
},
|
||||
],
|
||||
rankings: [
|
||||
{ driverId: 'driver-1', rating: 2400, overallRank: 2 },
|
||||
{ driverId: 'driver-2', rating: 2500, overallRank: 1 },
|
||||
],
|
||||
stats: {},
|
||||
avatarUrls: {},
|
||||
};
|
||||
|
||||
presenter.present(dto);
|
||||
|
||||
const result = presenter.viewModel;
|
||||
|
||||
expect(result.drivers[0].id).toBe('driver-2'); // Higher rating first
|
||||
expect(result.drivers[1].id).toBe('driver-1');
|
||||
});
|
||||
|
||||
it('should handle missing stats gracefully', () => {
|
||||
const dto: DriversLeaderboardResultDTO = {
|
||||
drivers: [
|
||||
{
|
||||
id: 'driver-1',
|
||||
name: 'Driver One',
|
||||
country: 'US',
|
||||
iracingId: '12345',
|
||||
joinedAt: new Date(),
|
||||
},
|
||||
],
|
||||
rankings: [
|
||||
{ driverId: 'driver-1', rating: 2500, overallRank: 1 },
|
||||
],
|
||||
stats: {}, // No stats
|
||||
avatarUrls: {},
|
||||
};
|
||||
|
||||
presenter.present(dto);
|
||||
|
||||
const result = presenter.viewModel;
|
||||
|
||||
expect(result.drivers[0].racesCompleted).toBe(0);
|
||||
expect(result.drivers[0].wins).toBe(0);
|
||||
expect(result.drivers[0].podiums).toBe(0);
|
||||
expect(result.drivers[0].isActive).toBe(false);
|
||||
});
|
||||
|
||||
it('should derive skill level from rating bands', () => {
|
||||
const dto: DriversLeaderboardResultDTO = {
|
||||
drivers: [
|
||||
{ id: 'd1', name: 'Beginner', country: 'US', iracingId: '1', joinedAt: new Date() },
|
||||
{ id: 'd2', name: 'Intermediate', country: 'US', iracingId: '2', joinedAt: new Date() },
|
||||
{ id: 'd3', name: 'Advanced', country: 'US', iracingId: '3', joinedAt: new Date() },
|
||||
{ id: 'd4', name: 'Pro', country: 'US', iracingId: '4', joinedAt: new Date() },
|
||||
],
|
||||
rankings: [
|
||||
{ driverId: 'd1', rating: 1700, overallRank: 4 },
|
||||
{ driverId: 'd2', rating: 2000, overallRank: 3 },
|
||||
{ driverId: 'd3', rating: 2600, overallRank: 2 },
|
||||
{ driverId: 'd4', rating: 3100, overallRank: 1 },
|
||||
],
|
||||
stats: {
|
||||
d1: { racesCompleted: 5, wins: 0, podiums: 0 },
|
||||
d2: { racesCompleted: 5, wins: 0, podiums: 0 },
|
||||
d3: { racesCompleted: 5, wins: 0, podiums: 0 },
|
||||
d4: { racesCompleted: 5, wins: 0, podiums: 0 },
|
||||
},
|
||||
avatarUrls: {
|
||||
d1: 'avatar-1',
|
||||
d2: 'avatar-2',
|
||||
d3: 'avatar-3',
|
||||
d4: 'avatar-4',
|
||||
},
|
||||
};
|
||||
|
||||
presenter.present(dto);
|
||||
const result = presenter.viewModel;
|
||||
|
||||
const levels = result.drivers
|
||||
.sort((a, b) => a.rating - b.rating)
|
||||
.map(d => d.skillLevel);
|
||||
|
||||
expect(levels).toEqual(['beginner', 'intermediate', 'advanced', 'pro']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('reset', () => {
|
||||
it('should reset the result', () => {
|
||||
const dto: DriversLeaderboardResultDTO = {
|
||||
drivers: [],
|
||||
rankings: [],
|
||||
stats: {},
|
||||
avatarUrls: {},
|
||||
};
|
||||
|
||||
presenter.present(dto);
|
||||
expect(presenter.viewModel).toBeDefined();
|
||||
|
||||
presenter.reset();
|
||||
expect(() => presenter.viewModel).toThrow('Presenter not presented');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -8,6 +8,8 @@ import type { ISeasonRepository } from '@core/racing/domain/repositories/ISeason
|
||||
import type { ILeagueRepository } from '@core/racing/domain/repositories/ILeagueRepository';
|
||||
import type { ILeagueMembershipRepository } from '@core/racing/domain/repositories/ILeagueMembershipRepository';
|
||||
import type { IRaceRepository } from '@core/racing/domain/repositories/IRaceRepository';
|
||||
import type { IProtestRepository } from '@core/racing/domain/repositories/IProtestRepository';
|
||||
import type { IDriverRepository } from '@core/racing/domain/repositories/IDriverRepository';
|
||||
|
||||
// Import concrete in-memory implementations
|
||||
import { InMemoryLeagueRepository } from '@adapters/racing/persistence/inmemory/InMemoryLeagueRepository';
|
||||
@@ -52,6 +54,7 @@ import { WithdrawFromLeagueWalletUseCase } from '@core/racing/application/use-ca
|
||||
|
||||
// Import presenters
|
||||
import { AllLeaguesWithCapacityPresenter } from './presenters/AllLeaguesWithCapacityPresenter';
|
||||
import { GetLeagueProtestsPresenter } from './presenters/GetLeagueProtestsPresenter';
|
||||
|
||||
// Define injection tokens
|
||||
export const LEAGUE_REPOSITORY_TOKEN = 'ILeagueRepository';
|
||||
@@ -145,6 +148,10 @@ export const LeagueProviders: Provider[] = [
|
||||
provide: 'AllLeaguesWithCapacityPresenter',
|
||||
useClass: AllLeaguesWithCapacityPresenter,
|
||||
},
|
||||
{
|
||||
provide: 'GetLeagueProtestsPresenter',
|
||||
useClass: GetLeagueProtestsPresenter,
|
||||
},
|
||||
// Use cases
|
||||
{
|
||||
provide: GetAllLeaguesWithCapacityUseCase,
|
||||
@@ -167,7 +174,17 @@ export const LeagueProviders: Provider[] = [
|
||||
RemoveLeagueMemberUseCase,
|
||||
UpdateLeagueMemberRoleUseCase,
|
||||
GetLeagueOwnerSummaryUseCase,
|
||||
GetLeagueProtestsUseCase,
|
||||
{
|
||||
provide: GetLeagueProtestsUseCase,
|
||||
useFactory: (
|
||||
raceRepo: IRaceRepository,
|
||||
protestRepo: IProtestRepository,
|
||||
driverRepo: IDriverRepository,
|
||||
leagueRepo: ILeagueRepository,
|
||||
presenter: GetLeagueProtestsPresenter,
|
||||
) => new GetLeagueProtestsUseCase(raceRepo, protestRepo, driverRepo, leagueRepo, presenter),
|
||||
inject: [RACE_REPOSITORY_TOKEN, PROTEST_REPOSITORY_TOKEN, DRIVER_REPOSITORY_TOKEN, LEAGUE_REPOSITORY_TOKEN, 'GetLeagueProtestsPresenter'],
|
||||
},
|
||||
GetLeagueSeasonsUseCase,
|
||||
GetLeagueMembershipsUseCase,
|
||||
GetLeagueScheduleUseCase,
|
||||
|
||||
@@ -257,9 +257,7 @@ export class LeagueService {
|
||||
if (result.isErr()) {
|
||||
throw new Error(result.unwrapErr().code);
|
||||
}
|
||||
const presenter = new GetLeagueProtestsPresenter();
|
||||
presenter.present(result.unwrap());
|
||||
return presenter.getViewModel()!;
|
||||
return (this.getLeagueProtestsUseCase.outputPort as GetLeagueProtestsPresenter).getResponseModel()!;
|
||||
}
|
||||
|
||||
async getLeagueSeasons(query: GetLeagueSeasonsQueryDTO): Promise<LeagueSeasonSummaryDTO[]> {
|
||||
@@ -268,9 +266,7 @@ export class LeagueService {
|
||||
if (result.isErr()) {
|
||||
throw new Error(result.unwrapErr().code);
|
||||
}
|
||||
const presenter = new GetLeagueSeasonsPresenter();
|
||||
presenter.present(result.unwrap());
|
||||
return presenter.getViewModel()!;
|
||||
return (this.getLeagueSeasonsUseCase.output as GetLeagueSeasonsPresenter).getResponseModel()!;
|
||||
}
|
||||
|
||||
async getLeagueMemberships(leagueId: string): Promise<LeagueMembershipsDTO> {
|
||||
|
||||
@@ -8,9 +8,9 @@ export class AllLeaguesWithCapacityAndScoringDTO {
|
||||
@IsArray()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => LeagueSummaryDTO)
|
||||
leagues: LeagueSummaryDTO[];
|
||||
leagues!: LeagueSummaryDTO[];
|
||||
|
||||
@ApiProperty()
|
||||
@IsNumber()
|
||||
totalCount: number;
|
||||
totalCount!: number;
|
||||
}
|
||||
@@ -1,5 +1,17 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
export interface LeagueSettings {
|
||||
maxDrivers: number;
|
||||
sessionDuration?: number;
|
||||
visibility?: string;
|
||||
}
|
||||
|
||||
export interface SocialLinks {
|
||||
discordUrl?: string;
|
||||
youtubeUrl?: string;
|
||||
websiteUrl?: string;
|
||||
}
|
||||
|
||||
export class LeagueWithCapacityDTO {
|
||||
@ApiProperty()
|
||||
id!: string;
|
||||
@@ -14,21 +26,13 @@ export class LeagueWithCapacityDTO {
|
||||
ownerId!: string;
|
||||
|
||||
@ApiProperty()
|
||||
settings!: {
|
||||
maxDrivers: number;
|
||||
sessionDuration?: number;
|
||||
visibility?: string;
|
||||
};
|
||||
settings!: LeagueSettings;
|
||||
|
||||
@ApiProperty()
|
||||
createdAt!: string;
|
||||
|
||||
@ApiProperty({ nullable: true })
|
||||
socialLinks?: {
|
||||
discordUrl?: string;
|
||||
youtubeUrl?: string;
|
||||
websiteUrl?: string;
|
||||
};
|
||||
socialLinks?: SocialLinks;
|
||||
|
||||
@ApiProperty()
|
||||
usedSlots!: number;
|
||||
|
||||
@@ -4,9 +4,9 @@ import { IsString } from 'class-validator';
|
||||
export class ApproveJoinRequestInputDTO {
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
requestId: string;
|
||||
requestId!: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
leagueId: string;
|
||||
leagueId!: string;
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import { IsString, IsBoolean } from 'class-validator';
|
||||
export class ApproveJoinRequestOutputDTO {
|
||||
@ApiProperty()
|
||||
@IsBoolean()
|
||||
success: boolean;
|
||||
success!: boolean;
|
||||
|
||||
@ApiProperty({ required: false })
|
||||
@IsString()
|
||||
|
||||
@@ -4,17 +4,17 @@ import { IsString, IsEnum } from 'class-validator';
|
||||
export class CreateLeagueInputDTO {
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
name: string;
|
||||
name!: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
description: string;
|
||||
description!: string;
|
||||
|
||||
@ApiProperty({ enum: ['public', 'private'] })
|
||||
@IsEnum(['public', 'private'])
|
||||
visibility: 'public' | 'private';
|
||||
visibility!: 'public' | 'private';
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
ownerId: string;
|
||||
ownerId!: string;
|
||||
}
|
||||
@@ -4,9 +4,9 @@ import { IsString, IsBoolean } from 'class-validator';
|
||||
export class CreateLeagueOutputDTO {
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
leagueId: string;
|
||||
leagueId!: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsBoolean()
|
||||
success: boolean;
|
||||
success!: boolean;
|
||||
}
|
||||
@@ -8,5 +8,5 @@ export class GetLeagueAdminConfigOutputDTO {
|
||||
@IsOptional()
|
||||
@ValidateNested()
|
||||
@Type(() => LeagueConfigFormModelDTO)
|
||||
form: LeagueConfigFormModelDTO | null;
|
||||
form!: LeagueConfigFormModelDTO | null;
|
||||
}
|
||||
@@ -4,5 +4,5 @@ import { IsString } from 'class-validator';
|
||||
export class GetLeagueAdminConfigQueryDTO {
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
leagueId: string;
|
||||
leagueId!: string;
|
||||
}
|
||||
@@ -4,9 +4,9 @@ import { IsString } from 'class-validator';
|
||||
export class GetLeagueAdminPermissionsInputDTO {
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
leagueId: string;
|
||||
leagueId!: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
performerDriverId: string;
|
||||
performerDriverId!: string;
|
||||
}
|
||||
@@ -4,5 +4,5 @@ import { IsString } from 'class-validator';
|
||||
export class GetLeagueJoinRequestsQueryDTO {
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
leagueId: string;
|
||||
leagueId!: string;
|
||||
}
|
||||
@@ -4,9 +4,9 @@ import { IsString } from 'class-validator';
|
||||
export class GetLeagueOwnerSummaryQueryDTO {
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
ownerId: string;
|
||||
ownerId!: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
leagueId: string;
|
||||
leagueId!: string;
|
||||
}
|
||||
@@ -4,5 +4,5 @@ import { IsString } from 'class-validator';
|
||||
export class GetLeagueProtestsQueryDTO {
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
leagueId: string;
|
||||
leagueId!: string;
|
||||
}
|
||||
@@ -3,5 +3,5 @@ import { RaceDTO } from '../../race/dtos/RaceDTO';
|
||||
|
||||
export class GetLeagueRacesOutputDTO {
|
||||
@ApiProperty({ type: [RaceDTO] })
|
||||
races: RaceDTO[];
|
||||
races!: RaceDTO[];
|
||||
}
|
||||
@@ -4,5 +4,5 @@ import { IsString } from 'class-validator';
|
||||
export class GetLeagueSeasonsQueryDTO {
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
leagueId: string;
|
||||
leagueId!: string;
|
||||
}
|
||||
@@ -2,28 +2,28 @@ import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
export class WalletTransactionDTO {
|
||||
@ApiProperty()
|
||||
id: string;
|
||||
id!: string;
|
||||
|
||||
@ApiProperty({ enum: ['sponsorship', 'membership', 'withdrawal', 'prize'] })
|
||||
type: 'sponsorship' | 'membership' | 'withdrawal' | 'prize';
|
||||
type!: 'sponsorship' | 'membership' | 'withdrawal' | 'prize';
|
||||
|
||||
@ApiProperty()
|
||||
description: string;
|
||||
description!: string;
|
||||
|
||||
@ApiProperty()
|
||||
amount: number;
|
||||
amount!: number;
|
||||
|
||||
@ApiProperty()
|
||||
fee: number;
|
||||
fee!: number;
|
||||
|
||||
@ApiProperty()
|
||||
netAmount: number;
|
||||
netAmount!: number;
|
||||
|
||||
@ApiProperty()
|
||||
date: string;
|
||||
date!: string;
|
||||
|
||||
@ApiProperty({ enum: ['completed', 'pending', 'failed'] })
|
||||
status: 'completed' | 'pending' | 'failed';
|
||||
status!: 'completed' | 'pending' | 'failed';
|
||||
|
||||
@ApiProperty({ required: false })
|
||||
reference?: string;
|
||||
@@ -31,29 +31,29 @@ export class WalletTransactionDTO {
|
||||
|
||||
export class GetLeagueWalletOutputDTO {
|
||||
@ApiProperty()
|
||||
balance: number;
|
||||
balance!: number;
|
||||
|
||||
@ApiProperty()
|
||||
currency: string;
|
||||
currency!: string;
|
||||
|
||||
@ApiProperty()
|
||||
totalRevenue: number;
|
||||
totalRevenue!: number;
|
||||
|
||||
@ApiProperty()
|
||||
totalFees: number;
|
||||
totalFees!: number;
|
||||
|
||||
@ApiProperty()
|
||||
totalWithdrawals: number;
|
||||
totalWithdrawals!: number;
|
||||
|
||||
@ApiProperty()
|
||||
pendingPayouts: number;
|
||||
pendingPayouts!: number;
|
||||
|
||||
@ApiProperty()
|
||||
canWithdraw: boolean;
|
||||
canWithdraw!: boolean;
|
||||
|
||||
@ApiProperty({ required: false })
|
||||
withdrawalBlockReason?: string;
|
||||
|
||||
@ApiProperty({ type: [WalletTransactionDTO] })
|
||||
transactions: WalletTransactionDTO[];
|
||||
transactions!: WalletTransactionDTO[];
|
||||
}
|
||||
@@ -3,5 +3,5 @@ import { SponsorshipDetailDTO } from '../../sponsor/dtos/SponsorshipDetailDTO';
|
||||
|
||||
export class GetSeasonSponsorshipsOutputDTO {
|
||||
@ApiProperty({ type: [SponsorshipDetailDTO] })
|
||||
sponsorships: SponsorshipDetailDTO[];
|
||||
sponsorships!: SponsorshipDetailDTO[];
|
||||
}
|
||||
@@ -8,5 +8,5 @@ export class LeagueAdminConfigDTO {
|
||||
@IsOptional()
|
||||
@ValidateNested()
|
||||
@Type(() => LeagueConfigFormModelDTO)
|
||||
form: LeagueConfigFormModelDTO | null;
|
||||
form!: LeagueConfigFormModelDTO | null;
|
||||
}
|
||||
@@ -12,27 +12,27 @@ export class LeagueAdminDTO {
|
||||
@IsArray()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => LeagueJoinRequestDTO)
|
||||
joinRequests: LeagueJoinRequestDTO[];
|
||||
joinRequests!: LeagueJoinRequestDTO[];
|
||||
|
||||
@ApiProperty({ type: () => LeagueOwnerSummaryDTO, nullable: true })
|
||||
@IsOptional()
|
||||
@ValidateNested()
|
||||
@Type(() => LeagueOwnerSummaryDTO)
|
||||
ownerSummary: LeagueOwnerSummaryDTO | null;
|
||||
ownerSummary!: LeagueOwnerSummaryDTO | null;
|
||||
|
||||
@ApiProperty({ type: () => LeagueAdminConfigDTO })
|
||||
@ValidateNested()
|
||||
@Type(() => LeagueAdminConfigDTO)
|
||||
config: LeagueAdminConfigDTO;
|
||||
config!: LeagueAdminConfigDTO;
|
||||
|
||||
@ApiProperty({ type: () => LeagueAdminProtestsDTO })
|
||||
@ValidateNested()
|
||||
@Type(() => LeagueAdminProtestsDTO)
|
||||
protests: LeagueAdminProtestsDTO;
|
||||
protests!: LeagueAdminProtestsDTO;
|
||||
|
||||
@ApiProperty({ type: [LeagueSeasonSummaryDTO] })
|
||||
@IsArray()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => LeagueSeasonSummaryDTO)
|
||||
seasons: LeagueSeasonSummaryDTO[];
|
||||
seasons!: LeagueSeasonSummaryDTO[];
|
||||
}
|
||||
@@ -4,9 +4,9 @@ import { IsBoolean } from 'class-validator';
|
||||
export class LeagueAdminPermissionsDTO {
|
||||
@ApiProperty()
|
||||
@IsBoolean()
|
||||
canRemoveMember: boolean;
|
||||
canRemoveMember!: boolean;
|
||||
|
||||
@ApiProperty()
|
||||
@IsBoolean()
|
||||
canUpdateRoles: boolean;
|
||||
canUpdateRoles!: boolean;
|
||||
}
|
||||
@@ -1,24 +1,24 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IsArray, ValidateNested } from 'class-validator';
|
||||
import { Type } from 'class-transformer';
|
||||
import { DriverDto } from '../../driver/dto/DriverDto';
|
||||
import { RaceDto } from '../../race/dto/RaceDto';
|
||||
import { DriverDTO } from '../../driver/dtos/DriverDTO';
|
||||
import { RaceDTO } from '../../race/dtos/RaceDTO';
|
||||
import { ProtestDTO } from './ProtestDTO';
|
||||
|
||||
export class LeagueAdminProtestsDTO {
|
||||
@ApiProperty({ type: [ProtestDTO] })
|
||||
@ApiProperty({ type: [ProtestDTO] })
|
||||
@IsArray()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => ProtestDTO)
|
||||
protests: ProtestDTO[];
|
||||
protests!: ProtestDTO[];
|
||||
|
||||
@ApiProperty({ type: () => RaceDto })
|
||||
@ApiProperty({ type: () => RaceDTO })
|
||||
@ValidateNested()
|
||||
@Type(() => RaceDto)
|
||||
racesById: { [raceId: string]: RaceDto };
|
||||
@Type(() => RaceDTO)
|
||||
racesById!: { [raceId: string]: RaceDTO };
|
||||
|
||||
@ApiProperty({ type: () => DriverDto })
|
||||
@ApiProperty({ type: () => DriverDTO })
|
||||
@ValidateNested()
|
||||
@Type(() => DriverDto)
|
||||
driversById: { [driverId: string]: DriverDto };
|
||||
@Type(() => DriverDTO)
|
||||
driversById!: { [driverId: string]: DriverDTO };
|
||||
}
|
||||
@@ -4,13 +4,13 @@ import { IsString, IsEnum } from 'class-validator';
|
||||
export class LeagueConfigFormModelBasicsDTO {
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
name: string;
|
||||
name!: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
description: string;
|
||||
description!: string;
|
||||
|
||||
@ApiProperty({ enum: ['public', 'private'] })
|
||||
@IsEnum(['public', 'private'])
|
||||
visibility: 'public' | 'private';
|
||||
visibility!: 'public' | 'private';
|
||||
}
|
||||
@@ -11,39 +11,39 @@ import { LeagueConfigFormModelTimingsDTO } from './LeagueConfigFormModelTimingsD
|
||||
export class LeagueConfigFormModelDTO {
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
leagueId: string;
|
||||
leagueId!: string;
|
||||
|
||||
@ApiProperty({ type: LeagueConfigFormModelBasicsDTO })
|
||||
@ValidateNested()
|
||||
@Type(() => LeagueConfigFormModelBasicsDTO)
|
||||
basics: LeagueConfigFormModelBasicsDTO;
|
||||
basics!: LeagueConfigFormModelBasicsDTO;
|
||||
|
||||
@ApiProperty({ type: LeagueConfigFormModelStructureDTO })
|
||||
@ValidateNested()
|
||||
@Type(() => LeagueConfigFormModelStructureDTO)
|
||||
structure: LeagueConfigFormModelStructureDTO;
|
||||
structure!: LeagueConfigFormModelStructureDTO;
|
||||
|
||||
@ApiProperty({ type: [Object] })
|
||||
@IsArray()
|
||||
championships: Object[];
|
||||
championships!: Object[];
|
||||
|
||||
@ApiProperty({ type: LeagueConfigFormModelScoringDTO })
|
||||
@ValidateNested()
|
||||
@Type(() => LeagueConfigFormModelScoringDTO)
|
||||
scoring: LeagueConfigFormModelScoringDTO;
|
||||
scoring!: LeagueConfigFormModelScoringDTO;
|
||||
|
||||
@ApiProperty({ type: LeagueConfigFormModelDropPolicyDTO })
|
||||
@ValidateNested()
|
||||
@Type(() => LeagueConfigFormModelDropPolicyDTO)
|
||||
dropPolicy: LeagueConfigFormModelDropPolicyDTO;
|
||||
dropPolicy!: LeagueConfigFormModelDropPolicyDTO;
|
||||
|
||||
@ApiProperty({ type: LeagueConfigFormModelTimingsDTO })
|
||||
@ValidateNested()
|
||||
@Type(() => LeagueConfigFormModelTimingsDTO)
|
||||
timings: LeagueConfigFormModelTimingsDTO;
|
||||
timings!: LeagueConfigFormModelTimingsDTO;
|
||||
|
||||
@ApiProperty({ type: LeagueConfigFormModelStewardingDTO })
|
||||
@ValidateNested()
|
||||
@Type(() => LeagueConfigFormModelStewardingDTO)
|
||||
stewarding: LeagueConfigFormModelStewardingDTO;
|
||||
stewarding!: LeagueConfigFormModelStewardingDTO;
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import { IsNumber, IsOptional, IsEnum } from 'class-validator';
|
||||
export class LeagueConfigFormModelDropPolicyDTO {
|
||||
@ApiProperty({ enum: ['none', 'worst_n'] })
|
||||
@IsEnum(['none', 'worst_n'])
|
||||
strategy: 'none' | 'worst_n';
|
||||
strategy!: 'none' | 'worst_n';
|
||||
|
||||
@ApiProperty({ required: false })
|
||||
@IsOptional()
|
||||
|
||||
@@ -4,9 +4,9 @@ import { IsString, IsNumber } from 'class-validator';
|
||||
export class LeagueConfigFormModelScoringDTO {
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
type: string;
|
||||
type!: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsNumber()
|
||||
points: number;
|
||||
points!: number;
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import { IsNumber, IsBoolean, IsOptional, IsEnum } from 'class-validator';
|
||||
export class LeagueConfigFormModelStewardingDTO {
|
||||
@ApiProperty({ enum: ['single_steward', 'committee_vote'] })
|
||||
@IsEnum(['single_steward', 'committee_vote'])
|
||||
decisionMode: 'single_steward' | 'committee_vote';
|
||||
decisionMode!: 'single_steward' | 'committee_vote';
|
||||
|
||||
@ApiProperty({ required: false })
|
||||
@IsOptional()
|
||||
@@ -13,29 +13,29 @@ export class LeagueConfigFormModelStewardingDTO {
|
||||
|
||||
@ApiProperty()
|
||||
@IsBoolean()
|
||||
requireDefense: boolean;
|
||||
requireDefense!: boolean;
|
||||
|
||||
@ApiProperty()
|
||||
@IsNumber()
|
||||
defenseTimeLimit: number;
|
||||
defenseTimeLimit!: number;
|
||||
|
||||
@ApiProperty()
|
||||
@IsNumber()
|
||||
voteTimeLimit: number;
|
||||
voteTimeLimit!: number;
|
||||
|
||||
@ApiProperty()
|
||||
@IsNumber()
|
||||
protestDeadlineHours: number;
|
||||
protestDeadlineHours!: number;
|
||||
|
||||
@ApiProperty()
|
||||
@IsNumber()
|
||||
stewardingClosesHours: number;
|
||||
stewardingClosesHours!: number;
|
||||
|
||||
@ApiProperty()
|
||||
@IsBoolean()
|
||||
notifyAccusedOnProtest: boolean;
|
||||
notifyAccusedOnProtest!: boolean;
|
||||
|
||||
@ApiProperty()
|
||||
@IsBoolean()
|
||||
notifyOnVoteRequired: boolean;
|
||||
notifyOnVoteRequired!: boolean;
|
||||
}
|
||||
@@ -5,5 +5,5 @@ export class LeagueConfigFormModelStructureDTO {
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
@IsEnum(['solo', 'team'])
|
||||
mode: 'solo' | 'team';
|
||||
mode!: 'solo' | 'team';
|
||||
}
|
||||
@@ -4,13 +4,13 @@ import { IsString, IsNumber } from 'class-validator';
|
||||
export class LeagueConfigFormModelTimingsDTO {
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
raceDayOfWeek: string;
|
||||
raceDayOfWeek!: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsNumber()
|
||||
raceTimeHour: number;
|
||||
raceTimeHour!: number;
|
||||
|
||||
@ApiProperty()
|
||||
@IsNumber()
|
||||
raceTimeMinute: number;
|
||||
raceTimeMinute!: number;
|
||||
}
|
||||
@@ -2,23 +2,28 @@ import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IsString, IsDate, IsOptional } from 'class-validator';
|
||||
import { Type } from 'class-transformer';
|
||||
|
||||
export interface DriverInfo {
|
||||
id: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export class LeagueJoinRequestDTO {
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
id: string;
|
||||
id!: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
leagueId: string;
|
||||
leagueId!: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
driverId: string;
|
||||
driverId!: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsDate()
|
||||
@Type(() => Date)
|
||||
requestedAt: Date;
|
||||
requestedAt!: Date;
|
||||
|
||||
@ApiProperty({ required: false })
|
||||
@IsOptional()
|
||||
@@ -30,8 +35,5 @@ export class LeagueJoinRequestDTO {
|
||||
type: () => Object,
|
||||
})
|
||||
@IsOptional()
|
||||
driver?: {
|
||||
id: string;
|
||||
name: string;
|
||||
};
|
||||
driver?: DriverInfo;
|
||||
}
|
||||
@@ -1,24 +1,24 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IsString, IsDate, IsEnum, ValidateNested } from 'class-validator';
|
||||
import { Type } from 'class-transformer';
|
||||
import { DriverDto } from '../../driver/dto/DriverDto';
|
||||
import { DriverDTO } from '../../driver/dtos/DriverDTO';
|
||||
|
||||
export class LeagueMemberDTO {
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
driverId: string;
|
||||
driverId!: string;
|
||||
|
||||
@ApiProperty({ type: () => DriverDto })
|
||||
@ApiProperty({ type: () => DriverDTO })
|
||||
@ValidateNested()
|
||||
@Type(() => DriverDto)
|
||||
driver: DriverDto;
|
||||
@Type(() => DriverDTO)
|
||||
driver!: DriverDTO;
|
||||
|
||||
@ApiProperty({ enum: ['owner', 'manager', 'member'] })
|
||||
@IsEnum(['owner', 'manager', 'member'])
|
||||
role: 'owner' | 'manager' | 'member';
|
||||
role!: 'owner' | 'manager' | 'member';
|
||||
|
||||
@ApiProperty()
|
||||
@IsDate()
|
||||
@Type(() => Date)
|
||||
joinedAt: Date;
|
||||
joinedAt!: Date;
|
||||
}
|
||||
@@ -4,25 +4,25 @@ import { IsString, IsEnum } from 'class-validator';
|
||||
export class LeagueMembershipDTO {
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
id: string;
|
||||
id!: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
leagueId: string;
|
||||
leagueId!: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
driverId: string;
|
||||
driverId!: string;
|
||||
|
||||
@ApiProperty({ enum: ['owner', 'admin', 'steward', 'member'] })
|
||||
@IsEnum(['owner', 'admin', 'steward', 'member'])
|
||||
role: 'owner' | 'admin' | 'steward' | 'member';
|
||||
role!: 'owner' | 'admin' | 'steward' | 'member';
|
||||
|
||||
@ApiProperty({ enum: ['active', 'inactive', 'pending'] })
|
||||
@IsEnum(['active', 'inactive', 'pending'])
|
||||
status: 'active' | 'inactive' | 'pending';
|
||||
status!: 'active' | 'inactive' | 'pending';
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
joinedAt: string;
|
||||
joinedAt!: string;
|
||||
}
|
||||
@@ -8,5 +8,5 @@ export class LeagueMembershipsDTO {
|
||||
@IsArray()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => LeagueMemberDTO)
|
||||
members: LeagueMemberDTO[];
|
||||
members!: LeagueMemberDTO[];
|
||||
}
|
||||
@@ -1,21 +1,21 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IsNumber, IsOptional, ValidateNested } from 'class-validator';
|
||||
import { Type } from 'class-transformer';
|
||||
import { DriverDto } from '../../driver/dto/DriverDto';
|
||||
import { DriverDTO } from '../../driver/dtos/DriverDTO';
|
||||
|
||||
export class LeagueOwnerSummaryDTO {
|
||||
@ApiProperty({ type: () => DriverDto })
|
||||
@ApiProperty({ type: () => DriverDTO })
|
||||
@ValidateNested()
|
||||
@Type(() => DriverDto)
|
||||
driver: DriverDto;
|
||||
@Type(() => DriverDTO)
|
||||
driver!: DriverDTO;
|
||||
|
||||
@ApiProperty({ nullable: true })
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
rating: number | null;
|
||||
rating!: number | null;
|
||||
|
||||
@ApiProperty({ nullable: true })
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
rank: number | null;
|
||||
rank!: number | null;
|
||||
}
|
||||
@@ -4,5 +4,5 @@ import { IsEnum } from 'class-validator';
|
||||
export class LeagueRoleDTO {
|
||||
@ApiProperty({ enum: ['owner', 'admin', 'steward', 'member'] })
|
||||
@IsEnum(['owner', 'admin', 'steward', 'member'])
|
||||
value: 'owner' | 'admin' | 'steward' | 'member';
|
||||
value!: 'owner' | 'admin' | 'steward' | 'member';
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IsArray, ValidateNested } from 'class-validator';
|
||||
import { Type } from 'class-transformer';
|
||||
import { RaceDto } from '../../race/dto/RaceDto';
|
||||
import { RaceDTO } from '../../race/dtos/RaceDTO';
|
||||
|
||||
export class LeagueScheduleDTO {
|
||||
@ApiProperty({ type: [RaceDto] })
|
||||
@ApiProperty({ type: [RaceDTO] })
|
||||
@IsArray()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => RaceDto)
|
||||
races: RaceDto[];
|
||||
@Type(() => RaceDTO)
|
||||
races!: RaceDTO[];
|
||||
}
|
||||
@@ -4,29 +4,29 @@ import { IsString, IsEnum } from 'class-validator';
|
||||
export class LeagueScoringPresetDTO {
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
id: string;
|
||||
id!: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
name: string;
|
||||
name!: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
description: string;
|
||||
description!: string;
|
||||
|
||||
@ApiProperty({ enum: ['driver', 'team', 'nations', 'trophy'] })
|
||||
@IsEnum(['driver', 'team', 'nations', 'trophy'])
|
||||
primaryChampionshipType: 'driver' | 'team' | 'nations' | 'trophy';
|
||||
primaryChampionshipType!: 'driver' | 'team' | 'nations' | 'trophy';
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
sessionSummary: string;
|
||||
sessionSummary!: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
bonusSummary: string;
|
||||
bonusSummary!: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
dropPolicySummary: string;
|
||||
dropPolicySummary!: string;
|
||||
}
|
||||
@@ -5,15 +5,15 @@ import { Type } from 'class-transformer';
|
||||
export class LeagueSeasonSummaryDTO {
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
seasonId: string;
|
||||
seasonId!: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
name: string;
|
||||
name!: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
status: string;
|
||||
status!: string;
|
||||
|
||||
@ApiProperty({ required: false })
|
||||
@IsOptional()
|
||||
@@ -29,9 +29,9 @@ export class LeagueSeasonSummaryDTO {
|
||||
|
||||
@ApiProperty()
|
||||
@IsBoolean()
|
||||
isPrimary: boolean;
|
||||
isPrimary!: boolean;
|
||||
|
||||
@ApiProperty()
|
||||
@IsBoolean()
|
||||
isParallelActive: boolean;
|
||||
isParallelActive!: boolean;
|
||||
}
|
||||
@@ -1,23 +1,23 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IsString, IsNumber, ValidateNested } from 'class-validator';
|
||||
import { Type } from 'class-transformer';
|
||||
import { DriverDto } from '../../driver/dto/DriverDto';
|
||||
import { DriverDTO } from '../../driver/dtos/DriverDTO';
|
||||
|
||||
export class LeagueStandingDTO {
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
driverId: string;
|
||||
driverId!: string;
|
||||
|
||||
@ApiProperty({ type: () => DriverDto })
|
||||
@ApiProperty({ type: () => DriverDTO })
|
||||
@ValidateNested()
|
||||
@Type(() => DriverDto)
|
||||
driver: DriverDto;
|
||||
@Type(() => DriverDTO)
|
||||
driver!: DriverDTO;
|
||||
|
||||
@ApiProperty()
|
||||
@IsNumber()
|
||||
points: number;
|
||||
points!: number;
|
||||
|
||||
@ApiProperty()
|
||||
@IsNumber()
|
||||
rank: number;
|
||||
rank!: number;
|
||||
}
|
||||
@@ -8,5 +8,5 @@ export class LeagueStandingsDTO {
|
||||
@IsArray()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => LeagueStandingDTO)
|
||||
standings: LeagueStandingDTO[];
|
||||
standings!: LeagueStandingDTO[];
|
||||
}
|
||||
@@ -4,13 +4,13 @@ import { IsNumber } from 'class-validator';
|
||||
export class LeagueStatsDTO {
|
||||
@ApiProperty()
|
||||
@IsNumber()
|
||||
totalMembers: number;
|
||||
totalMembers!: number;
|
||||
|
||||
@ApiProperty()
|
||||
@IsNumber()
|
||||
totalRaces: number;
|
||||
totalRaces!: number;
|
||||
|
||||
@ApiProperty()
|
||||
@IsNumber()
|
||||
averageRating: number;
|
||||
averageRating!: number;
|
||||
}
|
||||
@@ -4,11 +4,11 @@ import { IsString, IsNumber, IsBoolean, IsOptional } from 'class-validator';
|
||||
export class LeagueSummaryDTO {
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
id: string;
|
||||
id!: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
name: string;
|
||||
name!: string;
|
||||
|
||||
@ApiProperty({ nullable: true })
|
||||
@IsOptional()
|
||||
@@ -27,19 +27,19 @@ export class LeagueSummaryDTO {
|
||||
|
||||
@ApiProperty()
|
||||
@IsNumber()
|
||||
memberCount: number;
|
||||
memberCount!: number;
|
||||
|
||||
@ApiProperty()
|
||||
@IsNumber()
|
||||
maxMembers: number;
|
||||
maxMembers!: number;
|
||||
|
||||
@ApiProperty()
|
||||
@IsBoolean()
|
||||
isPublic: boolean;
|
||||
isPublic!: boolean;
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
ownerId: string;
|
||||
ownerId!: string;
|
||||
|
||||
@ApiProperty({ nullable: true })
|
||||
@IsOptional()
|
||||
|
||||
@@ -6,11 +6,11 @@ import { LeagueSettingsDTO } from './LeagueSettingsDTO';
|
||||
export class LeagueWithCapacityDTO {
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
id: string;
|
||||
id!: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
name: string;
|
||||
name!: string;
|
||||
|
||||
// ... other properties of LeagueWithCapacityDTO
|
||||
@ApiProperty({ nullable: true })
|
||||
@@ -20,20 +20,20 @@ export class LeagueWithCapacityDTO {
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
ownerId: string;
|
||||
ownerId!: string;
|
||||
|
||||
@ApiProperty({ type: () => LeagueSettingsDTO })
|
||||
@ValidateNested()
|
||||
@Type(() => LeagueSettingsDTO)
|
||||
settings: LeagueSettingsDTO;
|
||||
settings!: LeagueSettingsDTO;
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
createdAt: string;
|
||||
createdAt!: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsNumber()
|
||||
usedSlots: number;
|
||||
usedSlots!: number;
|
||||
|
||||
@ApiProperty({ type: () => Object, nullable: true }) // Using Object for generic social links
|
||||
@IsOptional()
|
||||
|
||||
@@ -4,5 +4,5 @@ import { IsEnum } from 'class-validator';
|
||||
export class MembershipRoleDTO {
|
||||
@ApiProperty({ enum: ['owner', 'admin', 'steward', 'member'] })
|
||||
@IsEnum(['owner', 'admin', 'steward', 'member'])
|
||||
value: 'owner' | 'admin' | 'steward' | 'member';
|
||||
value!: 'owner' | 'admin' | 'steward' | 'member';
|
||||
}
|
||||
@@ -4,5 +4,5 @@ import { IsEnum } from 'class-validator';
|
||||
export class MembershipStatusDTO {
|
||||
@ApiProperty({ enum: ['active', 'inactive', 'pending'] })
|
||||
@IsEnum(['active', 'inactive', 'pending'])
|
||||
value: 'active' | 'inactive' | 'pending';
|
||||
value!: 'active' | 'inactive' | 'pending';
|
||||
}
|
||||
@@ -13,34 +13,34 @@ import { Type } from 'class-transformer';
|
||||
export class ProtestDTO {
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
id: string;
|
||||
id!: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
leagueId: string;
|
||||
leagueId!: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
raceId: string;
|
||||
raceId!: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
protestingDriverId: string;
|
||||
protestingDriverId!: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
accusedDriverId: string;
|
||||
accusedDriverId!: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsDate()
|
||||
@Type(() => Date)
|
||||
submittedAt: Date;
|
||||
submittedAt!: Date;
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
description: string;
|
||||
description!: string;
|
||||
|
||||
@ApiProperty({ enum: ['pending', 'accepted', 'rejected'] })
|
||||
@IsEnum(['pending', 'accepted', 'rejected'])
|
||||
status: 'pending' | 'accepted' | 'rejected';
|
||||
status!: 'pending' | 'accepted' | 'rejected';
|
||||
}
|
||||
@@ -4,9 +4,9 @@ import { IsString } from 'class-validator';
|
||||
export class RejectJoinRequestInputDTO {
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
requestId: string;
|
||||
requestId!: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
leagueId: string;
|
||||
leagueId!: string;
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import { IsString, IsBoolean } from 'class-validator';
|
||||
export class RejectJoinRequestOutputDTO {
|
||||
@ApiProperty()
|
||||
@IsBoolean()
|
||||
success: boolean;
|
||||
success!: boolean;
|
||||
|
||||
@ApiProperty({ required: false })
|
||||
@IsString()
|
||||
|
||||
@@ -4,13 +4,13 @@ import { IsString } from 'class-validator';
|
||||
export class RemoveLeagueMemberInputDTO {
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
leagueId: string;
|
||||
leagueId!: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
performerDriverId: string;
|
||||
performerDriverId!: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
targetDriverId: string;
|
||||
targetDriverId!: string;
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import { IsBoolean, IsOptional, IsString } from 'class-validator';
|
||||
export class RemoveLeagueMemberOutputDTO {
|
||||
@ApiProperty()
|
||||
@IsBoolean()
|
||||
success: boolean;
|
||||
success!: boolean;
|
||||
|
||||
@ApiProperty({ required: false })
|
||||
@IsOptional()
|
||||
|
||||
@@ -5,15 +5,15 @@ import { Type } from 'class-transformer';
|
||||
export class SeasonDTO {
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
seasonId: string;
|
||||
seasonId!: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
name: string;
|
||||
name!: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
leagueId: string;
|
||||
leagueId!: string;
|
||||
|
||||
@ApiProperty({ required: false })
|
||||
@IsOptional()
|
||||
@@ -29,11 +29,11 @@ export class SeasonDTO {
|
||||
|
||||
@ApiProperty({ enum: ['planned', 'active', 'completed'] })
|
||||
@IsEnum(['planned', 'active', 'completed'])
|
||||
status: 'planned' | 'active' | 'completed';
|
||||
status!: 'planned' | 'active' | 'completed';
|
||||
|
||||
@ApiProperty()
|
||||
@IsBoolean()
|
||||
isPrimary: boolean;
|
||||
isPrimary!: boolean;
|
||||
|
||||
@ApiProperty({ required: false })
|
||||
@IsOptional()
|
||||
|
||||
@@ -4,5 +4,5 @@ import { IsNumber } from 'class-validator';
|
||||
export class TotalLeaguesDTO {
|
||||
@ApiProperty()
|
||||
@IsNumber()
|
||||
totalLeagues: number;
|
||||
totalLeagues!: number;
|
||||
}
|
||||
@@ -4,17 +4,17 @@ import { IsString, IsEnum } from 'class-validator';
|
||||
export class UpdateLeagueMemberRoleInputDTO {
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
leagueId: string;
|
||||
leagueId!: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
performerDriverId: string;
|
||||
performerDriverId!: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
targetDriverId: string;
|
||||
targetDriverId!: string;
|
||||
|
||||
@ApiProperty({ enum: ['owner', 'manager', 'member'] })
|
||||
@IsEnum(['owner', 'manager', 'member'])
|
||||
newRole: 'owner' | 'manager' | 'member';
|
||||
newRole!: 'owner' | 'manager' | 'member';
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import { IsBoolean, IsOptional, IsString } from 'class-validator';
|
||||
export class UpdateLeagueMemberRoleOutputDTO {
|
||||
@ApiProperty()
|
||||
@IsBoolean()
|
||||
success: boolean;
|
||||
success!: boolean;
|
||||
|
||||
@ApiProperty({ required: false })
|
||||
@IsOptional()
|
||||
|
||||
@@ -2,14 +2,14 @@ import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
export class WithdrawFromLeagueWalletInputDTO {
|
||||
@ApiProperty()
|
||||
amount: number;
|
||||
amount!: number;
|
||||
|
||||
@ApiProperty()
|
||||
currency: string;
|
||||
currency!: string;
|
||||
|
||||
@ApiProperty()
|
||||
seasonId: string;
|
||||
seasonId!: string;
|
||||
|
||||
@ApiProperty()
|
||||
destinationAccount: string;
|
||||
destinationAccount!: string;
|
||||
}
|
||||
@@ -2,7 +2,7 @@ import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
export class WithdrawFromLeagueWalletOutputDTO {
|
||||
@ApiProperty()
|
||||
success: boolean;
|
||||
success!: boolean;
|
||||
|
||||
@ApiProperty({ required: false })
|
||||
message?: string;
|
||||
|
||||
@@ -4,5 +4,5 @@ import { IsEnum } from 'class-validator';
|
||||
export class WizardStepDTO {
|
||||
@ApiProperty({ enum: [1, 2, 3, 4, 5, 6, 7] })
|
||||
@IsEnum([1, 2, 3, 4, 5, 6, 7])
|
||||
value: 1 | 2 | 3 | 4 | 5 | 6 | 7;
|
||||
value!: 1 | 2 | 3 | 4 | 5 | 6 | 7;
|
||||
}
|
||||
@@ -1,30 +1,26 @@
|
||||
import { GetLeagueOwnerSummaryOutputPort } from '@core/racing/application/ports/output/GetLeagueOwnerSummaryOutputPort';
|
||||
import type { UseCaseOutputPort } from '@core/shared/application';
|
||||
import type { GetLeagueOwnerSummaryResult } from '@core/racing/application/use-cases/GetLeagueOwnerSummaryUseCase';
|
||||
import { LeagueOwnerSummaryDTO } from '../dtos/LeagueOwnerSummaryDTO';
|
||||
|
||||
export class GetLeagueOwnerSummaryPresenter {
|
||||
export class GetLeagueOwnerSummaryPresenter implements UseCaseOutputPort<GetLeagueOwnerSummaryResult> {
|
||||
private result: LeagueOwnerSummaryDTO | null = null;
|
||||
|
||||
reset() {
|
||||
this.result = null;
|
||||
}
|
||||
|
||||
present(output: GetLeagueOwnerSummaryOutputPort) {
|
||||
if (!output.summary) {
|
||||
this.result = null;
|
||||
return;
|
||||
}
|
||||
|
||||
present(output: GetLeagueOwnerSummaryResult) {
|
||||
this.result = {
|
||||
driver: {
|
||||
id: output.summary.driver.id,
|
||||
iracingId: output.summary.driver.iracingId,
|
||||
name: output.summary.driver.name,
|
||||
country: output.summary.driver.country,
|
||||
bio: output.summary.driver.bio,
|
||||
joinedAt: output.summary.driver.joinedAt,
|
||||
id: output.owner.id,
|
||||
iracingId: output.owner.iracingId.toString(),
|
||||
name: output.owner.name.toString(),
|
||||
country: output.owner.country.toString(),
|
||||
joinedAt: output.owner.joinedAt.toDate().toISOString(),
|
||||
...(output.owner.bio ? { bio: output.owner.bio.toString() } : {}),
|
||||
},
|
||||
rating: output.summary.rating,
|
||||
rank: output.summary.rank,
|
||||
rating: output.rating,
|
||||
rank: output.rank,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { GetLeagueProtestsOutputPort, type ProtestOutputPort } from '@core/racing/application/ports/output/GetLeagueProtestsOutputPort';
|
||||
import { Presenter } from '@core/shared/presentation';
|
||||
import type { GetLeagueProtestsResult } from '@core/racing/application/use-cases/GetLeagueProtestsUseCase';
|
||||
import { LeagueAdminProtestsDTO } from '../dtos/LeagueAdminProtestsDTO';
|
||||
import { ProtestDTO } from '../dtos/ProtestDTO';
|
||||
import { RaceDTO } from '../../race/dtos/RaceDTO';
|
||||
import { DriverDTO } from '../../driver/dtos/DriverDTO';
|
||||
|
||||
function mapProtestStatus(status: ProtestOutputPort['status']): ProtestDTO['status'] {
|
||||
function mapProtestStatus(status: string): ProtestDTO['status'] {
|
||||
switch (status) {
|
||||
case 'pending':
|
||||
case 'awaiting_defense':
|
||||
@@ -20,53 +21,63 @@ function mapProtestStatus(status: ProtestOutputPort['status']): ProtestDTO['stat
|
||||
}
|
||||
}
|
||||
|
||||
export class GetLeagueProtestsPresenter {
|
||||
export class GetLeagueProtestsPresenter implements Presenter<GetLeagueProtestsResult, LeagueAdminProtestsDTO> {
|
||||
private result: LeagueAdminProtestsDTO | null = null;
|
||||
|
||||
reset() {
|
||||
this.result = null;
|
||||
}
|
||||
|
||||
present(output: GetLeagueProtestsOutputPort, leagueName?: string) {
|
||||
const protests: ProtestDTO[] = output.protests.map((protest) => {
|
||||
const race = output.racesById[protest.raceId];
|
||||
present(input: GetLeagueProtestsResult) {
|
||||
const protests: ProtestDTO[] = input.protests.map((protestWithEntities) => {
|
||||
const { protest, race } = protestWithEntities;
|
||||
|
||||
return {
|
||||
id: protest.id,
|
||||
leagueId: race?.leagueId || '',
|
||||
raceId: protest.raceId,
|
||||
protestingDriverId: protest.protestingDriverId,
|
||||
accusedDriverId: protest.accusedDriverId,
|
||||
id: protest.id.toString(),
|
||||
leagueId: race?.leagueId.toString() || '',
|
||||
raceId: protest.raceId.toString(),
|
||||
protestingDriverId: protest.protestingDriverId.toString(),
|
||||
accusedDriverId: protest.accusedDriverId.toString(),
|
||||
submittedAt: new Date(protest.filedAt),
|
||||
description: protest.incident.description,
|
||||
status: mapProtestStatus(protest.status),
|
||||
description: protest.incident.description.toString(),
|
||||
status: mapProtestStatus(protest.status.toString()),
|
||||
};
|
||||
});
|
||||
|
||||
const racesById: { [raceId: string]: RaceDTO } = {};
|
||||
for (const raceId in output.racesById) {
|
||||
const race = output.racesById[raceId];
|
||||
for (const protestWithEntities of input.protests) {
|
||||
const { race } = protestWithEntities;
|
||||
if (race) {
|
||||
racesById[raceId] = {
|
||||
id: race.id,
|
||||
name: race.track,
|
||||
racesById[race.id.toString()] = {
|
||||
id: race.id.toString(),
|
||||
name: race.track.toString(),
|
||||
date: race.scheduledAt.toISOString(),
|
||||
leagueName,
|
||||
leagueName: input.league.name.toString(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
const driversById: { [driverId: string]: DriverDTO } = {};
|
||||
for (const driverId in output.driversById) {
|
||||
const driver = output.driversById[driverId];
|
||||
if (driver) {
|
||||
driversById[driverId] = {
|
||||
id: driver.id,
|
||||
iracingId: driver.iracingId,
|
||||
name: driver.name,
|
||||
country: driver.country,
|
||||
bio: driver.bio,
|
||||
joinedAt: driver.joinedAt,
|
||||
for (const protestWithEntities of input.protests) {
|
||||
const { protestingDriver, accusedDriver } = protestWithEntities;
|
||||
if (protestingDriver) {
|
||||
driversById[protestingDriver.id.toString()] = {
|
||||
id: protestingDriver.id.toString(),
|
||||
iracingId: protestingDriver.iracingId.toString(),
|
||||
name: protestingDriver.name.toString(),
|
||||
country: protestingDriver.country.toString(),
|
||||
bio: protestingDriver.bio?.toString(),
|
||||
joinedAt: protestingDriver.joinedAt.toDate().toISOString(),
|
||||
};
|
||||
}
|
||||
if (accusedDriver) {
|
||||
driversById[accusedDriver.id.toString()] = {
|
||||
id: accusedDriver.id.toString(),
|
||||
iracingId: accusedDriver.iracingId.toString(),
|
||||
name: accusedDriver.name.toString(),
|
||||
country: accusedDriver.country.toString(),
|
||||
bio: accusedDriver.bio?.toString(),
|
||||
joinedAt: accusedDriver.joinedAt.toISOString(),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -78,7 +89,7 @@ export class GetLeagueProtestsPresenter {
|
||||
};
|
||||
}
|
||||
|
||||
getViewModel(): LeagueAdminProtestsDTO | null {
|
||||
getResponseModel(): LeagueAdminProtestsDTO | null {
|
||||
return this.result;
|
||||
}
|
||||
}
|
||||
@@ -1,26 +1,27 @@
|
||||
import { GetLeagueSeasonsOutputPort } from '@core/racing/application/ports/output/GetLeagueSeasonsOutputPort';
|
||||
import { Presenter } from '@core/shared/presentation';
|
||||
import type { GetLeagueSeasonsResult } from '@core/racing/application/use-cases/GetLeagueSeasonsUseCase';
|
||||
import { LeagueSeasonSummaryDTO } from '../dtos/LeagueSeasonSummaryDTO';
|
||||
|
||||
export class GetLeagueSeasonsPresenter {
|
||||
export class GetLeagueSeasonsPresenter implements Presenter<GetLeagueSeasonsResult, LeagueSeasonSummaryDTO[]> {
|
||||
private result: LeagueSeasonSummaryDTO[] | null = null;
|
||||
|
||||
reset() {
|
||||
this.result = null;
|
||||
}
|
||||
|
||||
present(output: GetLeagueSeasonsOutputPort) {
|
||||
this.result = output.seasons.map(season => ({
|
||||
seasonId: season.seasonId,
|
||||
name: season.name,
|
||||
status: season.status,
|
||||
startDate: season.startDate,
|
||||
endDate: season.endDate,
|
||||
isPrimary: season.isPrimary,
|
||||
isParallelActive: season.isParallelActive,
|
||||
present(input: GetLeagueSeasonsResult) {
|
||||
this.result = input.seasons.map(seasonSummary => ({
|
||||
seasonId: seasonSummary.season.id.toString(),
|
||||
name: seasonSummary.season.name.toString(),
|
||||
status: seasonSummary.season.status.toString(),
|
||||
startDate: seasonSummary.season.startDate.toISOString(),
|
||||
endDate: seasonSummary.season.endDate?.toISOString(),
|
||||
isPrimary: seasonSummary.isPrimary,
|
||||
isParallelActive: seasonSummary.isParallelActive,
|
||||
}));
|
||||
}
|
||||
|
||||
getViewModel(): LeagueSeasonSummaryDTO[] | null {
|
||||
getResponseModel(): LeagueSeasonSummaryDTO[] | null {
|
||||
return this.result;
|
||||
}
|
||||
}
|
||||
@@ -217,7 +217,7 @@ describe('MediaController', () => {
|
||||
describe('updateAvatar', () => {
|
||||
it('should update avatar and return result', async () => {
|
||||
const driverId = 'driver-123';
|
||||
const input = { mediaUrl: 'https://example.com/new-avatar.png' } as UpdateAvatarOutputDTO;
|
||||
const input: UpdateAvatarInputDTO = { avatarUrl: 'https://example.com/new-avatar.png' };
|
||||
const dto: UpdateAvatarOutputDTO = {
|
||||
success: true,
|
||||
};
|
||||
@@ -225,9 +225,9 @@ describe('MediaController', () => {
|
||||
|
||||
const res = createMockResponse();
|
||||
|
||||
await controller.updateAvatar(driverId, input as any, res);
|
||||
await controller.updateAvatar(driverId, input, res);
|
||||
|
||||
expect(service.updateAvatar).toHaveBeenCalledWith(driverId, input as any);
|
||||
expect(service.updateAvatar).toHaveBeenCalledWith(driverId, input);
|
||||
expect(res.status).toHaveBeenCalledWith(200);
|
||||
expect(res.json).toHaveBeenCalledWith(dto);
|
||||
});
|
||||
|
||||
@@ -92,7 +92,7 @@ export class MediaService {
|
||||
}
|
||||
|
||||
async uploadMedia(
|
||||
input: UploadMediaInput & { file: Express.Multer.File } & { userId?: string; metadata?: Record<string, any> },
|
||||
input: UploadMediaInput & { file: Express.Multer.File } & { userId?: string; metadata?: Record<string, unknown> },
|
||||
): Promise<UploadMediaOutputDTO> {
|
||||
this.logger.debug('[MediaService] Uploading media.');
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ export class UpdateAvatarPresenter implements UseCaseOutputPort<UpdateAvatarResu
|
||||
this.model = null;
|
||||
}
|
||||
|
||||
present(result: UpdateAvatarResult): void {
|
||||
present(_result: UpdateAvatarResult): void {
|
||||
this.model = {
|
||||
success: true,
|
||||
};
|
||||
|
||||
@@ -44,17 +44,11 @@ import type {
|
||||
UpdateMemberPaymentInput,
|
||||
UpdateMemberPaymentOutput,
|
||||
GetPrizesQuery,
|
||||
GetPrizesOutput,
|
||||
CreatePrizeInput,
|
||||
CreatePrizeOutput,
|
||||
AwardPrizeInput,
|
||||
AwardPrizeOutput,
|
||||
DeletePrizeInput,
|
||||
DeletePrizeOutput,
|
||||
GetWalletQuery,
|
||||
GetWalletOutput,
|
||||
ProcessWalletTransactionInput,
|
||||
ProcessWalletTransactionOutput,
|
||||
} from './dtos/PaymentsDto';
|
||||
|
||||
// Injection tokens
|
||||
|
||||
@@ -28,7 +28,7 @@ export class GetPaymentsPresenter implements UseCaseOutputPort<GetPaymentsResult
|
||||
};
|
||||
}
|
||||
|
||||
getResponseModel(): GetPaymentsOutput {
|
||||
get responseModel(): GetPaymentsOutput {
|
||||
if (!this.responseModel) throw new Error('Presenter not presented');
|
||||
return this.responseModel;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,11 @@ import { ReviewProtestPresenter, type ReviewProtestResponseDTO } from './present
|
||||
// Tokens
|
||||
import { LOGGER_TOKEN } from './ProtestsProviders';
|
||||
|
||||
import type { IProtestRepository } from '@core/racing/domain/repositories/IProtestRepository';
|
||||
import type { IRaceRepository } from '@core/racing/domain/repositories/IRaceRepository';
|
||||
import type { ILeagueMembershipRepository } from '@core/racing/domain/repositories/ILeagueMembershipRepository';
|
||||
import { PROTEST_REPOSITORY_TOKEN, RACE_REPOSITORY_TOKEN, LEAGUE_MEMBERSHIP_REPOSITORY_TOKEN } from './ProtestsProviders';
|
||||
|
||||
@Injectable()
|
||||
export class ProtestsService {
|
||||
constructor(
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { UseCaseOutputPort } from '@core/shared/application';
|
||||
import type { ReviewProtestResult } from '@core/racing/application/use-cases/ReviewProtestUseCase';
|
||||
import type { ReviewProtestResult, ReviewProtestApplicationError } from '@core/racing/application/use-cases/ReviewProtestUseCase';
|
||||
|
||||
export interface ReviewProtestResponseDTO {
|
||||
success: boolean;
|
||||
@@ -25,6 +25,14 @@ export class ReviewProtestPresenter implements UseCaseOutputPort<ReviewProtestRe
|
||||
};
|
||||
}
|
||||
|
||||
presentError(error: ReviewProtestApplicationError): void {
|
||||
this.model = {
|
||||
success: false,
|
||||
errorCode: error.code,
|
||||
message: error.details.message,
|
||||
};
|
||||
}
|
||||
|
||||
getResponseModel(): ReviewProtestResponseDTO | null {
|
||||
return this.model;
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ export class RaceController {
|
||||
@Query('driverId') driverId: string,
|
||||
): Promise<RaceDetailDTO> {
|
||||
const presenter = await this.raceService.getRaceDetail({ raceId, driverId });
|
||||
return presenter.viewModel;
|
||||
return await presenter.viewModel;
|
||||
}
|
||||
|
||||
@Get(':raceId/results')
|
||||
@@ -74,7 +74,7 @@ export class RaceController {
|
||||
@ApiResponse({ status: 200, description: 'Race results detail', type: RaceResultsDetailDTO })
|
||||
async getRaceResultsDetail(@Param('raceId') raceId: string): Promise<RaceResultsDetailDTO> {
|
||||
const presenter = await this.raceService.getRaceResultsDetail(raceId);
|
||||
return presenter.viewModel;
|
||||
return await presenter.viewModel;
|
||||
}
|
||||
|
||||
@Get(':raceId/sof')
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import type { RaceDetailOutputPort } from '@core/racing/application/ports/output/RaceDetailOutputPort';
|
||||
import type { RacesPageOutputPort } from '@core/racing/application/ports/output/RacesPageOutputPort';
|
||||
import type { RaceResultsDetailOutputPort } from '@core/racing/application/ports/output/RaceResultsDetailOutputPort';
|
||||
import type { RaceWithSOFOutputPort } from '@core/racing/application/ports/output/RaceWithSOFOutputPort';
|
||||
@@ -130,14 +129,15 @@ export class RaceService {
|
||||
async getRaceDetail(params: GetRaceDetailParamsDTO): Promise<RaceDetailPresenter> {
|
||||
this.logger.debug('[RaceService] Fetching race detail:', params);
|
||||
|
||||
const presenter = new RaceDetailPresenter(this.driverRatingProvider, this.imageService, params);
|
||||
this.getRaceDetailUseCase.setOutput(presenter);
|
||||
|
||||
const result = await this.getRaceDetailUseCase.execute(params);
|
||||
|
||||
if (result.isErr()) {
|
||||
throw new Error('Failed to get race detail');
|
||||
}
|
||||
|
||||
const presenter = new RaceDetailPresenter(this.driverRatingProvider, this.imageService);
|
||||
await presenter.present(result.value as RaceDetailOutputPort, params);
|
||||
return presenter;
|
||||
}
|
||||
|
||||
|
||||
@@ -47,4 +47,8 @@ export class AllRacesPageDataPresenter {
|
||||
|
||||
return this.model;
|
||||
}
|
||||
|
||||
get viewModel(): AllRacesPageDataResponseModel {
|
||||
return this.responseModel;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
import { GetAllRacesPresenter } from './GetAllRacesPresenter';
|
||||
import type { GetAllRacesResult } from '@core/racing/application/use-cases/GetAllRacesUseCase';
|
||||
|
||||
@@ -6,7 +5,7 @@ describe('GetAllRacesPresenter', () => {
|
||||
it('should map races and distinct leagues into the DTO', async () => {
|
||||
const presenter = new GetAllRacesPresenter();
|
||||
|
||||
const output: GetAllRacesOutputPort = {
|
||||
const output: GetAllRacesResult = {
|
||||
races: [
|
||||
{
|
||||
id: 'race-1',
|
||||
@@ -14,9 +13,8 @@ describe('GetAllRacesPresenter', () => {
|
||||
track: 'Track A',
|
||||
car: 'Car A',
|
||||
status: 'scheduled',
|
||||
scheduledAt: '2025-01-01T10:00:00.000Z',
|
||||
scheduledAt: new Date('2025-01-01T10:00:00.000Z'),
|
||||
strengthOfField: 1500,
|
||||
leagueName: 'League One',
|
||||
},
|
||||
{
|
||||
id: 'race-2',
|
||||
@@ -24,9 +22,8 @@ describe('GetAllRacesPresenter', () => {
|
||||
track: 'Track B',
|
||||
car: 'Car B',
|
||||
status: 'completed',
|
||||
scheduledAt: '2025-01-02T10:00:00.000Z',
|
||||
strengthOfField: null,
|
||||
leagueName: 'League One',
|
||||
scheduledAt: new Date('2025-01-02T10:00:00.000Z'),
|
||||
strengthOfField: undefined,
|
||||
},
|
||||
{
|
||||
id: 'race-3',
|
||||
@@ -34,16 +31,22 @@ describe('GetAllRacesPresenter', () => {
|
||||
track: 'Track C',
|
||||
car: 'Car C',
|
||||
status: 'running',
|
||||
scheduledAt: '2025-01-03T10:00:00.000Z',
|
||||
scheduledAt: new Date('2025-01-03T10:00:00.000Z'),
|
||||
strengthOfField: 1800,
|
||||
leagueName: 'League Two',
|
||||
},
|
||||
],
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
] as any,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
leagues: [
|
||||
{ id: 'league-1', name: 'League One' },
|
||||
{ id: 'league-2', name: 'League Two' },
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
] as any,
|
||||
totalCount: 3,
|
||||
};
|
||||
|
||||
await presenter.present(output);
|
||||
const viewModel = presenter.getViewModel();
|
||||
const viewModel = presenter.getResponseModel();
|
||||
|
||||
expect(viewModel).not.toBeNull();
|
||||
expect(viewModel!.races).toHaveLength(3);
|
||||
@@ -61,13 +64,16 @@ describe('GetAllRacesPresenter', () => {
|
||||
it('should handle empty races by returning empty leagues', async () => {
|
||||
const presenter = new GetAllRacesPresenter();
|
||||
|
||||
const output: GetAllRacesOutputPort = {
|
||||
races: [],
|
||||
const output: GetAllRacesResult = {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
races: [] as any,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
leagues: [] as any,
|
||||
totalCount: 0,
|
||||
};
|
||||
|
||||
await presenter.present(output);
|
||||
const viewModel = presenter.getViewModel();
|
||||
const viewModel = presenter.getResponseModel();
|
||||
|
||||
expect(viewModel).not.toBeNull();
|
||||
expect(viewModel!.races).toHaveLength(0);
|
||||
|
||||
@@ -53,4 +53,8 @@ export class GetAllRacesPresenter implements UseCaseOutputPort<GetAllRacesResult
|
||||
|
||||
return this.model;
|
||||
}
|
||||
|
||||
get viewModel(): GetAllRacesResponseModel {
|
||||
return this.responseModel;
|
||||
}
|
||||
}
|
||||
@@ -44,4 +44,8 @@ export class GetTotalRacesPresenter {
|
||||
|
||||
return this.model;
|
||||
}
|
||||
|
||||
get viewModel(): GetTotalRacesResponseModel {
|
||||
return this.responseModel;
|
||||
}
|
||||
}
|
||||
@@ -50,4 +50,8 @@ export class ImportRaceResultsApiPresenter {
|
||||
|
||||
return this.model;
|
||||
}
|
||||
|
||||
get viewModel(): ImportRaceResultsApiResponseModel {
|
||||
return this.responseModel;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,5 @@
|
||||
import type { Result } from '@core/shared/application/Result';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
import type {
|
||||
GetRaceDetailResult,
|
||||
GetRaceDetailErrorCode,
|
||||
} from '@core/racing/application/use-cases/GetRaceDetailUseCase';
|
||||
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
|
||||
import type { GetRaceDetailResult } from '@core/racing/application/use-cases/GetRaceDetailUseCase';
|
||||
import type { DriverRatingProvider } from '@core/racing/application/ports/DriverRatingProvider';
|
||||
import type { IImageServicePort } from '@core/racing/application/ports/IImageServicePort';
|
||||
import type { GetRaceDetailParamsDTO } from '../dtos/GetRaceDetailParamsDTO';
|
||||
@@ -16,47 +12,26 @@ import type { RaceDetailUserResultDTO } from '../dtos/RaceDetailUserResultDTO';
|
||||
|
||||
export type GetRaceDetailResponseModel = RaceDetailDTO;
|
||||
|
||||
export type GetRaceDetailApplicationError = ApplicationErrorCode<
|
||||
GetRaceDetailErrorCode,
|
||||
{ message: string }
|
||||
>;
|
||||
|
||||
export class RaceDetailPresenter {
|
||||
private model: GetRaceDetailResponseModel | null = null;
|
||||
export class RaceDetailPresenter implements UseCaseOutputPort<GetRaceDetailResult> {
|
||||
private result: GetRaceDetailResult | null = null;
|
||||
|
||||
constructor(
|
||||
private readonly driverRatingProvider: DriverRatingProvider,
|
||||
private readonly imageService: IImageServicePort,
|
||||
private readonly params: GetRaceDetailParamsDTO,
|
||||
) {}
|
||||
|
||||
reset(): void {
|
||||
this.model = null;
|
||||
present(result: GetRaceDetailResult): void {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
async present(
|
||||
result: Result<GetRaceDetailResult, GetRaceDetailApplicationError>,
|
||||
params: GetRaceDetailParamsDTO,
|
||||
): Promise<void> {
|
||||
if (result.isErr()) {
|
||||
const error = result.unwrapErr();
|
||||
if (error.code === 'RACE_NOT_FOUND') {
|
||||
this.model = {
|
||||
race: null,
|
||||
league: null,
|
||||
entryList: [],
|
||||
registration: {
|
||||
isUserRegistered: false,
|
||||
canRegister: false,
|
||||
},
|
||||
userResult: null,
|
||||
} as RaceDetailDTO;
|
||||
return;
|
||||
}
|
||||
|
||||
throw new Error(error.details?.message ?? 'Failed to get race detail');
|
||||
async getResponseModel(): Promise<GetRaceDetailResponseModel | null> {
|
||||
if (!this.result) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const output = result.unwrap();
|
||||
const output = this.result;
|
||||
const params = this.params;
|
||||
|
||||
const raceDTO: RaceDetailRaceDTO | null = output.race
|
||||
? {
|
||||
@@ -118,7 +93,7 @@ export class RaceDetailPresenter {
|
||||
}
|
||||
: null;
|
||||
|
||||
this.model = {
|
||||
return {
|
||||
race: raceDTO,
|
||||
league: leagueDTO,
|
||||
entryList: entryListDTO,
|
||||
@@ -127,16 +102,11 @@ export class RaceDetailPresenter {
|
||||
} as RaceDetailDTO;
|
||||
}
|
||||
|
||||
getResponseModel(): GetRaceDetailResponseModel | null {
|
||||
return this.model;
|
||||
}
|
||||
|
||||
get responseModel(): GetRaceDetailResponseModel {
|
||||
if (!this.model) {
|
||||
throw new Error('Presenter not presented');
|
||||
}
|
||||
|
||||
return this.model;
|
||||
get viewModel(): Promise<GetRaceDetailResponseModel> {
|
||||
return this.getResponseModel().then(model => {
|
||||
if (!model) throw new Error('Presenter not presented');
|
||||
return model;
|
||||
});
|
||||
}
|
||||
|
||||
private calculateRatingChange(position: number): number {
|
||||
|
||||
@@ -62,4 +62,8 @@ export class RacePenaltiesPresenter {
|
||||
|
||||
return this.model;
|
||||
}
|
||||
|
||||
get viewModel(): GetRacePenaltiesResponseModel {
|
||||
return this.responseModel;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,4 +63,8 @@ export class RaceProtestsPresenter {
|
||||
|
||||
return this.model;
|
||||
}
|
||||
|
||||
get viewModel(): GetRaceProtestsResponseModel {
|
||||
return this.responseModel;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import type { Result } from '@core/shared/application/Result';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
import type {
|
||||
GetRaceResultsDetailResult,
|
||||
@@ -16,33 +15,20 @@ export type GetRaceResultsDetailApplicationError = ApplicationErrorCode<
|
||||
>;
|
||||
|
||||
export class RaceResultsDetailPresenter {
|
||||
private model: GetRaceResultsDetailResponseModel | null = null;
|
||||
private result: GetRaceResultsDetailResult | null = null;
|
||||
|
||||
constructor(private readonly imageService: IImageServicePort) {}
|
||||
|
||||
reset(): void {
|
||||
this.model = null;
|
||||
present(result: GetRaceResultsDetailResult): void {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
async present(
|
||||
result: Result<GetRaceResultsDetailResult, GetRaceResultsDetailApplicationError>,
|
||||
): Promise<void> {
|
||||
if (result.isErr()) {
|
||||
const error = result.unwrapErr();
|
||||
|
||||
if (error.code === 'RACE_NOT_FOUND') {
|
||||
this.model = {
|
||||
raceId: '',
|
||||
track: '',
|
||||
results: [],
|
||||
} as RaceResultsDetailDTO;
|
||||
return;
|
||||
}
|
||||
|
||||
throw new Error(error.details?.message ?? 'Failed to get race results detail');
|
||||
async getResponseModel(): Promise<GetRaceResultsDetailResponseModel | null> {
|
||||
if (!this.result) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const output = result.unwrap();
|
||||
const output = this.result;
|
||||
|
||||
const driverMap = new Map(output.drivers.map(driver => [driver.id, driver]));
|
||||
|
||||
@@ -70,22 +56,17 @@ export class RaceResultsDetailPresenter {
|
||||
}),
|
||||
);
|
||||
|
||||
this.model = {
|
||||
return {
|
||||
raceId: output.race.id,
|
||||
track: output.race.track,
|
||||
results,
|
||||
} as RaceResultsDetailDTO;
|
||||
}
|
||||
|
||||
getResponseModel(): GetRaceResultsDetailResponseModel | null {
|
||||
return this.model;
|
||||
}
|
||||
|
||||
get responseModel(): GetRaceResultsDetailResponseModel {
|
||||
if (!this.model) {
|
||||
throw new Error('Presenter not presented');
|
||||
}
|
||||
|
||||
return this.model;
|
||||
get viewModel(): Promise<GetRaceResultsDetailResponseModel> {
|
||||
return this.getResponseModel().then(model => {
|
||||
if (!model) throw new Error('Presenter not presented');
|
||||
return model;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,4 +55,8 @@ export class RaceWithSOFPresenter {
|
||||
|
||||
return this.model;
|
||||
}
|
||||
|
||||
get viewModel(): GetRaceWithSOFResponseModel {
|
||||
return this.responseModel;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,4 +59,8 @@ export class RacesPageDataPresenter {
|
||||
|
||||
return this.model;
|
||||
}
|
||||
|
||||
get viewModel(): GetRacesPageDataResponseModel {
|
||||
return this.responseModel;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import { SponsorService } from './SponsorService';
|
||||
import { NotificationService } from '@core/notifications/application/ports/NotificationService';
|
||||
import type { IPaymentRepository } from '@core/payments/domain/repositories/IPaymentRepository';
|
||||
import { IWalletRepository } from '@core/payments/domain/repositories/IWalletRepository';
|
||||
import { IPaymentGateway } from '@core/racing/application/ports/IPaymentGateway';
|
||||
import { IPaymentGateway } from '@core/payments/domain/ports/IPaymentGateway';
|
||||
import { ILeagueMembershipRepository } from '@core/racing/domain/repositories/ILeagueMembershipRepository';
|
||||
import { ILeagueRepository } from '@core/racing/domain/repositories/ILeagueRepository';
|
||||
import { ILeagueWalletRepository } from '@core/racing/domain/repositories/ILeagueWalletRepository';
|
||||
|
||||
@@ -2,15 +2,17 @@ import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { TeamService } from './TeamService';
|
||||
import { GetAllTeamsUseCase } from '@core/racing/application/use-cases/GetAllTeamsUseCase';
|
||||
import { GetDriverTeamUseCase } from '@core/racing/application/use-cases/GetDriverTeamUseCase';
|
||||
import type { Logger } from '@core/shared/application/Logger';
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
import { AllTeamsPresenter } from './presenters/AllTeamsPresenter';
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
import { DriverTeamPresenter } from './presenters/DriverTeamPresenter';
|
||||
import { DriverTeamViewModel } from './dtos/TeamDto';
|
||||
|
||||
describe('TeamService', () => {
|
||||
let service: TeamService;
|
||||
let getAllTeamsUseCase: jest.Mocked<GetAllTeamsUseCase>;
|
||||
let getDriverTeamUseCase: jest.Mocked<GetDriverTeamUseCase>;
|
||||
let logger: jest.Mocked<Logger>;
|
||||
|
||||
beforeEach(async () => {
|
||||
const mockGetAllTeamsUseCase = {
|
||||
@@ -46,7 +48,6 @@ describe('TeamService', () => {
|
||||
service = module.get<TeamService>(TeamService);
|
||||
getAllTeamsUseCase = module.get(GetAllTeamsUseCase);
|
||||
getDriverTeamUseCase = module.get(GetDriverTeamUseCase);
|
||||
logger = module.get('Logger');
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
@@ -56,12 +57,14 @@ describe('TeamService', () => {
|
||||
describe('getAll', () => {
|
||||
it('should call use case and return result', async () => {
|
||||
const mockResult = { isOk: () => true, value: { teams: [], totalCount: 0 } };
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
getAllTeamsUseCase.execute.mockResolvedValue(mockResult as any);
|
||||
|
||||
const mockPresenter = {
|
||||
present: jest.fn(),
|
||||
getViewModel: jest.fn().mockReturnValue({ teams: [], totalCount: 0 }),
|
||||
};
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
(AllTeamsPresenter as any) = jest.fn().mockImplementation(() => mockPresenter);
|
||||
|
||||
const result = await service.getAll();
|
||||
@@ -74,12 +77,14 @@ describe('TeamService', () => {
|
||||
describe('getDriverTeam', () => {
|
||||
it('should call use case and return result', async () => {
|
||||
const mockResult = { isOk: () => true, value: {} };
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
getDriverTeamUseCase.execute.mockResolvedValue(mockResult as any);
|
||||
|
||||
const mockPresenter = {
|
||||
present: jest.fn(),
|
||||
getViewModel: jest.fn().mockReturnValue({} as DriverTeamViewModel),
|
||||
};
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
(DriverTeamPresenter as any) = jest.fn().mockImplementation(() => mockPresenter);
|
||||
|
||||
const result = await service.getDriverTeam('driver1');
|
||||
@@ -90,6 +95,7 @@ describe('TeamService', () => {
|
||||
|
||||
it('should return null on error', async () => {
|
||||
const mockResult = { isErr: () => true, error: {} };
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
getDriverTeamUseCase.execute.mockResolvedValue(mockResult as any);
|
||||
|
||||
const result = await service.getDriverTeam('driver1');
|
||||
|
||||
@@ -12,14 +12,18 @@ import { GetTeamMembershipOutputDTO } from './dtos/GetTeamMembershipOutputDTO';
|
||||
|
||||
// Core imports
|
||||
import type { Logger } from '@core/shared/application/Logger';
|
||||
import type { ITeamRepository } from '@core/racing/domain/repositories/ITeamRepository';
|
||||
import type { ITeamMembershipRepository } from '@core/racing/domain/repositories/ITeamMembershipRepository';
|
||||
import type { IDriverRepository } from '@core/racing/domain/repositories/IDriverRepository';
|
||||
import type { IImageServicePort } from '@core/racing/application/ports/IImageServicePort';
|
||||
|
||||
// Use cases
|
||||
import { GetAllTeamsUseCase } from '@core/racing/application/use-cases/GetAllTeamsUseCase';
|
||||
import { GetTeamDetailsUseCase } from '@core/racing/application/use-cases/GetTeamDetailsUseCase';
|
||||
import { GetTeamMembersUseCase } from '@core/racing/application/use-cases/GetTeamMembersUseCase';
|
||||
import { GetTeamJoinRequestsUseCase } from '@core/racing/application/use-cases/GetTeamJoinRequestsUseCase';
|
||||
import { CreateTeamUseCase } from '@core/racing/application/use-cases/CreateTeamUseCase';
|
||||
import { UpdateTeamUseCase } from '@core/racing/application/use-cases/UpdateTeamUseCase';
|
||||
import { CreateTeamUseCase, CreateTeamInput } from '@core/racing/application/use-cases/CreateTeamUseCase';
|
||||
import { UpdateTeamUseCase, UpdateTeamInput } from '@core/racing/application/use-cases/UpdateTeamUseCase';
|
||||
import { GetDriverTeamUseCase } from '@core/racing/application/use-cases/GetDriverTeamUseCase';
|
||||
import { GetTeamMembershipUseCase } from '@core/racing/application/use-cases/GetTeamMembershipUseCase';
|
||||
|
||||
@@ -34,97 +38,90 @@ import { CreateTeamPresenter } from './presenters/CreateTeamPresenter';
|
||||
import { UpdateTeamPresenter } from './presenters/UpdateTeamPresenter';
|
||||
|
||||
// Tokens
|
||||
import { LOGGER_TOKEN } from './TeamProviders';
|
||||
import { TEAM_REPOSITORY_TOKEN, TEAM_MEMBERSHIP_REPOSITORY_TOKEN, DRIVER_REPOSITORY_TOKEN, IMAGE_SERVICE_TOKEN, LOGGER_TOKEN } from './TeamProviders';
|
||||
|
||||
@Injectable()
|
||||
export class TeamService {
|
||||
constructor(
|
||||
private readonly getAllTeamsUseCase: GetAllTeamsUseCase,
|
||||
private readonly getTeamDetailsUseCase: GetTeamDetailsUseCase,
|
||||
private readonly getTeamMembersUseCase: GetTeamMembersUseCase,
|
||||
private readonly getTeamJoinRequestsUseCase: GetTeamJoinRequestsUseCase,
|
||||
private readonly createTeamUseCase: CreateTeamUseCase,
|
||||
private readonly updateTeamUseCase: UpdateTeamUseCase,
|
||||
private readonly getDriverTeamUseCase: GetDriverTeamUseCase,
|
||||
private readonly getTeamMembershipUseCase: GetTeamMembershipUseCase,
|
||||
@Inject(TEAM_REPOSITORY_TOKEN) private readonly teamRepository: ITeamRepository,
|
||||
@Inject(TEAM_MEMBERSHIP_REPOSITORY_TOKEN) private readonly membershipRepository: ITeamMembershipRepository,
|
||||
@Inject(DRIVER_REPOSITORY_TOKEN) private readonly driverRepository: IDriverRepository,
|
||||
@Inject(IMAGE_SERVICE_TOKEN) private readonly imageService: IImageServicePort,
|
||||
@Inject(LOGGER_TOKEN) private readonly logger: Logger,
|
||||
) {}
|
||||
|
||||
async getAll(): Promise<any> { // TODO: type
|
||||
async getAll(): Promise<GetAllTeamsOutputDTO> {
|
||||
this.logger.debug('[TeamService] Fetching all teams.');
|
||||
|
||||
const result = await this.getAllTeamsUseCase.execute();
|
||||
const presenter = new AllTeamsPresenter();
|
||||
const useCase = new GetAllTeamsUseCase(this.teamRepository, this.membershipRepository, this.logger, presenter);
|
||||
const result = await useCase.execute();
|
||||
if (result.isErr()) {
|
||||
this.logger.error('Error fetching all teams', result.error);
|
||||
await presenter.present({ teams: [], totalCount: 0 });
|
||||
return presenter.responseModel;
|
||||
this.logger.error('Error fetching all teams', result.error?.details?.message || 'Unknown error');
|
||||
return { teams: [], totalCount: 0 };
|
||||
}
|
||||
|
||||
await presenter.present(result.value);
|
||||
return presenter.responseModel;
|
||||
}
|
||||
|
||||
async getDetails(teamId: string, userId?: string): Promise<TeamDetailsPresenter> {
|
||||
async getDetails(teamId: string, userId?: string): Promise<GetTeamDetailsOutputDTO | null> {
|
||||
this.logger.debug(`[TeamService] Fetching team details for teamId: ${teamId}, userId: ${userId}`);
|
||||
|
||||
const presenter = new TeamDetailsPresenter();
|
||||
const result = await this.getTeamDetailsUseCase.execute({ teamId, driverId: userId || '' });
|
||||
const useCase = new GetTeamDetailsUseCase(this.teamRepository, this.membershipRepository, presenter);
|
||||
const result = await useCase.execute({ teamId, driverId: userId || '' });
|
||||
if (result.isErr()) {
|
||||
this.logger.error(`Error fetching team details for teamId: ${teamId}`, result.error);
|
||||
return presenter;
|
||||
this.logger.error(`Error fetching team details for teamId: ${teamId}: ${result.error?.details?.message || 'Unknown error'}`);
|
||||
return null;
|
||||
}
|
||||
|
||||
await presenter.present(result.value);
|
||||
return presenter;
|
||||
return presenter.getResponseModel();
|
||||
}
|
||||
|
||||
async getMembers(teamId: string): Promise<TeamMembersPresenter> {
|
||||
async getMembers(teamId: string): Promise<GetTeamMembersOutputDTO> {
|
||||
this.logger.debug(`[TeamService] Fetching team members for teamId: ${teamId}`);
|
||||
|
||||
const presenter = new TeamMembersPresenter();
|
||||
const result = await this.getTeamMembersUseCase.execute({ teamId });
|
||||
const useCase = new GetTeamMembersUseCase(this.membershipRepository, this.driverRepository, this.imageService, this.logger, presenter);
|
||||
const result = await useCase.execute({ teamId });
|
||||
if (result.isErr()) {
|
||||
this.logger.error(`Error fetching team members for teamId: ${teamId}`, result.error);
|
||||
await presenter.present({
|
||||
this.logger.error(`Error fetching team members for teamId: ${teamId}: ${result.error?.details?.message || 'Unknown error'}`);
|
||||
return {
|
||||
members: [],
|
||||
totalCount: 0,
|
||||
ownerCount: 0,
|
||||
managerCount: 0,
|
||||
memberCount: 0,
|
||||
} as unknown as any);
|
||||
return presenter;
|
||||
};
|
||||
}
|
||||
|
||||
await presenter.present(result.value);
|
||||
return presenter;
|
||||
return presenter.getResponseModel()!;
|
||||
}
|
||||
|
||||
async getJoinRequests(teamId: string): Promise<TeamJoinRequestsPresenter> {
|
||||
async getJoinRequests(teamId: string): Promise<GetTeamJoinRequestsOutputDTO> {
|
||||
this.logger.debug(`[TeamService] Fetching team join requests for teamId: ${teamId}`);
|
||||
|
||||
const presenter = new TeamJoinRequestsPresenter();
|
||||
const result = await this.getTeamJoinRequestsUseCase.execute({ teamId });
|
||||
const useCase = new GetTeamJoinRequestsUseCase(this.membershipRepository, this.driverRepository, this.teamRepository, presenter);
|
||||
const result = await useCase.execute({ teamId });
|
||||
if (result.isErr()) {
|
||||
this.logger.error(`Error fetching team join requests for teamId: ${teamId}`, result.error);
|
||||
await presenter.present({
|
||||
this.logger.error(new Error(`Error fetching team join requests for teamId: ${teamId}: ${result.error?.details?.message || 'Unknown error'}`));
|
||||
return {
|
||||
requests: [],
|
||||
pendingCount: 0,
|
||||
totalCount: 0,
|
||||
} as unknown as any);
|
||||
return presenter;
|
||||
};
|
||||
}
|
||||
|
||||
await presenter.present(result.value);
|
||||
return presenter;
|
||||
return presenter.getResponseModel()!;
|
||||
}
|
||||
|
||||
async create(input: CreateTeamInputDTO, userId?: string): Promise<CreateTeamPresenter> {
|
||||
async create(input: CreateTeamInputDTO, userId?: string): Promise<CreateTeamOutputDTO> {
|
||||
this.logger.debug('[TeamService] Creating team', { input, userId });
|
||||
|
||||
const presenter = new CreateTeamPresenter();
|
||||
|
||||
const command = {
|
||||
const command: CreateTeamInput = {
|
||||
name: input.name,
|
||||
tag: input.tag,
|
||||
description: input.description ?? '',
|
||||
@@ -132,68 +129,66 @@ export class TeamService {
|
||||
leagues: [],
|
||||
};
|
||||
|
||||
const result = await this.createTeamUseCase.execute(command as any);
|
||||
const useCase = new CreateTeamUseCase(this.teamRepository, this.membershipRepository, this.logger, presenter);
|
||||
const result = await useCase.execute(command);
|
||||
if (result.isErr()) {
|
||||
this.logger.error('Error creating team', result.error);
|
||||
presenter.presentError();
|
||||
return presenter;
|
||||
this.logger.error(`Error creating team: ${result.error?.details?.message || 'Unknown error'}`);
|
||||
return { id: '', success: false };
|
||||
}
|
||||
|
||||
presenter.presentSuccess(result.value);
|
||||
return presenter;
|
||||
return presenter.responseModel;
|
||||
}
|
||||
|
||||
async update(teamId: string, input: UpdateTeamInputDTO, userId?: string): Promise<UpdateTeamPresenter> {
|
||||
async update(teamId: string, input: UpdateTeamInputDTO, userId?: string): Promise<UpdateTeamOutputDTO> {
|
||||
this.logger.debug(`[TeamService] Updating team ${teamId}`, { input, userId });
|
||||
|
||||
const presenter = new UpdateTeamPresenter();
|
||||
|
||||
const command = {
|
||||
const command: UpdateTeamInput = {
|
||||
teamId,
|
||||
updates: {
|
||||
name: input.name,
|
||||
tag: input.tag,
|
||||
description: input.description,
|
||||
...(input.name !== undefined && { name: input.name }),
|
||||
...(input.tag !== undefined && { tag: input.tag }),
|
||||
...(input.description !== undefined && { description: input.description }),
|
||||
},
|
||||
updatedBy: userId || '',
|
||||
};
|
||||
|
||||
const result = await this.updateTeamUseCase.execute(command as any);
|
||||
const useCase = new UpdateTeamUseCase(this.teamRepository, this.membershipRepository, presenter);
|
||||
const result = await useCase.execute(command);
|
||||
if (result.isErr()) {
|
||||
this.logger.error(`Error updating team ${teamId}`, result.error);
|
||||
presenter.presentError();
|
||||
return presenter;
|
||||
this.logger.error(`Error updating team ${teamId}: ${result.error?.details?.message || 'Unknown error'}`);
|
||||
return { success: false };
|
||||
}
|
||||
|
||||
presenter.presentSuccess();
|
||||
return presenter;
|
||||
return presenter.responseModel;
|
||||
}
|
||||
|
||||
async getDriverTeam(driverId: string): Promise<DriverTeamPresenter> {
|
||||
async getDriverTeam(driverId: string): Promise<GetDriverTeamOutputDTO | null> {
|
||||
this.logger.debug(`[TeamService] Fetching driver team for driverId: ${driverId}`);
|
||||
|
||||
const presenter = new DriverTeamPresenter();
|
||||
const result = await this.getDriverTeamUseCase.execute({ driverId });
|
||||
const useCase = new GetDriverTeamUseCase(this.teamRepository, this.membershipRepository, this.logger, presenter);
|
||||
const result = await useCase.execute({ driverId });
|
||||
if (result.isErr()) {
|
||||
this.logger.error(`Error fetching driver team for driverId: ${driverId}`, result.error);
|
||||
return presenter;
|
||||
this.logger.error(`Error fetching driver team for driverId: ${driverId}: ${result.error?.details?.message || 'Unknown error'}`);
|
||||
return null;
|
||||
}
|
||||
|
||||
await presenter.present(result.value);
|
||||
return presenter;
|
||||
return presenter.getResponseModel();
|
||||
}
|
||||
|
||||
async getMembership(teamId: string, driverId: string): Promise<TeamMembershipPresenter> {
|
||||
async getMembership(teamId: string, driverId: string): Promise<GetTeamMembershipOutputDTO | null> {
|
||||
this.logger.debug(`[TeamService] Fetching team membership for teamId: ${teamId}, driverId: ${driverId}`);
|
||||
|
||||
const presenter = new TeamMembershipPresenter();
|
||||
const result = await this.getTeamMembershipUseCase.execute({ teamId, driverId });
|
||||
const useCase = new GetTeamMembershipUseCase(this.membershipRepository, this.logger, presenter);
|
||||
const result = await useCase.execute({ teamId, driverId });
|
||||
if (result.isErr()) {
|
||||
this.logger.error(`Error fetching team membership for teamId: ${teamId}, driverId: ${driverId}`, result.error);
|
||||
return presenter;
|
||||
this.logger.error(`Error fetching team membership for teamId: ${teamId}, driverId: ${driverId}: ${result.error?.details?.message || 'Unknown error'}`);
|
||||
return null;
|
||||
}
|
||||
|
||||
presenter.present(result.value as any);
|
||||
return presenter;
|
||||
return presenter.responseModel;
|
||||
}
|
||||
}
|
||||
@@ -1,36 +1,26 @@
|
||||
import type { GetAllTeamsErrorCode, GetAllTeamsResult } from '@core/racing/application/use-cases/GetAllTeamsUseCase';
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
|
||||
import type { GetAllTeamsResult } from '@core/racing/application/use-cases/GetAllTeamsUseCase';
|
||||
import { GetAllTeamsOutputDTO } from '../dtos/GetAllTeamsOutputDTO';
|
||||
|
||||
export type GetAllTeamsError = ApplicationErrorCode<GetAllTeamsErrorCode, { message: string }>;
|
||||
|
||||
export class AllTeamsPresenter {
|
||||
export class AllTeamsPresenter implements UseCaseOutputPort<GetAllTeamsResult> {
|
||||
private model: GetAllTeamsOutputDTO | null = null;
|
||||
|
||||
reset(): void {
|
||||
this.model = null;
|
||||
}
|
||||
|
||||
present(result: Result<GetAllTeamsResult, GetAllTeamsError>): void {
|
||||
if (result.isErr()) {
|
||||
const error = result.unwrapErr();
|
||||
throw new Error(error.details?.message ?? 'Failed to get teams');
|
||||
}
|
||||
|
||||
const output = result.unwrap();
|
||||
|
||||
present(result: GetAllTeamsResult): void {
|
||||
this.model = {
|
||||
teams: output.teams.map(team => ({
|
||||
teams: result.teams.map(team => ({
|
||||
id: team.id,
|
||||
name: team.name,
|
||||
tag: team.tag,
|
||||
description: team.description,
|
||||
name: team.name.toString(),
|
||||
tag: team.tag.toString(),
|
||||
description: team.description?.toString() || '',
|
||||
memberCount: team.memberCount,
|
||||
leagues: team.leagues || [],
|
||||
leagues: team.leagues?.map(l => l.toString()) || [],
|
||||
// Note: specialization, region, languages not available in output
|
||||
})),
|
||||
totalCount: output.totalCount ?? output.teams.length,
|
||||
totalCount: result.totalCount ?? result.teams.length,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,36 +1,17 @@
|
||||
import type { Result } from '@core/shared/application/Result';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
import type { CreateTeamErrorCode, CreateTeamResult } from '@core/racing/application/use-cases/CreateTeamUseCase';
|
||||
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
|
||||
import type { CreateTeamResult } from '@core/racing/application/use-cases/CreateTeamUseCase';
|
||||
import type { CreateTeamOutputDTO } from '../dtos/CreateTeamOutputDTO';
|
||||
|
||||
export type CreateTeamError = ApplicationErrorCode<CreateTeamErrorCode, { message: string }>;
|
||||
|
||||
export class CreateTeamPresenter {
|
||||
export class CreateTeamPresenter implements UseCaseOutputPort<CreateTeamResult> {
|
||||
private model: CreateTeamOutputDTO | null = null;
|
||||
|
||||
reset(): void {
|
||||
this.model = null;
|
||||
}
|
||||
|
||||
present(result: Result<CreateTeamResult, CreateTeamError>): void {
|
||||
if (result.isErr()) {
|
||||
const error = result.unwrapErr();
|
||||
// Validation and expected domain errors map to an unsuccessful DTO
|
||||
if (error.code === 'VALIDATION_ERROR' || error.code === 'LEAGUE_NOT_FOUND') {
|
||||
this.model = {
|
||||
id: '',
|
||||
success: false,
|
||||
};
|
||||
return;
|
||||
}
|
||||
|
||||
throw new Error(error.details?.message ?? 'Failed to create team');
|
||||
}
|
||||
|
||||
const output = result.unwrap();
|
||||
|
||||
present(result: CreateTeamResult): void {
|
||||
this.model = {
|
||||
id: output.team.id,
|
||||
id: result.team.id,
|
||||
success: true,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,38 +1,39 @@
|
||||
import { DriverTeamOutputPort } from '@core/racing/application/ports/output/DriverTeamOutputPort';
|
||||
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
|
||||
import type { GetDriverTeamResult } from '@core/racing/application/use-cases/GetDriverTeamUseCase';
|
||||
import { GetDriverTeamOutputDTO } from '../dtos/GetDriverTeamOutputDTO';
|
||||
|
||||
export class DriverTeamPresenter {
|
||||
export class DriverTeamPresenter implements UseCaseOutputPort<GetDriverTeamResult> {
|
||||
private result: GetDriverTeamOutputDTO | null = null;
|
||||
|
||||
reset() {
|
||||
this.result = null;
|
||||
}
|
||||
|
||||
async present(output: DriverTeamOutputPort) {
|
||||
const isOwner = output.team.ownerId === output.driverId;
|
||||
const canManage = isOwner || output.membership.role === 'owner' || output.membership.role === 'manager';
|
||||
present(result: GetDriverTeamResult): void {
|
||||
const isOwner = result.team.ownerId.toString() === result.driverId;
|
||||
const canManage = isOwner || result.membership.role === 'owner' || result.membership.role === 'manager';
|
||||
|
||||
this.result = {
|
||||
team: {
|
||||
id: output.team.id,
|
||||
name: output.team.name,
|
||||
tag: output.team.tag,
|
||||
description: output.team.description || '',
|
||||
ownerId: output.team.ownerId,
|
||||
leagues: output.team.leagues || [],
|
||||
createdAt: output.team.createdAt.toISOString(),
|
||||
id: result.team.id,
|
||||
name: result.team.name.toString(),
|
||||
tag: result.team.tag.toString(),
|
||||
description: result.team.description?.toString() || '',
|
||||
ownerId: result.team.ownerId.toString(),
|
||||
leagues: result.team.leagues?.map(l => l.toString()) || [],
|
||||
createdAt: result.team.createdAt.toDate().toISOString(),
|
||||
},
|
||||
membership: {
|
||||
role: output.membership.role === 'driver' ? 'member' : output.membership.role,
|
||||
joinedAt: output.membership.joinedAt.toISOString(),
|
||||
isActive: output.membership.status === 'active',
|
||||
role: result.membership.role === 'driver' ? 'member' : result.membership.role,
|
||||
joinedAt: result.membership.joinedAt.toISOString(),
|
||||
isActive: result.membership.status === 'active',
|
||||
},
|
||||
isOwner,
|
||||
canManage,
|
||||
};
|
||||
}
|
||||
|
||||
getViewModel(): GetDriverTeamOutputDTO | null {
|
||||
getResponseModel(): GetDriverTeamOutputDTO | null {
|
||||
return this.result;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user