I am looking to retrieve only the user object from the request.
public async getUserByHash(hash: IHash) {
this.logger.log('Hash for check email accessed');
const user = await this.hashRepository.findOne({
select: ['id', 'user'],
relations: ['user'],
where: hash,
});
return user;
}
The user variable now holds the following information.
{
id:2
user: {
id: 3,
email:"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0f6a626e66634f7b6a7c7b216c6062">[email protected]</a>",
password:"12345678"
}
}
I specifically want to retrieve only the user fields, which are the identifier and email.
I attempted to modify it like so but encountered an error.
public async getUserByHash(hash: IHash) {
this.logger.log('Hash for check email accessed');
const user = await this.hashRepository.findOne({
select: ['user.id', 'user.email'],
relations: ['user'],
where: hash,
});
return user;
}
However, I encountered an error message:
QueryFailedError: ER_BAD_FIELD_ERROR: Unknown column 'distinctAlias.Hash_id' in 'field list'
Is there a better way to retrieve only the user fields, such as ID and email?