aboutsummaryrefslogtreecommitdiff
path: root/src/services/UserFriendsService.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/services/UserFriendsService.ts')
-rw-r--r--src/services/UserFriendsService.ts67
1 files changed, 65 insertions, 2 deletions
diff --git a/src/services/UserFriendsService.ts b/src/services/UserFriendsService.ts
index dbec1974..86339868 100644
--- a/src/services/UserFriendsService.ts
+++ b/src/services/UserFriendsService.ts
@@ -1,8 +1,13 @@
//Abstracted common friends api calls out here
+import AsyncStorage from '@react-native-community/async-storage';
import {Alert} from 'react-native';
-import {FriendshipStatusType} from '../types';
-import {FRIENDS_ENDPOINT} from '../constants';
+import {ContactType, FriendshipStatusType} from '../types';
+import {
+ FRIENDS_ENDPOINT,
+ INVITE_FRIEND_ENDPOINT,
+ USERS_FROM_CONTACTS_ENDPOINT,
+} from '../constants';
import {ERROR_SOMETHING_WENT_WRONG_REFRESH} from '../constants/strings';
export const loadFriends = async (userId: string, token: string) => {
@@ -181,3 +186,61 @@ export const deleteFriendshipService = async (
return false;
}
};
+
+export const usersFromContactsService = async (
+ contacts: Array<ContactType>,
+) => {
+ console.log('Contacts: ', contacts);
+ try {
+ const token = await AsyncStorage.getItem('token');
+ const response = await fetch(USERS_FROM_CONTACTS_ENDPOINT, {
+ method: 'POST',
+ headers: {
+ Authorization: 'Token ' + token,
+ },
+ body: JSON.stringify({
+ contacts: contacts,
+ }),
+ });
+ const status = response.status;
+ if (Math.floor(status / 100) === 2) {
+ const users_data = await response.json();
+ return users_data;
+ } else {
+ console.log(
+ 'Something went wrong! 😭',
+ 'Not able to retrieve tagg users list',
+ );
+ }
+ } catch (error) {
+ console.log(error);
+ Alert.alert(ERROR_SOMETHING_WENT_WRONG_REFRESH);
+ return false;
+ }
+};
+
+export const inviteFriendService = async (
+ phoneNumber: string,
+ inviteeFirstName: string,
+ inviteeLastName: string,
+ inviterFullName: string,
+) => {
+ const token = await AsyncStorage.getItem('token');
+ const response = await fetch(INVITE_FRIEND_ENDPOINT, {
+ method: 'POST',
+ headers: {
+ Authorization: 'Token ' + token,
+ },
+ body: JSON.stringify({
+ phone_number: phoneNumber,
+ invitee_first_name: inviteeFirstName,
+ invitee_last_name: inviteeLastName,
+ inviter_full_name: inviterFullName,
+ }),
+ });
+ if (response.status === 201) {
+ const response_body = await response.json();
+ return response_body;
+ }
+ return false;
+};