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:
Mathis H (Avnyr) 2024-05-02 14:25:10 +02:00
parent abaeafea8a
commit 3d3da77df0
Signed by: Mathis
GPG Key ID: DD9E0666A747D126

View File

@ -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