import { NotFoundException } from '@nestjs/common'; import { QueryHandler } from '@nestjs/cqrs'; import { LoggingMessager } from '../../adapters/secondaries/logging.messager'; import { UsersRepository } from '../../adapters/secondaries/users.repository'; import { FindUserByUuidQuery } from '../../queries/find-user-by-uuid.query'; import { User } from '../entities/user'; @QueryHandler(FindUserByUuidQuery) export class FindUserByUuidUseCase { constructor( private readonly _repository: UsersRepository, private readonly _loggingMessager: LoggingMessager, ) {} async execute(findUserByUuid: FindUserByUuidQuery): Promise { try { const user = await this._repository.findOneByUuid(findUserByUuid.uuid); if (!user) throw new NotFoundException(); return user; } catch (error) { this._loggingMessager.publish( 'user.read.warning', JSON.stringify({ query: findUserByUuid, error, }), ); throw error; } } }