refactor
This commit is contained in:
@@ -7,21 +7,13 @@ import { SponsorshipPricing } from '@core/racing/domain/value-objects/Sponsorshi
|
||||
import type { SponsorableEntityType } from '@core/racing/domain/entities/SponsorshipRequest';
|
||||
import type { Logger } from '@core/shared/application';
|
||||
|
||||
interface StorageKey {
|
||||
entityType: SponsorableEntityType;
|
||||
entityId: string;
|
||||
}
|
||||
|
||||
export class InMemorySponsorshipPricingRepository implements ISponsorshipPricingRepository {
|
||||
private pricings: Map<string, { entityType: SponsorableEntityType; entityId: string; pricing: SponsorshipPricing }> = new Map();
|
||||
private readonly logger: Logger;
|
||||
|
||||
constructor(logger: Logger, seedData?: Array<{ entityType: SponsorableEntityType; entityId: string; pricing: SponsorshipPricing }>) {
|
||||
constructor(logger: Logger) {
|
||||
this.logger = logger;
|
||||
this.logger.info('InMemorySponsorshipPricingRepository initialized.');
|
||||
if (seedData) {
|
||||
this.seed(seedData);
|
||||
}
|
||||
}
|
||||
|
||||
private makeKey(entityType: SponsorableEntityType, entityId: string): string {
|
||||
@@ -41,7 +33,7 @@ export class InMemorySponsorshipPricingRepository implements ISponsorshipPricing
|
||||
}
|
||||
return pricing;
|
||||
} catch (error) {
|
||||
this.logger.error(`Error finding sponsorship pricing for entity ${entityType}, ${entityId}:`, error);
|
||||
this.logger.error(`Error finding sponsorship pricing for entity ${entityType}, ${entityId}:`, error instanceof Error ? error : new Error(String(error)));
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -58,7 +50,7 @@ export class InMemorySponsorshipPricingRepository implements ISponsorshipPricing
|
||||
this.pricings.set(key, { entityType, entityId, pricing });
|
||||
this.logger.info(`Sponsorship pricing saved for entity: ${entityType}, ${entityId}.`);
|
||||
} catch (error) {
|
||||
this.logger.error(`Error saving sponsorship pricing for entity ${entityType}, ${entityId}:`, error);
|
||||
this.logger.error(`Error saving sponsorship pricing for entity ${entityType}, ${entityId}:`, error instanceof Error ? error : new Error(String(error)));
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -73,7 +65,7 @@ export class InMemorySponsorshipPricingRepository implements ISponsorshipPricing
|
||||
this.logger.warn(`Sponsorship pricing for entity ${entityType}, ${entityId} not found for deletion.`);
|
||||
}
|
||||
} catch (error) {
|
||||
this.logger.error(`Error deleting sponsorship pricing for entity ${entityType}, ${entityId}:`, error);
|
||||
this.logger.error(`Error deleting sponsorship pricing for entity ${entityType}, ${entityId}:`, error instanceof Error ? error : new Error(String(error)));
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -86,7 +78,7 @@ export class InMemorySponsorshipPricingRepository implements ISponsorshipPricing
|
||||
this.logger.debug(`Sponsorship pricing for entity ${entityType}, ${entityId} exists: ${exists}.`);
|
||||
return exists;
|
||||
} catch (error) {
|
||||
this.logger.error(`Error checking existence of sponsorship pricing for entity ${entityType}, ${entityId}:`, error);
|
||||
this.logger.error(`Error checking existence of sponsorship pricing for entity ${entityType}, ${entityId}:`, error instanceof Error ? error : new Error(String(error)));
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -107,31 +99,4 @@ export class InMemorySponsorshipPricingRepository implements ISponsorshipPricing
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Seed initial data
|
||||
*/
|
||||
seed(data: Array<{ entityType: SponsorableEntityType; entityId: string; pricing: SponsorshipPricing }>): void {
|
||||
this.logger.debug(`Seeding ${data.length} sponsorship pricing entries.`);
|
||||
try {
|
||||
for (const entry of data) {
|
||||
const key = this.makeKey(entry.entityType, entry.entityId);
|
||||
this.pricings.set(key, entry);
|
||||
this.logger.debug(`Seeded pricing for entity ${entry.entityType}, ${entry.entityId}.`);
|
||||
}
|
||||
this.logger.info(`Successfully seeded ${data.length} sponsorship pricing entries.`);
|
||||
} catch (error) {
|
||||
this.logger.error(`Error seeding sponsorship pricing data:`, error instanceof Error ? error : new Error(String(error)));
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all data (for testing)
|
||||
*/
|
||||
clear(): void {
|
||||
this.logger.debug('Clearing all sponsorship pricing data.');
|
||||
this.pricings.clear();
|
||||
this.logger.info('All sponsorship pricing data cleared.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user