user/src/modules/users/adapters/primaries/users.controller.ts

26 lines
805 B
TypeScript
Raw Normal View History

2022-12-13 17:00:07 +00:00
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<User> {
const user = await this._queryBus.execute(
new FindUserByUuidQuery(data.uuid),
);
if (user) {
return user;
}
throw new RpcException({
code: 5,
message: 'User not found',
});
}
}