feat(services): add getByEmailService
to user.service.ts
A new method `getByEmailService` has been added to `user.service.ts`. This method retrieves a user from the database by their email. The tracing log adjustment has also been performed, where logging only happens when it's in debug mode. If there are multiple users with the same email, this method will return the first user. Issue: #18 Signed-off-by: Mathis <yidhra@tuta.io>
This commit is contained in:
parent
abaeafea8a
commit
3d3da77df0
@ -245,14 +245,21 @@ async function login(inputData: IReqLogin): Promise<ISError | string> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a user from the database by email.
|
||||
*
|
||||
* @param {string} email - The email associated with the user.
|
||||
* @return {Promise<IDbUser | false>} - A Promise that resolves to the user (if found) or false (if not found).
|
||||
*/
|
||||
async function getByEmailService(email: string): Promise<IDbUser | false> {
|
||||
const dbUser = await MySqlService.User.getByEmail(DbHandler, email);
|
||||
if (dbUser === undefined) {
|
||||
logger.trace(`\n\n> User not found in DB (${email})\n`);
|
||||
if (dbUser.length === 0) {
|
||||
if (isDebugMode()) logger.trace(`\n\n> User not found in DB (${email})\n`);
|
||||
return false;
|
||||
}
|
||||
logger.trace(dbUser);
|
||||
return dbUser;
|
||||
if (isDebugMode()) logger.trace(dbUser);
|
||||
if (dbUser.length > 1 && dbUser[0]) return dbUser[0];
|
||||
return false;
|
||||
}
|
||||
|
||||
//TOTest
|
||||
|
Loading…
x
Reference in New Issue
Block a user