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