Skip to content

Commit

Permalink
feat(friends): GET /user/friends endpoint also shows outgoing frien…
Browse files Browse the repository at this point in the history
…d requests
  • Loading branch information
Likqez committed Dec 2, 2024
1 parent 06ef470 commit 3a824d2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
10 changes: 6 additions & 4 deletions DB/friendships.sql
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,15 @@ END;
$$ LANGUAGE plpgsql;


-- retrieve accepted friendships
-- retrieve accepted friendships aswell as pending friendships where the user is the action_user
CREATE OR REPLACE FUNCTION get_friends(user_id UUID)
RETURNS TABLE
(
friendship_id BIGINT,
friend_id UUID,
created_at TIMESTAMP WITH TIME ZONE,
updated_at TIMESTAMP WITH TIME ZONE
updated_at TIMESTAMP WITH TIME ZONE,
status friendship_status
)
AS
$$
Expand All @@ -153,10 +154,11 @@ BEGIN
ELSE f.user1_id
END AS friend_id,
f.created_at,
f.updated_at
f.updated_at,
f.status
FROM friendships f
WHERE (f.user1_id = user_id OR f.user2_id = user_id)
AND f.status = 'accepted';
AND (f.status = 'accepted' OR (f.status = 'pending' AND f.action_user_id = user_id));
END;
$$ LANGUAGE plpgsql;

Expand Down
1 change: 1 addition & 0 deletions types/api/responses/user.friends.response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export interface GetFriendsResponse {
friend_id: string,
created_at: string
updated_at: string
status: "pending" | "accepted"
}

export interface FriendError {
Expand Down

0 comments on commit 3a824d2

Please sign in to comment.