import { QueryHandler , IQueryHandler } from '@nestjs/cqrs' ; import { InjectRepository } from '@nestjs/typeorm' ; import { RpcException } from '@nestjs/microservices' ; import { ItemEntity } from '@infrastructure/entities' ; import { ItemReadRepository } from '@infrastructure/repositories' ; import { GetItemByIdQuery } from '../../impl' ; @ QueryHandler ( GetItemByIdQuery ) export class GetItemByIdHandler implements IQueryHandler < GetItemByIdQuery > { constructor ( @ InjectRepository ( ItemReadRepository ) private readonly itemReadRepository ) { } async execute ( query ) { const { id } = query ; const item = await this . itemReadRepository . findOne ( id ) ; if ( ! item ) throw new RpcException ( { statusCode : 404 , errorStatus : `Item with ID: ${ id } not found` , } ) ; return item ; } }