Method in service.
async loginUser(dto: LoginDto) {
const user = await this.usersRepository.findOne({ where: { uuid: dto.uuid } });
if (!user) {
throw new NotFoundUserException();
}
if (!await user.validatePassword(dto.password)) {
await this.historyService.create({ uuid: dto.uuid, ip: dto.ip }, HistoryType.loginFailure);
throw new IncorrectPasswordException();
}
await this.historyService.create({ uuid: dto.uuid, ip: dto.ip }, HistoryType.loginSuccess);
return user;
}