harden media

This commit is contained in:
2025-12-31 15:39:28 +01:00
parent 92226800df
commit 8260bf7baf
413 changed files with 8361 additions and 1544 deletions

View File

@@ -5,9 +5,10 @@
* Stores data in a Map structure.
*/
import type { Team } from '@core/racing/domain/entities/Team';
import { Team } from '@core/racing/domain/entities/Team';
import type { ITeamRepository } from '@core/racing/domain/repositories/ITeamRepository';
import type { Logger } from '@core/shared/application';
import { MediaReference } from '@core/domain/media/MediaReference';
export class InMemoryTeamRepository implements ITeamRepository {
private teams: Map<string, Team>;
@@ -122,4 +123,53 @@ export class InMemoryTeamRepository implements ITeamRepository {
throw error;
}
}
// Serialization methods for persistence
serialize(team: Team): Record<string, unknown> {
return {
id: team.id,
name: team.name.toString(),
tag: team.tag.toString(),
description: team.description.toString(),
ownerId: team.ownerId.toString(),
leagues: team.leagues.map(l => l.toString()),
category: team.category ?? null,
isRecruiting: team.isRecruiting,
createdAt: team.createdAt.toDate().toISOString(),
logoRef: team.logoRef.toJSON(),
};
}
deserialize(data: Record<string, unknown>): Team {
const props: {
id: string;
name: string;
tag: string;
description: string;
ownerId: string;
leagues: string[];
category?: string;
isRecruiting: boolean;
createdAt: Date;
logoRef?: MediaReference;
} = {
id: data.id as string,
name: data.name as string,
tag: data.tag as string,
description: data.description as string,
ownerId: data.ownerId as string,
leagues: data.leagues as string[],
isRecruiting: data.isRecruiting as boolean,
createdAt: new Date(data.createdAt as string),
};
if (data.category !== null && data.category !== undefined) {
props.category = data.category as string;
}
if (data.logoRef !== null && data.logoRef !== undefined) {
props.logoRef = MediaReference.fromJSON(data.logoRef as Record<string, unknown>);
}
return Team.rehydrate(props);
}
}