seed data
This commit is contained in:
@@ -44,13 +44,20 @@ export class InMemoryRaceRegistrationRepository implements IRaceRegistrationRepo
|
||||
}
|
||||
|
||||
async register(registration: RaceRegistration): Promise<void> {
|
||||
this.logger.debug(`[InMemoryRaceRegistrationRepository] Registering driver ${registration.driverId.toString()} for race ${registration.raceId.toString()}.`);
|
||||
if (await this.isRegistered(registration.raceId.toString(), registration.driverId.toString())) {
|
||||
this.logger.warn(`Driver ${registration.driverId.toString()} already registered for race ${registration.raceId.toString()}.`);
|
||||
const raceId = registration.raceId.toString();
|
||||
const driverId = registration.driverId.toString();
|
||||
|
||||
this.logger.debug(`[InMemoryRaceRegistrationRepository] Registering driver ${driverId} for race ${raceId}.`);
|
||||
|
||||
if (await this.isRegistered(raceId, driverId)) {
|
||||
this.logger.warn(`Driver ${driverId} already registered for race ${raceId}.`);
|
||||
throw new Error('Driver already registered for this race');
|
||||
}
|
||||
this.registrations.set(registration.id, registration);
|
||||
this.logger.info(`Driver ${registration.driverId.toString()} registered for race ${registration.raceId.toString()}.`);
|
||||
|
||||
const key = `${raceId}:${driverId}`;
|
||||
this.registrations.set(key, registration);
|
||||
|
||||
this.logger.info(`Driver ${driverId} registered for race ${raceId}.`);
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
@@ -80,16 +87,19 @@ export class InMemoryRaceRegistrationRepository implements IRaceRegistrationRepo
|
||||
|
||||
async clearRaceRegistrations(raceId: string): Promise<void> {
|
||||
this.logger.debug(`[InMemoryRaceRegistrationRepository] Clearing all registrations for race: ${raceId}.`);
|
||||
const registrationsToDelete: string[] = [];
|
||||
|
||||
const keysToDelete: string[] = [];
|
||||
for (const registration of this.registrations.values()) {
|
||||
if (registration.raceId.toString() === raceId) {
|
||||
registrationsToDelete.push(registration.id);
|
||||
keysToDelete.push(`${registration.raceId.toString()}:${registration.driverId.toString()}`);
|
||||
}
|
||||
}
|
||||
for (const id of registrationsToDelete) {
|
||||
this.registrations.delete(id);
|
||||
|
||||
for (const key of keysToDelete) {
|
||||
this.registrations.delete(key);
|
||||
}
|
||||
this.logger.info(`Cleared ${registrationsToDelete.length} registrations for race ${raceId}.`);
|
||||
|
||||
this.logger.info(`Cleared ${keysToDelete.length} registrations for race ${raceId}.`);
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user