harden media
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { ILeagueRepository } from '@core/racing/domain/repositories/ILeagueRepository';
|
||||
import { League } from '@core/racing/domain/entities/League';
|
||||
import { Logger } from '@core/shared/application';
|
||||
import { MediaReference } from '@core/domain/media/MediaReference';
|
||||
|
||||
export class InMemoryLeagueRepository implements ILeagueRepository {
|
||||
private leagues: Map<string, League> = new Map();
|
||||
@@ -132,4 +133,71 @@ export class InMemoryLeagueRepository implements ILeagueRepository {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Serialization methods for persistence
|
||||
serialize(league: League): Record<string, unknown> {
|
||||
return {
|
||||
id: league.id.toString(),
|
||||
name: league.name.toString(),
|
||||
description: league.description.toString(),
|
||||
ownerId: league.ownerId.toString(),
|
||||
settings: league.settings,
|
||||
category: league.category ?? null,
|
||||
createdAt: league.createdAt.toDate().toISOString(),
|
||||
participantCount: league.getParticipantCount(),
|
||||
socialLinks: league.socialLinks
|
||||
? {
|
||||
discordUrl: league.socialLinks.discordUrl,
|
||||
youtubeUrl: league.socialLinks.youtubeUrl,
|
||||
websiteUrl: league.socialLinks.websiteUrl,
|
||||
}
|
||||
: undefined,
|
||||
logoRef: league.logoRef.toJSON(),
|
||||
};
|
||||
}
|
||||
|
||||
deserialize(data: Record<string, unknown>): League {
|
||||
const props: {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
ownerId: string;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
settings: any;
|
||||
category?: string;
|
||||
createdAt: Date;
|
||||
participantCount: number;
|
||||
socialLinks?: {
|
||||
discordUrl?: string;
|
||||
youtubeUrl?: string;
|
||||
websiteUrl?: string;
|
||||
};
|
||||
logoRef?: MediaReference;
|
||||
} = {
|
||||
id: data.id as string,
|
||||
name: data.name as string,
|
||||
description: data.description as string,
|
||||
ownerId: data.ownerId as string,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
settings: data.settings as any,
|
||||
createdAt: new Date(data.createdAt as string),
|
||||
participantCount: data.participantCount as number,
|
||||
};
|
||||
|
||||
if (data.category !== null && data.category !== undefined) {
|
||||
props.category = data.category as string;
|
||||
}
|
||||
if (data.socialLinks !== null && data.socialLinks !== undefined) {
|
||||
props.socialLinks = data.socialLinks as {
|
||||
discordUrl?: string;
|
||||
youtubeUrl?: string;
|
||||
websiteUrl?: string;
|
||||
};
|
||||
}
|
||||
if (data.logoRef !== null && data.logoRef !== undefined) {
|
||||
props.logoRef = MediaReference.fromJSON(data.logoRef as Record<string, unknown>);
|
||||
}
|
||||
|
||||
return League.rehydrate(props);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user