import { Inject } from '@nestjs/common' ; import { EventsHandler , IEventHandler } from '@nestjs/cqrs' ; import { Model } from 'mongoose' ; import { GroupNameWasChanged } from '../../../domain/event' ; import { GroupView } from '../schema/group.schema' ; @ EventsHandler ( GroupNameWasChanged ) export class GroupWasRenamedProjection implements IEventHandler < GroupNameWasChanged > { constructor ( @ Inject ( 'GROUP_MODEL' ) private readonly groupModel ) { } async handle ( event ) { this . groupModel . updateOne ( { _id : event . id } , { name : event . name } ) . exec ( ) ; } }