refactor
This commit is contained in:
@@ -4,9 +4,9 @@
|
||||
* Mock repository for testing and development
|
||||
*/
|
||||
|
||||
import type { DriverLivery } from '../../domain/entities/DriverLivery';
|
||||
import type { LiveryTemplate } from '../../domain/entities/LiveryTemplate';
|
||||
import type { ILiveryRepository } from '../../domain/repositories/ILiveryRepository';
|
||||
import type { DriverLivery } from '../../../../core/racing/domain/entities/DriverLivery';
|
||||
import type { LiveryTemplate } from '../../../../core/racing/domain/entities/LiveryTemplate';
|
||||
import type { ILiveryRepository } from '../../../../core/racing/domain/repositories/ILiveryRepository';
|
||||
import type { Logger } from '@core/shared/application';
|
||||
|
||||
export class InMemoryLiveryRepository implements ILiveryRepository {
|
||||
@@ -22,7 +22,7 @@ export class InMemoryLiveryRepository implements ILiveryRepository {
|
||||
this.logger.debug(`Seeded ${seedDriverLiveries.length} driver liveries.`);
|
||||
}
|
||||
if (seedTemplates) {
|
||||
seedTemplates.forEach(template => this.templates.set(template.id, template));
|
||||
seedTemplates.forEach(template => this.templates.set(template.id.toString(), template));
|
||||
this.logger.debug(`Seeded ${seedTemplates.length} livery templates.`);
|
||||
}
|
||||
}
|
||||
@@ -47,7 +47,7 @@ export class InMemoryLiveryRepository implements ILiveryRepository {
|
||||
async findDriverLiveriesByDriverId(driverId: string): Promise<DriverLivery[]> {
|
||||
this.logger.debug(`Finding driver liveries by driver id: ${driverId}`);
|
||||
try {
|
||||
const liveries = Array.from(this.driverLiveries.values()).filter(l => l.driverId === driverId);
|
||||
const liveries = Array.from(this.driverLiveries.values()).filter(l => l.driverId.toString() === driverId);
|
||||
this.logger.info(`Found ${liveries.length} driver liveries for driver id: ${driverId}.`);
|
||||
return liveries;
|
||||
} catch (error) {
|
||||
@@ -60,7 +60,7 @@ export class InMemoryLiveryRepository implements ILiveryRepository {
|
||||
this.logger.debug(`Finding driver livery by driver: ${driverId} and car: ${carId}`);
|
||||
try {
|
||||
for (const livery of this.driverLiveries.values()) {
|
||||
if (livery.driverId === driverId && livery.carId === carId) {
|
||||
if (livery.driverId.toString() === driverId && livery.carId.toString() === carId) {
|
||||
this.logger.info(`Found driver livery for driver: ${driverId}, car: ${carId}.`);
|
||||
return livery;
|
||||
}
|
||||
@@ -68,7 +68,7 @@ export class InMemoryLiveryRepository implements ILiveryRepository {
|
||||
this.logger.warn(`Driver livery for driver ${driverId} and car ${carId} not found.`);
|
||||
return null;
|
||||
} catch (error) {
|
||||
this.logger.error(`Error finding driver livery by driver ${driverId}, car ${carId}:`, error);
|
||||
this.logger.error(`Error finding driver livery by driver ${driverId}, car ${carId}:`, error instanceof Error ? error : new Error(String(error)));
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -76,7 +76,7 @@ export class InMemoryLiveryRepository implements ILiveryRepository {
|
||||
async findDriverLiveriesByGameId(gameId: string): Promise<DriverLivery[]> {
|
||||
this.logger.debug(`Finding driver liveries by game id: ${gameId}`);
|
||||
try {
|
||||
const liveries = Array.from(this.driverLiveries.values()).filter(l => l.gameId === gameId);
|
||||
const liveries = Array.from(this.driverLiveries.values()).filter(l => l.gameId.toString() === gameId);
|
||||
this.logger.info(`Found ${liveries.length} driver liveries for game id: ${gameId}.`);
|
||||
return liveries;
|
||||
} catch (error) {
|
||||
@@ -89,12 +89,12 @@ export class InMemoryLiveryRepository implements ILiveryRepository {
|
||||
this.logger.debug(`Finding driver liveries by driver: ${driverId} and game: ${gameId}`);
|
||||
try {
|
||||
const liveries = Array.from(this.driverLiveries.values()).filter(
|
||||
l => l.driverId === driverId && l.gameId === gameId
|
||||
l => l.driverId.toString() === driverId && l.gameId.toString() === gameId
|
||||
);
|
||||
this.logger.info(`Found ${liveries.length} driver liveries for driver: ${driverId}, game: ${gameId}.`);
|
||||
return liveries;
|
||||
} catch (error) {
|
||||
this.logger.error(`Error finding driver liveries by driver ${driverId}, game ${gameId}:`, error);
|
||||
this.logger.error(`Error finding driver liveries by driver ${driverId}, game ${gameId}:`, error instanceof Error ? error : new Error(String(error)));
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -165,7 +165,7 @@ export class InMemoryLiveryRepository implements ILiveryRepository {
|
||||
async findTemplatesBySeasonId(seasonId: string): Promise<LiveryTemplate[]> {
|
||||
this.logger.debug(`Finding livery templates by season id: ${seasonId}`);
|
||||
try {
|
||||
const templates = Array.from(this.templates.values()).filter(t => t.seasonId === seasonId);
|
||||
const templates = Array.from(this.templates.values()).filter(t => t.seasonId.toString() === seasonId);
|
||||
this.logger.info(`Found ${templates.length} livery templates for season id: ${seasonId}.`);
|
||||
return templates;
|
||||
} catch (error) {
|
||||
@@ -178,7 +178,7 @@ export class InMemoryLiveryRepository implements ILiveryRepository {
|
||||
this.logger.debug(`Finding livery template by season: ${seasonId} and car: ${carId}`);
|
||||
try {
|
||||
for (const template of this.templates.values()) {
|
||||
if (template.seasonId === seasonId && template.carId === carId) {
|
||||
if (template.seasonId.toString() === seasonId && template.carId.toString() === carId) {
|
||||
this.logger.info(`Found livery template for season: ${seasonId}, car: ${carId}.`);
|
||||
return template;
|
||||
}
|
||||
@@ -186,39 +186,39 @@ export class InMemoryLiveryRepository implements ILiveryRepository {
|
||||
this.logger.warn(`Livery template for season ${seasonId} and car ${carId} not found.`);
|
||||
return null;
|
||||
} catch (error) {
|
||||
this.logger.error(`Error finding livery template by season ${seasonId}, car ${carId}:`, error);
|
||||
this.logger.error(`Error finding livery template by season ${seasonId}, car ${carId}:`, error instanceof Error ? error : new Error(String(error)));
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async createTemplate(template: LiveryTemplate): Promise<LiveryTemplate> {
|
||||
this.logger.debug(`Creating livery template: ${template.id}`);
|
||||
this.logger.debug(`Creating livery template: ${template.id.toString()}`);
|
||||
try {
|
||||
if (this.templates.has(template.id)) {
|
||||
this.logger.warn(`LiveryTemplate with ID ${template.id} already exists.`);
|
||||
if (this.templates.has(template.id.toString())) {
|
||||
this.logger.warn(`LiveryTemplate with ID ${template.id.toString()} already exists.`);
|
||||
throw new Error('LiveryTemplate with this ID already exists');
|
||||
}
|
||||
this.templates.set(template.id, template);
|
||||
this.logger.info(`LiveryTemplate ${template.id} created successfully.`);
|
||||
this.templates.set(template.id.toString(), template);
|
||||
this.logger.info(`LiveryTemplate ${template.id.toString()} created successfully.`);
|
||||
return template;
|
||||
} catch (error) {
|
||||
this.logger.error(`Error creating livery template ${template.id}:`, error instanceof Error ? error : new Error(String(error)));
|
||||
this.logger.error(`Error creating livery template ${template.id.toString()}:`, error instanceof Error ? error : new Error(String(error)));
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async updateTemplate(template: LiveryTemplate): Promise<LiveryTemplate> {
|
||||
this.logger.debug(`Updating livery template: ${template.id}`);
|
||||
this.logger.debug(`Updating livery template: ${template.id.toString()}`);
|
||||
try {
|
||||
if (!this.templates.has(template.id)) {
|
||||
this.logger.warn(`LiveryTemplate with ID ${template.id} not found for update.`);
|
||||
if (!this.templates.has(template.id.toString())) {
|
||||
this.logger.warn(`LiveryTemplate with ID ${template.id.toString()} not found for update.`);
|
||||
throw new Error('LiveryTemplate not found');
|
||||
}
|
||||
this.templates.set(template.id, template);
|
||||
this.logger.info(`LiveryTemplate ${template.id} updated successfully.`);
|
||||
this.templates.set(template.id.toString(), template);
|
||||
this.logger.info(`LiveryTemplate ${template.id.toString()} updated successfully.`);
|
||||
return template;
|
||||
} catch (error) {
|
||||
this.logger.error(`Error updating livery template ${template.id}:`, error instanceof Error ? error : new Error(String(error)));
|
||||
this.logger.error(`Error updating livery template ${template.id.toString()}:`, error instanceof Error ? error : new Error(String(error)));
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user