84 lines
2.3 KiB
TypeScript
84 lines
2.3 KiB
TypeScript
import { GetLeagueProtestsOutputPort, type ProtestOutputPort } from '@core/racing/application/ports/output/GetLeagueProtestsOutputPort';
|
|
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'] {
|
|
switch (status) {
|
|
case 'pending':
|
|
case 'awaiting_defense':
|
|
case 'under_review':
|
|
return 'pending';
|
|
case 'upheld':
|
|
return 'accepted';
|
|
case 'dismissed':
|
|
case 'withdrawn':
|
|
return 'rejected';
|
|
default:
|
|
return 'pending';
|
|
}
|
|
}
|
|
|
|
export class GetLeagueProtestsPresenter {
|
|
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];
|
|
|
|
return {
|
|
id: protest.id,
|
|
leagueId: race?.leagueId || '',
|
|
raceId: protest.raceId,
|
|
protestingDriverId: protest.protestingDriverId,
|
|
accusedDriverId: protest.accusedDriverId,
|
|
submittedAt: new Date(protest.filedAt),
|
|
description: protest.incident.description,
|
|
status: mapProtestStatus(protest.status),
|
|
};
|
|
});
|
|
|
|
const racesById: { [raceId: string]: RaceDTO } = {};
|
|
for (const raceId in output.racesById) {
|
|
const race = output.racesById[raceId];
|
|
if (race) {
|
|
racesById[raceId] = {
|
|
id: race.id,
|
|
name: race.track,
|
|
date: race.scheduledAt.toISOString(),
|
|
leagueName,
|
|
};
|
|
}
|
|
}
|
|
|
|
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,
|
|
};
|
|
}
|
|
}
|
|
|
|
this.result = {
|
|
protests,
|
|
racesById,
|
|
driversById,
|
|
};
|
|
}
|
|
|
|
getViewModel(): LeagueAdminProtestsDTO | null {
|
|
return this.result;
|
|
}
|
|
} |