From fdd4d22cab5f555f981ba922f5fef9731dbe9e9d Mon Sep 17 00:00:00 2001 From: Shravya Ramesh Date: Tue, 23 Feb 2021 08:38:20 -0800 Subject: added frind button --- src/services/UserFriendsService.ts | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'src/services') diff --git a/src/services/UserFriendsService.ts b/src/services/UserFriendsService.ts index eff18f16..a0bf7ac7 100644 --- a/src/services/UserFriendsService.ts +++ b/src/services/UserFriendsService.ts @@ -86,18 +86,16 @@ export const friendOrUnfriendUser = async ( } }; -export const declineFriendRequestService = async ( - user_id: string, - token: string | null, -) => { +export const addFriendService = async (friend: string, token: string) => { try { - const response = await fetch(FRIENDS_ENDPOINT + `${user_id}/`, { - method: 'DELETE', + const response = await fetch(FRIENDS_ENDPOINT, { + method: 'POST', headers: { + 'Content-Type': 'application/json', Authorization: 'Token ' + token, }, body: JSON.stringify({ - reason: 'declined', + requested: friend, }), }); const status = response.status; @@ -105,12 +103,18 @@ export const declineFriendRequestService = async ( return true; } else { console.log(await response.json()); - Alert.alert(ERROR_SOMETHING_WENT_WRONG_REFRESH); + Alert.alert( + 'Something went wrong! 😭', + "Would you believe me if I told you that I don't know what happened?", + ); return false; } } catch (error) { console.log(error); - Alert.alert(ERROR_SOMETHING_WENT_WRONG_REFRESH); + Alert.alert( + 'Something went wrong! 😭', + "Would you believe me if I told you that I don't know what happened?", + ); return false; } }; @@ -148,18 +152,20 @@ export const acceptFriendRequestService = async ( } }; -export const unfriendService = async ( +export const deleteFriendshipService = async ( user_id: string, + reason: 'declined' | 'cancelled' | 'unfriended', token: string | null, ) => { try { + console.log('deleteFriendshipService!'); const response = await fetch(FRIENDS_ENDPOINT + `${user_id}/`, { method: 'DELETE', headers: { Authorization: 'Token ' + token, }, body: JSON.stringify({ - reason: 'unfriended', + reason, }), }); const status = response.status; -- cgit v1.2.3-70-g09d2