2022-12-23 14:14:51 +00:00
|
|
|
import { NotFoundException } from '@nestjs/common';
|
2022-12-13 17:00:07 +00:00
|
|
|
import { QueryHandler } from '@nestjs/cqrs';
|
2022-12-23 14:14:51 +00:00
|
|
|
import { LoggingMessager } from '../../adapters/secondaries/logging.messager';
|
2022-12-13 17:00:07 +00:00
|
|
|
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 {
|
2022-12-23 14:14:51 +00:00
|
|
|
constructor(
|
|
|
|
private readonly _repository: UsersRepository,
|
|
|
|
private readonly _loggingMessager: LoggingMessager,
|
|
|
|
) {}
|
2022-12-13 17:00:07 +00:00
|
|
|
|
|
|
|
async execute(findUserByUuid: FindUserByUuidQuery): Promise<User> {
|
2022-12-23 14:14:51 +00:00
|
|
|
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;
|
|
|
|
}
|
2022-12-13 17:00:07 +00:00
|
|
|
}
|
|
|
|
}
|