aboutsummaryrefslogtreecommitdiff
path: root/src/services/UserFriendsService.ts
diff options
context:
space:
mode:
authorShravya Ramesh <shravs1208@gmail.com>2021-02-23 08:38:20 -0800
committerShravya Ramesh <shravs1208@gmail.com>2021-02-23 08:38:20 -0800
commitfdd4d22cab5f555f981ba922f5fef9731dbe9e9d (patch)
tree2167e4862777a14f16df04b461216603c9ceb9eb /src/services/UserFriendsService.ts
parent7692a4321af074158f75c96b8aa3b71dbf9e3bb5 (diff)
added frind button
Diffstat (limited to 'src/services/UserFriendsService.ts')
-rw-r--r--src/services/UserFriendsService.ts28
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;