refactor
This commit is contained in:
@@ -1,24 +1,20 @@
|
||||
/**
|
||||
* In-Memory Implementation: ILeagueWalletRepository
|
||||
*
|
||||
*
|
||||
* Mock repository for testing and development
|
||||
*/
|
||||
|
||||
import type { LeagueWallet } from '../../domain/entities/LeagueWallet';
|
||||
import type { ILeagueWalletRepository } from '../../domain/repositories/ILeagueWalletRepository';
|
||||
import { LeagueWallet } from '@core/racing/domain/entities/league-wallet/LeagueWallet';
|
||||
import type { ILeagueWalletRepository } from '@core/racing/domain/repositories/ILeagueWalletRepository';
|
||||
import type { Logger } from '@core/shared/application';
|
||||
|
||||
export class InMemoryLeagueWalletRepository implements ILeagueWalletRepository {
|
||||
private wallets: Map<string, LeagueWallet> = new Map();
|
||||
private readonly logger: Logger;
|
||||
|
||||
constructor(logger: Logger, seedData?: LeagueWallet[]) {
|
||||
constructor(logger: Logger) {
|
||||
this.logger = logger;
|
||||
this.logger.info('InMemoryLeagueWalletRepository initialized.');
|
||||
if (seedData) {
|
||||
seedData.forEach(wallet => this.wallets.set(wallet.id, wallet));
|
||||
this.logger.debug(`Seeded ${seedData.length} league wallets.`);
|
||||
}
|
||||
}
|
||||
|
||||
async findById(id: string): Promise<LeagueWallet | null> {
|
||||
@@ -41,7 +37,7 @@ export class InMemoryLeagueWalletRepository implements ILeagueWalletRepository {
|
||||
this.logger.debug(`Finding league wallet by league id: ${leagueId}`);
|
||||
try {
|
||||
for (const wallet of this.wallets.values()) {
|
||||
if (wallet.leagueId === leagueId) {
|
||||
if (wallet.leagueId.toString() === leagueId) {
|
||||
this.logger.info(`Found league wallet for league id: ${leagueId}.`);
|
||||
return wallet;
|
||||
}
|
||||
@@ -57,11 +53,11 @@ export class InMemoryLeagueWalletRepository implements ILeagueWalletRepository {
|
||||
async create(wallet: LeagueWallet): Promise<LeagueWallet> {
|
||||
this.logger.debug(`Creating league wallet: ${wallet.id}`);
|
||||
try {
|
||||
if (this.wallets.has(wallet.id)) {
|
||||
if (this.wallets.has(wallet.id.toString())) {
|
||||
this.logger.warn(`LeagueWallet with ID ${wallet.id} already exists.`);
|
||||
throw new Error('LeagueWallet with this ID already exists');
|
||||
}
|
||||
this.wallets.set(wallet.id, wallet);
|
||||
this.wallets.set(wallet.id.toString(), wallet);
|
||||
this.logger.info(`LeagueWallet ${wallet.id} created successfully.`);
|
||||
return wallet;
|
||||
} catch (error) {
|
||||
@@ -73,11 +69,11 @@ export class InMemoryLeagueWalletRepository implements ILeagueWalletRepository {
|
||||
async update(wallet: LeagueWallet): Promise<LeagueWallet> {
|
||||
this.logger.debug(`Updating league wallet: ${wallet.id}`);
|
||||
try {
|
||||
if (!this.wallets.has(wallet.id)) {
|
||||
if (!this.wallets.has(wallet.id.toString())) {
|
||||
this.logger.warn(`LeagueWallet with ID ${wallet.id} not found for update.`);
|
||||
throw new Error('LeagueWallet not found');
|
||||
}
|
||||
this.wallets.set(wallet.id, wallet);
|
||||
this.wallets.set(wallet.id.toString(), wallet);
|
||||
this.logger.info(`LeagueWallet ${wallet.id} updated successfully.`);
|
||||
return wallet;
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user