harden media
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { IDriverRepository } from '@core/racing/domain/repositories/IDriverRepository';
|
||||
import { Driver } from '@core/racing/domain/entities/Driver';
|
||||
import { Logger } from '@core/shared/application';
|
||||
import { MediaReference } from '@core/domain/media/MediaReference';
|
||||
|
||||
export class InMemoryDriverRepository implements IDriverRepository {
|
||||
private drivers: Map<string, Driver> = new Map();
|
||||
@@ -91,4 +92,49 @@ export class InMemoryDriverRepository implements IDriverRepository {
|
||||
this.logger.debug(`[InMemoryDriverRepository] Checking existence of driver with iRacing ID: ${iracingId}`);
|
||||
return Promise.resolve(this.iracingIdIndex.has(iracingId));
|
||||
}
|
||||
}
|
||||
|
||||
// Serialization methods for persistence
|
||||
serialize(driver: Driver): Record<string, unknown> {
|
||||
return {
|
||||
id: driver.id,
|
||||
iracingId: driver.iracingId.toString(),
|
||||
name: driver.name.toString(),
|
||||
country: driver.country.toString(),
|
||||
bio: driver.bio?.toString() ?? null,
|
||||
joinedAt: driver.joinedAt.toDate().toISOString(),
|
||||
category: driver.category ?? null,
|
||||
avatarRef: driver.avatarRef.toJSON(),
|
||||
};
|
||||
}
|
||||
|
||||
deserialize(data: Record<string, unknown>): Driver {
|
||||
const props: {
|
||||
id: string;
|
||||
iracingId: string;
|
||||
name: string;
|
||||
country: string;
|
||||
bio?: string;
|
||||
joinedAt: Date;
|
||||
category?: string;
|
||||
avatarRef?: MediaReference;
|
||||
} = {
|
||||
id: data.id as string,
|
||||
iracingId: data.iracingId as string,
|
||||
name: data.name as string,
|
||||
country: data.country as string,
|
||||
joinedAt: new Date(data.joinedAt as string),
|
||||
};
|
||||
|
||||
if (data.bio !== null && data.bio !== undefined) {
|
||||
props.bio = data.bio as string;
|
||||
}
|
||||
if (data.category !== null && data.category !== undefined) {
|
||||
props.category = data.category as string;
|
||||
}
|
||||
if (data.avatarRef !== null && data.avatarRef !== undefined) {
|
||||
props.avatarRef = MediaReference.fromJSON(data.avatarRef as Record<string, unknown>);
|
||||
}
|
||||
|
||||
return Driver.rehydrate(props);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user