seed data
This commit is contained in:
50
adapters/racing/services/DriverStatsStore.ts
Normal file
50
adapters/racing/services/DriverStatsStore.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import type { DriverStats } from '@core/racing/domain/services/IDriverStatsService';
|
||||
|
||||
/**
|
||||
* Global store for driver stats that can be populated during seeding
|
||||
* and read by the InMemoryDriverStatsService
|
||||
*/
|
||||
export class DriverStatsStore {
|
||||
private static instance: DriverStatsStore;
|
||||
private statsMap = new Map<string, DriverStats>();
|
||||
|
||||
private constructor() {}
|
||||
|
||||
static getInstance(): DriverStatsStore {
|
||||
if (!DriverStatsStore.instance) {
|
||||
DriverStatsStore.instance = new DriverStatsStore();
|
||||
}
|
||||
return DriverStatsStore.instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Populate the store with stats (called during seeding)
|
||||
*/
|
||||
loadStats(stats: Map<string, DriverStats>): void {
|
||||
this.statsMap.clear();
|
||||
stats.forEach((input, driverId) => {
|
||||
this.statsMap.set(driverId, input);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get stats for a specific driver
|
||||
*/
|
||||
getDriverStats(driverId: string): DriverStats | null {
|
||||
return this.statsMap.get(driverId) ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all stats (useful for reseeding)
|
||||
*/
|
||||
clear(): void {
|
||||
this.statsMap.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all stats (for debugging)
|
||||
*/
|
||||
getAllStats(): Map<string, DriverStats> {
|
||||
return new Map(this.statsMap);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user