diff options
| author | Ivan Chen <ivan@tagg.id> | 2021-03-24 13:25:29 -0400 |
|---|---|---|
| committer | Ivan Chen <ivan@tagg.id> | 2021-03-24 13:25:29 -0400 |
| commit | cc1b5a0be911dc05386a5114e966b7ee4eb21441 (patch) | |
| tree | 90fad5a8ed92206b3026e8fd033b4d35360884f7 /src/services | |
| parent | 96477697afe4dd92ce68f0f778decbca30d83e77 (diff) | |
| parent | 33c107f7382955f6993d8415f08262f51060d178 (diff) | |
Merge branch 'master' into tma698-api-profile
# Conflicts:
# src/components/search/SearchBar.tsx
Diffstat (limited to 'src/services')
| -rw-r--r-- | src/services/UserFriendsService.ts | 68 |
1 files changed, 65 insertions, 3 deletions
diff --git a/src/services/UserFriendsService.ts b/src/services/UserFriendsService.ts index 5ce9df29..da39380f 100644 --- a/src/services/UserFriendsService.ts +++ b/src/services/UserFriendsService.ts @@ -1,9 +1,17 @@ //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 {ERROR_SOMETHING_WENT_WRONG_REFRESH} from '../constants/strings'; +import {ContactType, FriendshipStatusType} from '../types'; +import { + FRIENDS_ENDPOINT, + INVITE_FRIEND_ENDPOINT, + USERS_FROM_CONTACTS_ENDPOINT, +} from '../constants'; +import { + ERROR_SOMETHING_WENT_WRONG, + ERROR_SOMETHING_WENT_WRONG_REFRESH, +} from '../constants/strings'; export const loadFriends = async (userId: string, token: string) => { try { @@ -180,3 +188,57 @@ export const deleteFriendshipService = async ( return false; } }; + +export const usersFromContactsService = async ( + contacts: Array<ContactType>, +) => { + 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, +) => { + const token = await AsyncStorage.getItem('token'); + const response = await fetch(INVITE_FRIEND_ENDPOINT, { + method: 'POST', + headers: { + Authorization: 'Token ' + token, + }, + body: JSON.stringify({ + invitee_phone_number: phoneNumber, + invitee_first_name: inviteeFirstName, + invitee_last_name: inviteeLastName, + }), + }); + if (response.status === 201 || response.status === 200) { + return await response.json(); + } + return false; +}; |
