added 2 new endpoints
This commit is contained in:
		@@ -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();
 | 
			
		||||
@@ -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();
 | 
			
		||||
		Reference in New Issue
	
	Block a user