refactor driver module (wip)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user