import { Injectable } from '@nestjs/common' ; import { EventPublisher } from '@nestjs/cqrs' ; import { EventStore } from '../../../core/eventstore/eventstore' ; import { Users } from '../../domain/repository/users' ; import { User } from '../../domain/model/user' ; import { UserId } from '../../domain/model/user-id' ; @ Injectable ( ) export class UserEventStore implements Users { constructor ( private readonly eventStore , private readonly publisher ) { } async get ( userId ) { return this . eventStore . read ( User , userId . value ) ; } async find ( userId ) { return this . eventStore . read ( User , userId . value ) ; } save ( user ) { user = this . publisher . mergeObjectContext ( user ) ; user . commit ( ) ; } }