style(services): improve code readability in user.service file

The user.service has been reformatted for better readability. Changes mainly include adding new lines and spaces to make the code more structured. No change in logic involved, purely cosmetic.

Signed-off-by: Mathis <yidhra@tuta.io>
This commit is contained in:
Mathis H (Avnyr) 2024-04-30 16:52:23 +02:00
parent d7f9cb0b37
commit ae6b25fbd6
Signed by: Mathis
GPG Key ID: DD9E0666A747D126

View File

@ -153,7 +153,9 @@ async function register(inputData: IReqRegister): Promise<ISError | string> {
message: "Error when inserting user in database.", message: "Error when inserting user in database.",
}; };
} }
logger.info(`\n\n> New user created ! (${inputData.username}::${currentId})\n`); logger.info(
`\n\n> New user created ! (${inputData.username}::${currentId})\n`,
);
// JWT // JWT
const token = await JwtService.sign( const token = await JwtService.sign(
@ -204,7 +206,7 @@ async function login(inputData: IReqLogin): Promise<ISError | string> {
} }
const isPasswordValid = await CredentialService.compare( const isPasswordValid = await CredentialService.compare(
inputData.password, inputData.password,
dbUser.hash dbUser.hash,
); );
if (!isPasswordValid) { if (!isPasswordValid) {
return { return {
@ -215,16 +217,18 @@ async function login(inputData: IReqLogin): Promise<ISError | string> {
const token = await JwtService.sign( const token = await JwtService.sign(
{ {
sub: dbUser.id, sub: dbUser.id,
p: [{ p: [
{
isAdmin: dbUser.is_admin, isAdmin: dbUser.is_admin,
gdpr: dbUser.gdpr gdpr: dbUser.gdpr,
}] },
],
}, },
{ {
alg: "HS512", alg: "HS512",
}, },
"1d", "1d",
"user" "user",
); );
return token; return token;
} catch (err) { } catch (err) {
@ -262,7 +266,10 @@ async function getAllUsersService(): Promise<Array<IDbUser> | ISError> {
} }
} }
async function editUserService(targetId, inputData: IDbUser): Promise<ISError | boolean> { async function editUserService(
targetId,
inputData: IDbUser,
): Promise<ISError | boolean> {
if (!targetId || targetId.length !== 36) { if (!targetId || targetId.length !== 36) {
logger.info(`\n\n> Invalid ID (${targetId})\n`); logger.info(`\n\n> Invalid ID (${targetId})\n`);
return { return {
@ -270,7 +277,7 @@ async function editUserService(targetId, inputData: IDbUser): Promise<ISError |
message: "Invalid ID length.", message: "Invalid ID length.",
}; };
} }
const dbUser = await MySqlService.User.getById(DbHandler, targetId) const dbUser = await MySqlService.User.getById(DbHandler, targetId);
if (!dbUser.id) { if (!dbUser.id) {
return { return {
error: ErrorType.NotFound, error: ErrorType.NotFound,
@ -282,7 +289,7 @@ async function editUserService(targetId, inputData: IDbUser): Promise<ISError |
firstname: inputData.firstname, firstname: inputData.firstname,
lastname: inputData.lastname, lastname: inputData.lastname,
dob: inputData.dob, dob: inputData.dob,
}) });
} }
/** /**