import { Controller } from '@nestjs/common'; import { QueryBus } from '@nestjs/cqrs'; import { GrpcMethod, RpcException } from '@nestjs/microservices'; import { FindUserByUuidRequest } from '../../domain/dto/findUserByUuidRequest'; import { User } from '../../domain/entities/user'; import { FindUserByUuidQuery } from '../../queries/find-user-by-uuid.query'; @Controller() export class UsersController { constructor(private readonly _queryBus: QueryBus) {} @GrpcMethod('UsersService', 'FindOneByUuid') async findOneByUuid(data: FindUserByUuidRequest): Promise { const user = await this._queryBus.execute( new FindUserByUuidQuery(data.uuid), ); if (user) { return user; } throw new RpcException({ code: 5, message: 'User not found', }); } }