aboutsummaryrefslogtreecommitdiff
path: root/src/services/UserProfileService.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/services/UserProfileService.ts')
-rw-r--r--src/services/UserProfileService.ts29
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;
+ }
+};