diff options
Diffstat (limited to 'src/services/UserFriendsService.ts')
-rw-r--r-- | src/services/UserFriendsService.ts | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/services/UserFriendsService.ts b/src/services/UserFriendsService.ts index f2e15824..99d86d0b 100644 --- a/src/services/UserFriendsService.ts +++ b/src/services/UserFriendsService.ts @@ -147,3 +147,32 @@ export const acceptFriendRequestService = async ( return false; } }; + +export const unfriendService = async ( + user_id: string, + token: string | null, +) => { + try { + const response = await fetch(FRIENDS_ENDPOINT + `${user_id}/`, { + method: 'DELETE', + headers: { + Authorization: 'Token ' + token, + }, + body: JSON.stringify({ + reason: 'unfriended', + }), + }); + const status = response.status; + if (Math.floor(status / 100) === 2) { + return true; + } else { + console.log(await response.json()); + Alert.alert(ERROR_SOMETHING_WENT_WRONG_REFRESH); + return false; + } + } catch (error) { + console.log(error); + Alert.alert(ERROR_SOMETHING_WENT_WRONG_REFRESH); + return false; + } +}; |