diff options
author | Ivan Chen <ivan@thetaggid.com> | 2021-02-23 18:51:50 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-23 18:51:50 -0500 |
commit | a586f89ddd40b1954310673cf86f1b953545d720 (patch) | |
tree | bd8dd6dc89ee583c8decac25b46170bb3ef792ee /src/services/UserFriendsService.ts | |
parent | 5864b997b68ae774a871ee9b43c0e548a2656cc6 (diff) | |
parent | 9bf53a2251f043396fb536800b49e2cf4f811a66 (diff) |
Merge pull request #259 from shravyaramesh/sp-add-friend-button
[TMA-258] Suggested People: Add friend button
Diffstat (limited to 'src/services/UserFriendsService.ts')
-rw-r--r-- | src/services/UserFriendsService.ts | 28 |
1 files changed, 17 insertions, 11 deletions
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; |