added endpoints for changing password and username

This commit is contained in:
2024-11-02 01:36:25 +03:00
parent afa1edeb8d
commit 02b1a572d1
3 changed files with 28 additions and 0 deletions

View File

@@ -31,6 +31,14 @@ class UserService {
if (await (this.isInGroup(userId, groupId))) throw new customError(`joinGroup user already in group`, responseCodes.responses.user.already_in_group);
await db.query("UPDATE Users SET groups = array_append(groups, $1::integer) WHERE ID = $2", [groupId, userId]);
}
async changeUsername(userId, username) {
await db.query("UPDATE users SET username = $1 WHERE id = $2", [username, userId]).catch(e => errorHandler(e, "user"));
}
async changePassword(userId, password) {
await db.query("UPDATE users SET password = $1 WHERE id = $2", [bcrypt.hashSync(password, 12), userId])
}
}
export default new UserService();