diff options
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; |