refactor
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* In-Memory Implementation: InMemoryWalletRepository
|
||||
*/
|
||||
|
||||
import type { Logger } from '@gridpilot/shared/application/Logger';
|
||||
import type { IWalletRepository, ITransactionRepository } from '../../../../core/payments/domain/repositories/IWalletRepository';
|
||||
import type { Wallet, Transaction } from '../../../../core/payments/domain/entities/Wallet';
|
||||
|
||||
const wallets: Map<string, Wallet> = new Map();
|
||||
const transactions: Map<string, Transaction> = new Map();
|
||||
|
||||
export class InMemoryWalletRepository implements IWalletRepository {
|
||||
constructor(private readonly logger: Logger) {}
|
||||
|
||||
async findById(id: string): Promise<Wallet | null> {
|
||||
this.logger.debug('[InMemoryWalletRepository] findById', { id });
|
||||
return wallets.get(id) || null;
|
||||
}
|
||||
|
||||
async findByLeagueId(leagueId: string): Promise<Wallet | null> {
|
||||
this.logger.debug('[InMemoryWalletRepository] findByLeagueId', { leagueId });
|
||||
return Array.from(wallets.values()).find(w => w.leagueId === leagueId) || null;
|
||||
}
|
||||
|
||||
async create(wallet: Wallet): Promise<Wallet> {
|
||||
this.logger.debug('[InMemoryWalletRepository] create', { wallet });
|
||||
wallets.set(wallet.id, wallet);
|
||||
return wallet;
|
||||
}
|
||||
|
||||
async update(wallet: Wallet): Promise<Wallet> {
|
||||
this.logger.debug('[InMemoryWalletRepository] update', { wallet });
|
||||
wallets.set(wallet.id, wallet);
|
||||
return wallet;
|
||||
}
|
||||
}
|
||||
|
||||
export class InMemoryTransactionRepository implements ITransactionRepository {
|
||||
constructor(private readonly logger: Logger) {}
|
||||
|
||||
async findById(id: string): Promise<Transaction | null> {
|
||||
this.logger.debug('[InMemoryTransactionRepository] findById', { id });
|
||||
return transactions.get(id) || null;
|
||||
}
|
||||
|
||||
async findByWalletId(walletId: string): Promise<Transaction[]> {
|
||||
this.logger.debug('[InMemoryTransactionRepository] findByWalletId', { walletId });
|
||||
return Array.from(transactions.values()).filter(t => t.walletId === walletId);
|
||||
}
|
||||
|
||||
async create(transaction: Transaction): Promise<Transaction> {
|
||||
this.logger.debug('[InMemoryTransactionRepository] create', { transaction });
|
||||
transactions.set(transaction.id, transaction);
|
||||
return transaction;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user