import { Injectable } from '@nestjs/common' ; import { EventPublisher } from '@nestjs/cqrs' ; import { EventStore } from '../../../core/eventstore/eventstore' ; import { Transactions } from '../../domain/repository/transactions' ; import { DepositTransaction } from '../../domain/model/deposit-transaction' ; import { DebtTransaction } from '../../domain/model/debt-transaction' ; import { TransactionId } from '../../domain/model/transaction-id' ; import { TransferTransaction } from '../../domain/model/transfer-transaction' ; @ Injectable ( ) export class TransactionEventStore implements Transactions { constructor ( private readonly eventStore , private readonly publisher ) { } async getDepositTransaction ( transactionId ) { return this . eventStore . read ( DepositTransaction , transactionId . value ) ; } async findDepositTransaction ( transactionId ) { return this . eventStore . read ( DepositTransaction , transactionId . value ) ; } saveDepositTransaction ( depositTransaction ) { depositTransaction = this . publisher . mergeObjectContext ( depositTransaction ) ; depositTransaction . commit ( ) ; } async getDebtTransaction ( transactionId ) { return this . eventStore . read ( DebtTransaction , transactionId . value ) ; } async findDebtTransaction ( transactionId ) { return this . eventStore . read ( DebtTransaction , transactionId . value ) ; } saveDebtTransaction ( debtTransaction ) { debtTransaction = this . publisher . mergeObjectContext ( debtTransaction ) ; debtTransaction . commit ( ) ; } async getTransferTransaction ( transactionId ) { return this . eventStore . read ( TransferTransaction , transactionId . value ) ; } async findTransferTransaction ( transactionId ) { return this . eventStore . read ( TransferTransaction , transactionId . value ) ; } saveTransferTransaction ( transferTransaction ) { transferTransaction = this . publisher . mergeObjectContext ( transferTransaction ) ; transferTransaction . commit ( ) ; } }