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.",
};
}
logger.info(`\n\n> New user created ! (${inputData.username}::${currentId})\n`);
logger.info(
`\n\n> New user created ! (${inputData.username}::${currentId})\n`,
);
// JWT
const token = await JwtService.sign(
@ -204,7 +206,7 @@ async function login(inputData: IReqLogin): Promise<ISError | string> {
}
const isPasswordValid = await CredentialService.compare(
inputData.password,
dbUser.hash
dbUser.hash,
);
if (!isPasswordValid) {
return {
@ -215,16 +217,18 @@ async function login(inputData: IReqLogin): Promise<ISError | string> {
const token = await JwtService.sign(
{
sub: dbUser.id,
p: [{
isAdmin: dbUser.is_admin,
gdpr: dbUser.gdpr
}]
p: [
{
isAdmin: dbUser.is_admin,
gdpr: dbUser.gdpr,
},
],
},
{
alg: "HS512",
},
"1d",
"user"
"user",
);
return token;
} catch (err) {
@ -255,34 +259,37 @@ async function getAllUsersService(): Promise<Array<IDbUser> | ISError> {
return allUsers;
} catch (err) {
logger.error(`\n\n${err}\n`);
return {
error: ErrorType.DatabaseError,
message: "An unknown error occurred.",
};
return {
error: ErrorType.DatabaseError,
message: "An unknown error occurred.",
};
}
}
async function editUserService(targetId, inputData: IDbUser): Promise<ISError | boolean> {
async function editUserService(
targetId,
inputData: IDbUser,
): Promise<ISError | boolean> {
if (!targetId || targetId.length !== 36) {
logger.info(`\n\n> Invalid ID (${targetId})\n`);
return {
error: ErrorType.InvalidData,
message: "Invalid ID length.",
};
}
const dbUser = await MySqlService.User.getById(DbHandler, targetId)
logger.info(`\n\n> Invalid ID (${targetId})\n`);
return {
error: ErrorType.InvalidData,
message: "Invalid ID length.",
};
}
const dbUser = await MySqlService.User.getById(DbHandler, targetId);
if (!dbUser.id) {
return {
error: ErrorType.NotFound,
message: "User not found.",
};
error: ErrorType.NotFound,
message: "User not found.",
};
}
const result = await MySqlService.User.update(DbHandler, {
username: inputData.username,
firstname: inputData.firstname,
lastname: inputData.lastname,
dob: inputData.dob,
})
firstname: inputData.firstname,
lastname: inputData.lastname,
dob: inputData.dob,
});
}
/**