diff options
author | Ivan Chen <ivan@tagg.id> | 2021-03-25 14:43:21 -0400 |
---|---|---|
committer | Ivan Chen <ivan@tagg.id> | 2021-03-25 14:43:21 -0400 |
commit | c4047f0bd2293437373c19e84266cd8d010adc3c (patch) | |
tree | 6c7704d125f5bf31f67e709521852264d125bc8a /src/services/UserProfileService.ts | |
parent | e240ab56296ddbcd6a5407f0307d4400f734e27f (diff) |
refactored editprofile endpoint
Diffstat (limited to 'src/services/UserProfileService.ts')
-rw-r--r-- | src/services/UserProfileService.ts | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/services/UserProfileService.ts b/src/services/UserProfileService.ts index dd77db9f..041dd4c3 100644 --- a/src/services/UserProfileService.ts +++ b/src/services/UserProfileService.ts @@ -3,6 +3,7 @@ import moment from 'moment'; import {Alert} from 'react-native'; import RNFetchBlob from 'rn-fetch-blob'; import { + EDIT_PROFILE_ENDPOINT, GET_FB_POSTS_ENDPOINT, GET_IG_POSTS_ENDPOINT, GET_TWITTER_POSTS_ENDPOINT, @@ -356,3 +357,31 @@ export const sendRegister = async ( return undefined; } }; + +export const patchEditProfile = async (form: FormData, userId: string) => { + const endpoint = EDIT_PROFILE_ENDPOINT + `${userId}/`; + try { + const token = await AsyncStorage.getItem('token'); + let response = await fetch(endpoint, { + method: 'PATCH', + headers: { + 'Content-Type': 'multipart/form-data', + Authorization: 'Token ' + token, + }, + body: form, + }); + let statusCode = response.status; + if (statusCode === 200) { + return true; + } else if (statusCode === 400) { + let data = await response.json(); + throw ( + 'Profile update failed. 😔' + data.error || 'Something went wrong! ðŸ˜' + ); + } else { + throw ERROR_SOMETHING_WENT_WRONG_REFRESH; + } + } catch (error) { + throw ERROR_DOUBLE_CHECK_CONNECTION; + } +}; |