diff options
| author | Ivan Chen <ivan@thetaggid.com> | 2021-02-20 12:27:45 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-20 12:27:45 -0500 |
| commit | eae63e4a336785ae45cd01c4448a8444a7793613 (patch) | |
| tree | 08aeb9ce90be7ca69b56923bab6c34871b3a793a /src/services/SuggestedPeopleService.ts | |
| parent | 4b8130932b943afe9fdf63c611f1897622ab795e (diff) | |
| parent | 82fc3c7ded1022a31cd532d469457d77f9214cc8 (diff) | |
Merge pull request #248 from IvanIFChen/tma258-sp-pagination-2
[TMA-258] SP Pagination
Diffstat (limited to 'src/services/SuggestedPeopleService.ts')
| -rw-r--r-- | src/services/SuggestedPeopleService.ts | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/src/services/SuggestedPeopleService.ts b/src/services/SuggestedPeopleService.ts index 525c68b1..34a31662 100644 --- a/src/services/SuggestedPeopleService.ts +++ b/src/services/SuggestedPeopleService.ts @@ -1,10 +1,10 @@ import AsyncStorage from '@react-native-community/async-storage'; import { EDIT_PROFILE_ENDPOINT, - SP_BASE_ENDPOINT, - SP_UPDATE_PICTURE, + SP_UPDATE_PICTURE_ENDPOINT, + SP_USERS_ENDPOINT } from '../constants'; -import {SuggestedPeopleDataType} from '../types'; +import { SuggestedPeopleDataType } from '../types'; export const sendSuggestedPeopleLinked = async ( userId: string, @@ -39,7 +39,7 @@ export const sendSuggestedPeoplePhoto = async (photoUri: string) => { name: 'sp_photo.jpg', type: 'image/jpg', }); - const response = await fetch(SP_UPDATE_PICTURE, { + const response = await fetch(SP_UPDATE_PICTURE_ENDPOINT, { method: 'POST', headers: { 'Content-Type': 'multipart/form-data', @@ -54,10 +54,33 @@ export const sendSuggestedPeoplePhoto = async (photoUri: string) => { } }; +export const getSuggestedPeople = async (limit: number, offset: number) => { + try { + const token = await AsyncStorage.getItem('token'); + const url = `${SP_USERS_ENDPOINT}?limit=${limit}&offset=${offset}`; + const response = await fetch(url, { + method: 'GET', + headers: { + Authorization: 'Token ' + token, + }, + }); + if (response.status !== 200) { + throw 'Non-200 response'; + } + const data = await response.json(); + const typedData: SuggestedPeopleDataType[] = data.results; + return typedData; + } catch (error) { + console.log('Error fetching SP user data'); + console.log(error); + return []; + } +}; + export const getSuggestedPeopleProfile = async (userId: string) => { try { const token = await AsyncStorage.getItem('token'); - const response = await fetch(SP_BASE_ENDPOINT + userId + '/', { + const response = await fetch(SP_USERS_ENDPOINT + userId + '/', { method: 'GET', headers: { Authorization: 'Token ' + token, @@ -73,4 +96,3 @@ export const getSuggestedPeopleProfile = async (userId: string) => { console.log('Error retrieving SP info'); return undefined; } -}; |
