added 2 new endpoints

This commit is contained in:
2024-11-02 21:51:29 +03:00
parent 07ffeb8de4
commit 317fba81aa
7 changed files with 38 additions and 8 deletions

View File

@@ -29,10 +29,14 @@ class GroupService {
}
async getByName(name) {
let res = (await db.query("SELECT * FROM groups WHERE name = $1", [name]));
let res = (await db.query("SELECT id FROM groups WHERE name = $1", [name]));
if (res.rowCount == 0) throw new customError(`getByName group not found`, responseCodes.responses.groups.name_not_found);
return res.rows[0];
}
async getUsersInGroup(groupId) {
return (await db.query("SELECT id FROM users WHERE $1 = ANY(groups)", [groupId])).rows.map((group) => group.id)
}
};
export default new GroupService();

View File

@@ -39,6 +39,10 @@ class UserService {
async changePassword(userId, password) {
await db.query("UPDATE users SET password = $1 WHERE id = $2", [bcrypt.hashSync(password, 12), userId])
}
async getAllGroupsForUser(userId) {
return (await db.query("SELECT groups FROM users WHERE id = $1", [userId])).rows[0].groups
}
}
export default new UserService();