resolve todos in website and api
This commit is contained in:
@@ -1,28 +1,49 @@
|
||||
import { GetLeagueProtestsOutputPort } from '@core/racing/application/ports/output/GetLeagueProtestsOutputPort';
|
||||
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';
|
||||
|
||||
export function mapGetLeagueProtestsOutputPortToDTO(output: GetLeagueProtestsOutputPort): LeagueAdminProtestsDTO {
|
||||
const protests: ProtestDTO[] = output.protests.map(protest => ({
|
||||
id: protest.id,
|
||||
raceId: protest.raceId,
|
||||
protestingDriverId: protest.protestingDriverId,
|
||||
accusedDriverId: protest.accusedDriverId,
|
||||
submittedAt: new Date(protest.filedAt),
|
||||
description: protest.incident.description,
|
||||
status: protest.status as 'pending' | 'accepted' | 'rejected', // TODO: map properly
|
||||
}));
|
||||
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 function mapGetLeagueProtestsOutputPortToDTO(output: GetLeagueProtestsOutputPort, leagueName?: string): LeagueAdminProtestsDTO {
|
||||
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];
|
||||
racesById[raceId] = {
|
||||
id: race.id,
|
||||
name: race.track, // assuming name is track
|
||||
name: race.track,
|
||||
date: race.scheduledAt,
|
||||
leagueName: undefined, // TODO: get league name if needed
|
||||
leagueName,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user