website refactor
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { ProtestDTO } from '../types/generated/ProtestDTO';
|
||||
import { RaceProtestDTO } from '../types/generated/RaceProtestDTO';
|
||||
import { ProtestDTO } from '@/lib/types/generated/ProtestDTO';
|
||||
import { RaceProtestDTO } from '@/lib/types/generated/RaceProtestDTO';
|
||||
|
||||
/**
|
||||
* Protest view model
|
||||
@@ -22,15 +22,41 @@ export class ProtestViewModel {
|
||||
|
||||
constructor(dto: ProtestDTO | RaceProtestDTO) {
|
||||
this.id = dto.id;
|
||||
this.raceId = (dto as any).raceId || '';
|
||||
|
||||
// Type narrowing for raceId
|
||||
if ('raceId' in dto) {
|
||||
this.raceId = dto.raceId;
|
||||
} else {
|
||||
this.raceId = '';
|
||||
}
|
||||
|
||||
this.protestingDriverId = dto.protestingDriverId;
|
||||
this.accusedDriverId = dto.accusedDriverId;
|
||||
this.description = (dto as any).description || dto.description;
|
||||
this.submittedAt = (dto as any).submittedAt || (dto as any).filedAt || '';
|
||||
this.filedAt = (dto as any).filedAt || (dto as any).submittedAt;
|
||||
|
||||
// Type narrowing for description
|
||||
if ('description' in dto && typeof dto.description === 'string') {
|
||||
this.description = dto.description;
|
||||
} else {
|
||||
this.description = '';
|
||||
}
|
||||
|
||||
// Type narrowing for submittedAt and filedAt
|
||||
if ('submittedAt' in dto && typeof dto.submittedAt === 'string') {
|
||||
this.submittedAt = dto.submittedAt;
|
||||
} else if ('filedAt' in dto && typeof dto.filedAt === 'string') {
|
||||
this.submittedAt = dto.filedAt;
|
||||
} else {
|
||||
this.submittedAt = '';
|
||||
}
|
||||
|
||||
if ('filedAt' in dto && typeof dto.filedAt === 'string') {
|
||||
this.filedAt = dto.filedAt;
|
||||
} else if ('submittedAt' in dto && typeof dto.submittedAt === 'string') {
|
||||
this.filedAt = dto.submittedAt;
|
||||
}
|
||||
|
||||
// Handle different DTO structures
|
||||
if ('status' in dto) {
|
||||
if ('status' in dto && typeof dto.status === 'string') {
|
||||
this.status = dto.status;
|
||||
} else {
|
||||
this.status = 'pending';
|
||||
@@ -38,14 +64,16 @@ export class ProtestViewModel {
|
||||
|
||||
// Handle incident data
|
||||
if ('incident' in dto && dto.incident) {
|
||||
const incident = dto.incident as { lap?: number; description?: string };
|
||||
this.incident = {
|
||||
lap: (dto.incident as any).lap,
|
||||
description: (dto.incident as any).description
|
||||
lap: typeof incident.lap === 'number' ? incident.lap : undefined,
|
||||
description: typeof incident.description === 'string' ? incident.description : undefined
|
||||
};
|
||||
} else if ('lap' in dto || 'description' in dto) {
|
||||
} else if (('lap' in dto && typeof (dto as { lap?: number }).lap === 'number') ||
|
||||
('description' in dto && typeof (dto as { description?: string }).description === 'string')) {
|
||||
this.incident = {
|
||||
lap: (dto as any).lap,
|
||||
description: (dto as any).description
|
||||
lap: 'lap' in dto ? (dto as { lap?: number }).lap : undefined,
|
||||
description: 'description' in dto ? (dto as { description?: string }).description : undefined
|
||||
};
|
||||
} else {
|
||||
this.incident = null;
|
||||
|
||||
Reference in New Issue
Block a user