aboutsummaryrefslogtreecommitdiff
path: root/src/services/UserProfileService.ts
diff options
context:
space:
mode:
authorIvan Chen <ivan@tagg.id>2021-03-26 20:01:26 -0400
committerIvan Chen <ivan@tagg.id>2021-03-26 20:01:26 -0400
commited26661062a2e47df2662254eaddfcfa1de62d04 (patch)
tree78e1683c60ba65a1d71631838be500e1f54607f6 /src/services/UserProfileService.ts
parent5b975a354f0707c0671571387d5bda501fbe75ae (diff)
parentbef5728b24a71d1bf327a72e425346020a997037 (diff)
Merge branch 'master' into tma-722-cornell-fe
# Conflicts: # src/types/types.ts
Diffstat (limited to 'src/services/UserProfileService.ts')
-rw-r--r--src/services/UserProfileService.ts48
1 files changed, 40 insertions, 8 deletions
diff --git a/src/services/UserProfileService.ts b/src/services/UserProfileService.ts
index e00c0530..085787c3 100644
--- a/src/services/UserProfileService.ts
+++ b/src/services/UserProfileService.ts
@@ -2,6 +2,7 @@ import AsyncStorage from '@react-native-community/async-storage';
import moment from 'moment';
import {Alert} from 'react-native';
import {
+ EDIT_PROFILE_ENDPOINT,
GET_FB_POSTS_ENDPOINT,
GET_IG_POSTS_ENDPOINT,
GET_TWITTER_POSTS_ENDPOINT,
@@ -296,16 +297,19 @@ export const sendRegister = async (
password: string,
) => {
try {
+ const form = new FormData();
+ form.append('first_name', firstName);
+ form.append('last_name', lastName);
+ form.append('email', email);
+ form.append('phone_number', phone);
+ form.append('username', username);
+ form.append('password', password);
const response = await fetch(REGISTER_ENDPOINT, {
method: 'POST',
- body: JSON.stringify({
- first_name: firstName,
- last_name: lastName,
- email: email,
- phone_number: phone,
- username: username,
- password: password,
- }),
+ headers: {
+ 'Content-Type': 'multipart/form-data',
+ },
+ body: form,
});
return response;
} catch (error) {
@@ -334,3 +338,31 @@ export const fetchUserProfile = async (userId: string, token?: string) => {
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;
+ }
+};