From 4844b69ed6c381fe8e573e77d32302965c4de274 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Tue, 23 Mar 2021 16:18:19 -0400 Subject: updated types, using api/profile --- src/services/UserProfileService.ts | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'src/services') diff --git a/src/services/UserProfileService.ts b/src/services/UserProfileService.ts index de24d2d6..e733cb47 100644 --- a/src/services/UserProfileService.ts +++ b/src/services/UserProfileService.ts @@ -7,6 +7,7 @@ import { GET_TWITTER_POSTS_ENDPOINT, HEADER_PHOTO_ENDPOINT, PASSWORD_RESET_ENDPOINT, + USER_PROFILE_ENDPOINT, PROFILE_INFO_ENDPOINT, PROFILE_PHOTO_ENDPOINT, REGISTER_ENDPOINT, @@ -25,7 +26,7 @@ import { SUCCESS_PWD_RESET, SUCCESS_VERIFICATION_CODE_SENT, } from '../constants/strings'; -import {SocialAccountType} from '../types'; +import {SocialAccountType, ProfileType} from '../types'; export const loadProfileInfo = async (token: string, userId: string) => { try { @@ -333,3 +334,24 @@ export const sendRegister = async ( return undefined; } }; + +export const fetchUserProfile = async (userId: string, token?: string) => { + try { + if (!token) { + token = (await AsyncStorage.getItem('token')) ?? ''; + } + const response = await fetch(USER_PROFILE_ENDPOINT + userId + '/', { + method: 'GET', + headers: { + Authorization: 'Token ' + token, + }, + }); + if (response.status === 200) { + const data: ProfileType = await response.json(); + return data; + } + } catch (error) { + console.log(error); + return undefined; + } +}; -- cgit v1.2.3-70-g09d2