/** * In-Memory Implementation: ITransactionRepository * * Mock repository for testing and development */ import type { Transaction, TransactionType } from '../../domain/entities/Transaction'; import type { ITransactionRepository } from '../../domain/repositories/ITransactionRepository'; export class InMemoryTransactionRepository implements ITransactionRepository { private transactions: Map = new Map(); async findById(id: string): Promise { return this.transactions.get(id) ?? null; } async findByWalletId(walletId: string): Promise { return Array.from(this.transactions.values()).filter(t => t.walletId === walletId); } async findByType(type: TransactionType): Promise { return Array.from(this.transactions.values()).filter(t => t.type === type); } async create(transaction: Transaction): Promise { if (this.transactions.has(transaction.id)) { throw new Error('Transaction with this ID already exists'); } this.transactions.set(transaction.id, transaction); return transaction; } async update(transaction: Transaction): Promise { if (!this.transactions.has(transaction.id)) { throw new Error('Transaction not found'); } this.transactions.set(transaction.id, transaction); return transaction; } async delete(id: string): Promise { this.transactions.delete(id); } async exists(id: string): Promise { return this.transactions.has(id); } // Test helper clear(): void { this.transactions.clear(); } }