From 3a824d23f158dda77c810818c614a73ed9502483 Mon Sep 17 00:00:00 2001 From: Lukas Lanzner Date: Mon, 2 Dec 2024 20:43:11 +0100 Subject: [PATCH] feat(friends): GET `/user/friends` endpoint also shows outgoing friend requests --- DB/friendships.sql | 10 ++++++---- types/api/responses/user.friends.response.ts | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/DB/friendships.sql b/DB/friendships.sql index 03eabcf..9149339 100644 --- a/DB/friendships.sql +++ b/DB/friendships.sql @@ -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 $$ @@ -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; diff --git a/types/api/responses/user.friends.response.ts b/types/api/responses/user.friends.response.ts index fdb083f..d409702 100644 --- a/types/api/responses/user.friends.response.ts +++ b/types/api/responses/user.friends.response.ts @@ -3,6 +3,7 @@ export interface GetFriendsResponse { friend_id: string, created_at: string updated_at: string + status: "pending" | "accepted" } export interface FriendError {