diff --git a/client-new/src/components/filecollection/FileList.tsx b/client-new/src/components/filecollection/FileList.tsx index 840b8a2..424bc1f 100644 --- a/client-new/src/components/filecollection/FileList.tsx +++ b/client-new/src/components/filecollection/FileList.tsx @@ -7,19 +7,20 @@ import { widthPercentageToDP as w } from 'react-native-responsive-screen'; -import FileIcon from '../icons/FileIcon'; import FileRow from './FileRow'; type FileListProps = { files: IFile[]; }; -export default function FileList(props: FileListProps) { +const FileList: React.FC = ({ files }) => { return ( - {props.files.map((file, index) => ( + {files?.filter((file) => file.file_name !== undefined).map((file) => ( ))} ); } + +export default FileList; \ No newline at end of file diff --git a/client-new/src/components/filecollection/FileRow.tsx b/client-new/src/components/filecollection/FileRow.tsx index 97bf7e7..c9ede89 100644 --- a/client-new/src/components/filecollection/FileRow.tsx +++ b/client-new/src/components/filecollection/FileRow.tsx @@ -22,8 +22,8 @@ type FileRowProps = { const FileRow: React.FC = ({ file }) => { const size = ConvertFileSize(file.file_size); const { 0: fileName, 1: fileEnding } = file.file_name.split('.'); - const truncatedName = fileName.length > 40 ? fileName.substring(0, 40) + '...' + fileEnding : fileName + '.' + fileEnding; - const date = RelativeTime(new Date(file.created_at)); + const truncatedName = fileName.length > 40 ? fileName.substring(0, 40) + '...' : fileName + '.' + fileEnding; + // const date = RelativeTime(new Date(file.created_at)); const handlePress = async () => { const url = await fetchFileURL(file.id); @@ -45,32 +45,32 @@ const FileRow: React.FC = ({ file }) => { return ( handlePress()}> - - - - + + + + - - {truncatedName} - 1 item ∙ {size} - {/* Created {date.toString()} */} - - - + + {truncatedName} + 1 item ∙ {size} + {/* Created {date.toString()} */} + + + + - ); } diff --git a/client-new/src/components/icons/FileIcon.tsx b/client-new/src/components/icons/FileIcon.tsx index 7b29fc5..84aa4aa 100644 --- a/client-new/src/components/icons/FileIcon.tsx +++ b/client-new/src/components/icons/FileIcon.tsx @@ -17,7 +17,6 @@ const FileIcon = (props) => ( xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" - fill="none" viewBox={`0 0 ${originalWidth} ${originalHeight}`} {...props} > diff --git a/client-new/src/components/reusable/CircleProgress.tsx b/client-new/src/components/reusable/CircleProgress.tsx index 307401a..6432548 100644 --- a/client-new/src/components/reusable/CircleProgress.tsx +++ b/client-new/src/components/reusable/CircleProgress.tsx @@ -45,7 +45,7 @@ const CircleProgress = ({ progress }) => { strokeDashoffset={animatedValue.interpolate({ inputRange: [0, 100], outputRange: [circumference, progressStrokeDashoffset], - })} + })} strokeLinecap="round" fill="none" transform="rotate(-90 50 50)" diff --git a/client-new/src/contexts/ProfileContext.tsx b/client-new/src/contexts/ProfileContext.tsx index ff5a77a..2038702 100644 --- a/client-new/src/contexts/ProfileContext.tsx +++ b/client-new/src/contexts/ProfileContext.tsx @@ -77,6 +77,7 @@ export const ProfileProvider: React.FC = ({ console.log('[profile context] fetched profile', fetchedProfile); if (fetchedProfile) { setProfile(fetchedProfile); + console.log('[profile context] fetched profile completed onboarding', fetchedProfile?.completed_onboarding_response) setCompletedOnboarding(fetchedProfile?.completed_onboarding_response) await setItemAsync('profile', JSON.stringify(fetchedProfile)); await setItemAsync('completedOnboarding', JSON.stringify(fetchedProfile?.completed_onboarding_response || false)) diff --git a/client-new/src/navigation/Router.tsx b/client-new/src/navigation/Router.tsx index 8f5b4b6..e468655 100644 --- a/client-new/src/navigation/Router.tsx +++ b/client-new/src/navigation/Router.tsx @@ -5,21 +5,23 @@ import AuthStack from '@/navigation/AuthStack'; import { NavigationContainer } from '@react-navigation/native'; import React from 'react'; -import { View, Text } from 'react-native'; +import { ActivityIndicator, Text } from 'react-native'; +import { View } from 'native-base'; export default function Router() { - const { completedOnboarding } = useProfile(); + const { profile, completedOnboarding } = useProfile(); - console.log('completedOnboarding', completedOnboarding); - - if (completedOnboarding === null) { + if (completedOnboarding == undefined || profile == undefined) { return ( - - Loading... + + - ) + ); } + console.log('[router] completedOnboarding profile', profile.completed_onboarding_response); + console.log('[router] completedOnboarding', completedOnboarding); + return ( {completedOnboarding ? : } diff --git a/client-new/src/screens/app/BottomTabNavigator.tsx b/client-new/src/screens/app/BottomTabNavigator.tsx index 7f94b92..1352261 100644 --- a/client-new/src/screens/app/BottomTabNavigator.tsx +++ b/client-new/src/screens/app/BottomTabNavigator.tsx @@ -11,7 +11,6 @@ import FileCollectionScreen from './FileCollectionScreen'; import GuideScreen from './GuideScreen'; import HomeScreen from './HomeScreen'; import MapScreen from './MarketplaceScreen'; -import ProfileScreen from './ProfileScreen'; import TaskScreen from './TaskScreen'; import ProfileStack from '@/navigation/ProfileStack'; diff --git a/client-new/src/screens/app/FileCollectionScreen.tsx b/client-new/src/screens/app/FileCollectionScreen.tsx index 4287c80..1b2c049 100644 --- a/client-new/src/screens/app/FileCollectionScreen.tsx +++ b/client-new/src/screens/app/FileCollectionScreen.tsx @@ -22,40 +22,12 @@ export default function FileCollectionScreen() { const [filter, setFilter] = useState(null); const { isPending, data: files, error, refetch } = useQuery({ - queryKey: ['userFiles', user?.id, filter], + queryKey: ['userfiles', user?.id, filter], queryFn: () => fetchUserFilesList(user.id, filter), // staleTime: 60000 // TEMP, unsolved refetch when unncessary }); console.log('Query Key:', ['userFiles', user?.id, filter]); - if (isPending) { - return ( - < View - flex={1} - justifyContent={'center'} - alignItems={'center'} - bg={'#FFF9EE'} - > - - - - ); - } - - if (error) { - return ( - < View - flex={1} - justifyContent={'center'} - alignItems={'center'} - bg={'#FFF9EE'} - > - Error! - {error.message} - - ); - } - return ( @@ -86,9 +58,10 @@ export default function FileCollectionScreen() { tintColor={'#ff0000'} /> }> - + {isPending && } + {error && Error: {error.message}} + {files && files.length === 0 && No files found} + {files && } diff --git a/client-new/src/screens/app/HomeScreen.tsx b/client-new/src/screens/app/HomeScreen.tsx index c0abf90..516ede2 100644 --- a/client-new/src/screens/app/HomeScreen.tsx +++ b/client-new/src/screens/app/HomeScreen.tsx @@ -49,11 +49,7 @@ export default function HomeScreen({ navigation }) { tintColor={'#ff0000'} /> } - > - + > diff --git a/client-new/src/screens/app/ProfileScreen.tsx b/client-new/src/screens/app/ProfileScreen.tsx deleted file mode 100644 index 873ac48..0000000 --- a/client-new/src/screens/app/ProfileScreen.tsx +++ /dev/null @@ -1,3 +0,0 @@ -export default function ProfileScreen() { - return <>; -} diff --git a/client-new/src/screens/app/profile/AllPersonasScreen.tsx b/client-new/src/screens/app/profile/AllPersonasScreen.tsx index 98fc45b..702f201 100644 --- a/client-new/src/screens/app/profile/AllPersonasScreen.tsx +++ b/client-new/src/screens/app/profile/AllPersonasScreen.tsx @@ -1,6 +1,6 @@ -import {View, Text} from "native-base"; +import { View, Text, ScrollView } from "native-base"; import {SafeAreaView} from "react-native-safe-area-context"; -import {Pressable} from "react-native"; +import { ActivityIndicator, Pressable } from "react-native"; import Svg, {Path} from "react-native-svg"; import {useEffect, useState} from "react"; import { IPersona } from "@/interfaces/IPersona"; @@ -12,15 +12,14 @@ import { } from "react-native-responsive-screen"; import React from "react"; import LegacyWordmarkWithBackArrow from "@/components/reusable/LegacyWordMarkWithBackArrow"; +import { useQuery } from "@tanstack/react-query"; /** * Screen to render all personas * @param route and navigation are props passed in by the react navigation stack * @returns All Peronas Screen */ -export default function AllPersonasScreen({route, navigation}) { - const [personas, setPersonas] = useState([]); - +export default function AllPersonasScreen({ route, navigation }) { /** * Sends user to the persona screen. Must pass in title and description of the persona. * @param title Title of persona @@ -36,58 +35,50 @@ export default function AllPersonasScreen({route, navigation}) { * Fetch all data for this screen: * - All personas */ - const fetchData = async () => { - try { - const personasData = await getAllPersonas(); - setPersonas(personasData); - } catch (error) { - console.log(error); - } - }; + const { isPending, data: personas, error } = useQuery({ + queryKey: ["allPersonas"], + queryFn: async () => await getAllPersonas(), + }); - /** - * Load in all personas on first render - */ - useEffect(() => { - fetchData(); - }, []); return ( - - navigation.navigate("My Persona Screen")} - /> - - All Personas - - {personas.map((value, index) => ( - - - toPersona(value.persona_title, value.persona_description) - } - /> - - ))} - + + + navigation.navigate("My Persona Screen")} /> + + All Personas + + {isPending && } + {error && Something went wrong ...} + {personas?.map((value, index) => ( + + + toPersona(value.persona_title, value.persona_description) + } + /> + + ))} + + ); } diff --git a/client-new/src/screens/app/profile/MyPersonaScreen.tsx b/client-new/src/screens/app/profile/MyPersonaScreen.tsx index 51a0e38..997e96f 100644 --- a/client-new/src/screens/app/profile/MyPersonaScreen.tsx +++ b/client-new/src/screens/app/profile/MyPersonaScreen.tsx @@ -6,27 +6,22 @@ import { getPersona } from "@/services/ProfileService"; import { IPersona } from "@/interfaces/IPersona"; import React , {useEffect, useState} from "react"; import ScreenWideButton from "@/components/reusable/ScreenWideButton"; +import { useUser } from "@/contexts/UserContext"; +import { useQuery } from "@tanstack/react-query"; +import { ActivityIndicator } from "react-native"; -const mockUser = { - id: "1", -}; export default function MyPersonaScreen({route, navigation}) { + const { user } = useUser(); const [myPersona, setMyPersona] = useState(undefined); - /** - * Fetches the persona of the current user - */ - const fetchMyPersona = async () => { - const myPersona = await getPersona(mockUser.id); - setMyPersona(myPersona); - }; /** - * Loads and displays the persona of the current user + * Fetches the persona of the current user */ - useEffect(() => { - fetchMyPersona(); - }, []); + const { isPending, data: persona, error } = useQuery({ + queryKey: ['persona', user?.id], + queryFn: async () => await getPersona(user?.id) + }); return ( You are an - + {isPending && } + {error && Something went wrong ...} + {persona && ( + + )} (null); - const [shareModal, setShareModal] = useState(false); + const { user, logout } = useUser(); + const { setCompletedOnboarding } = useProfile(); /** * Fetch all data for this screen: * - My Persona */ - const fetchData = async () => { - const persona = await getPersona(userID); - setMyPersona(persona); + const { isPending, data: persona, error } = useQuery({ + queryKey: ['persona', user?.id], + queryFn: async () => await getPersona(user?.id) + }); + + const handleLogout = () => { + Alert.alert( + 'Logout', + 'Are you sure you want to logout?', + [ + { + text: 'Cancel', + style: 'cancel', + onPress: () => console.log('Cancel Pressed') + }, + { + text: 'Logout', + style: 'destructive', + onPress: () => { + logout() + setCompletedOnboarding(false); + } + } + ], + { cancelable: false } + ); + }; - /** - * Load in data on first render - */ - useEffect(() => { - fetchData(); - }, []); + const handleDeleteAccount = () => { + Alert.alert( + 'Delete Account', + 'Are you sure you want to delete your account?', + [ + { + text: 'Cancel', + style: 'cancel', + onPress: () => console.log('Cancel Pressed') + }, + { + text: 'Delete', + style: 'destructive', + onPress: () => console.log('Delete Pressed') + } + ], + { cancelable: false } + ); + } + + const handleShare = () => { + Alert.alert( + 'Share Legacy', + 'Share Legacy with your friends!', + [ + { + text: 'Cancel', + style: 'cancel', + onPress: () => console.log('Cancel Pressed') + }, + { + text: 'Share', + style: 'default', + onPress: () => console.log('Share Pressed') + } + ], + { cancelable: false } + ); + } return ( - + {}} /> Profile - navigation.navigate('My Persona Screen')} - /> + {isPending && } + {error && Something went wrong...} + {persona && ( + navigation.navigate('My Persona Screen')} + /> + )} setShareModal(true)} + handleOnPress={() => handleShare()} /> - {shareModal && ( - - - - {'SHARE / RATE APP'} - - - - )} + + {/* {shareModal && ( */} + {/* // / */} + {/* */} + {/* )} */} + + + + + + ); } diff --git a/client-new/src/screens/auth/LoginScreen.tsx b/client-new/src/screens/auth/LoginScreen.tsx index 2cf0292..74d9a31 100644 --- a/client-new/src/screens/auth/LoginScreen.tsx +++ b/client-new/src/screens/auth/LoginScreen.tsx @@ -52,9 +52,6 @@ export default function LoginScreen({ route, navigation }) { setPassword(''); return; } - - console.log('HIT'); - navigation.navigate('Onboarding Stack'); } handleLogin(); diff --git a/client-new/src/screens/auth/PersonaScreen.tsx b/client-new/src/screens/auth/PersonaScreen.tsx index 213fc5f..b286099 100644 --- a/client-new/src/screens/auth/PersonaScreen.tsx +++ b/client-new/src/screens/auth/PersonaScreen.tsx @@ -43,7 +43,7 @@ const PersonaScreen = ({ route, navigation }) => { // go to app await initalizeAllProgress(user.id); await toggleOnboarding(); - navigation.navigate('Home Screen'); + // navigation.navigate('Home Screen'); }; const svgImage = ` diff --git a/client-new/src/services/FileService.ts b/client-new/src/services/FileService.ts index 3d5fd0d..ea7b28d 100644 --- a/client-new/src/services/FileService.ts +++ b/client-new/src/services/FileService.ts @@ -1,20 +1,28 @@ import { IFile } from '@/interfaces/IFile'; import axios from 'axios'; import { API_BASE_URL } from '@/services/const'; +import { sleep } from '@/utils/MockDelayUtil'; export const fetchUserFilesList = async (userId: number, tag?: string) => { - let response; - if (tag) { - response = await axios.get(`${API_BASE_URL}/files/${userId}/user`, {params: {tag: tag}}); - } else { - response = await axios.get(`${API_BASE_URL}/files/${userId}/user`); + try { + let response; + if (tag) { + response = await axios.get(`${API_BASE_URL}/files/${userId}/user`, {params: {tag: tag}}); + } else { + response = await axios.get(`${API_BASE_URL}/files/${userId}/user`); + } + + return response.data as IFile[]; + } catch (error) { + throw new Error('Error fetching user files list'); } - - return response.data as IFile[]; - // return response.status === 200 ? response.data : []; }; export const fetchFileURL = async (fileId: number) => { - const response = await axios.get(`${API_BASE_URL}/files/${fileId}`); - return response.data as string; + try { + const response = await axios.get(`${API_BASE_URL}/files/${fileId}`); + return response.data as string; + } catch (error) { + throw new Error('Error fetching file URL'); + } }; \ No newline at end of file diff --git a/client-new/src/services/GuideService.ts b/client-new/src/services/GuideService.ts index 130d31f..7fa6933 100644 --- a/client-new/src/services/GuideService.ts +++ b/client-new/src/services/GuideService.ts @@ -5,13 +5,19 @@ import { sleep } from '@/utils/MockDelayUtil'; import { API_BASE_URL } from '@/services/const'; export const fetchAllGuides = async () => { - // await sleep(1000) // Simulate network delay - const response = await axios.get(`${API_BASE_URL}/guides/`); - return response.data as IGuide[]; + try { + const response = await axios.get(`${API_BASE_URL}/guides/`); + return response.data as IGuide[]; + } catch (error) { + throw new Error('Error fetching all guides'); + } } export const fetchGuideByName = async (name: string) => { - // await sleep(10000) // Simulate network delay - const response = await axios.get(`${API_BASE_URL}/guides/${name}`); - return response.data as IGuide; + try { + const response = await axios.get(`${API_BASE_URL}/guides/${name}`); + return response.data as IGuide; + } catch (error) { + throw new Error('Error fetching guide by name'); + } } diff --git a/client-new/src/services/PersonaService.ts b/client-new/src/services/PersonaService.ts index e057ea1..362362d 100644 --- a/client-new/src/services/PersonaService.ts +++ b/client-new/src/services/PersonaService.ts @@ -5,6 +5,10 @@ import { IUser } from '../interfaces/IUser'; import { API_BASE_URL } from '@/services/const'; export const fetchUserPersona = async (user_id: number): Promise => { - const response = await axios.get(`${API_BASE_URL}/users/${user_id}/persona`); - return response.data; + try { + const response = await axios.get(`${API_BASE_URL}/users/${user_id}/persona`); + return response.data; + } catch (error) { + throw new Error('Error fetching user persona'); + } }; diff --git a/client-new/src/services/ProfileService.ts b/client-new/src/services/ProfileService.ts index 019ebc1..261d2e6 100644 --- a/client-new/src/services/ProfileService.ts +++ b/client-new/src/services/ProfileService.ts @@ -5,25 +5,34 @@ import { IProfile } from '../interfaces/IProfile'; import { API_BASE_URL } from '@/services/const'; import axios from "axios"; import {IPersona} from "../interfaces/IPersona"; +import { sleep } from '@/utils/MockDelayUtil'; export const getProfile = async (user_id: string) => { console.log('[profile service] fetching profile', `${API_BASE_URL}/users/${user_id}/profile`) - const response = await axios.get(`${API_BASE_URL}/users/${user_id}/profile`); - return response.data as IProfile; + try { + const response = await axios.get(`${API_BASE_URL}/users/${user_id}/profile`); + return response.data as IProfile; + } catch (error) { + throw new Error('Error fetching profile'); + } }; export const updateProfile = async ( profile: IProfile, profile_id: number ): Promise => { - await axios.patch(`${API_BASE_URL}/profiles/${profile_id}`, { - name: profile.name, - date_of_birth: profile.date_of_birth, - phone_number: profile.phone_number, - onboarding_response: profile.onboarding_response, - completed_onboarding_response: profile.completed_onboarding_response, - user_id: profile.user_id - }); + try { + await axios.patch(`${API_BASE_URL}/profiles/${profile_id}`, { + name: profile.name, + date_of_birth: profile.date_of_birth, + phone_number: profile.phone_number, + onboarding_response: profile.onboarding_response, + completed_onboarding_response: profile.completed_onboarding_response, + user_id: profile.user_id + }); + } catch (error) { + throw new Error('Error updating profile'); + } }; export const insertOnboardingResponse = async ( @@ -31,18 +40,26 @@ export const insertOnboardingResponse = async ( profile_id: number, user_id: number ): Promise => { - const response = await axios.patch(`${API_BASE_URL}/profiles/response/${profile_id}/${user_id}`, - onboardingResponse - ); - return response.data; + try { + const response = await axios.patch(`${API_BASE_URL}/profiles/response/${profile_id}/${user_id}`, + onboardingResponse + ); + return response.data; + } catch (error) { + throw new Error('Error inserting onboarding response'); + } }; export const updateOnboardingToComplete = async ( profile_id: number, ): Promise => { console.log('[profile service] updating onboarding to complete', `${API_BASE_URL}/profiles/complete/${profile_id}`) - const response = await axios.patch(`${API_BASE_URL}/profiles/complete/${profile_id}`); - return response.data; + try { + const response = await axios.patch(`${API_BASE_URL}/profiles/complete/${profile_id}`); + return response.data; + } catch (error) { + throw new Error('Error updating onboarding to complete'); + } } /** @@ -56,7 +73,7 @@ export const getAllPersonas = async (): Promise => { ); return response.data; } catch (error) { - throw error.response.data; + throw new Error('Error fetching all personas'); } }; @@ -65,14 +82,12 @@ export const getAllPersonas = async (): Promise => { * @param userID id for some user * @returns persona */ -export const getPersona = async (userID: string): Promise => { +export const getPersona = async (userID: number): Promise => { + console.log('[profile service] getting persona', `${API_BASE_URL}/users/${userID}/persona`) try { - const response = await axios.get( - `http://localhost:8080/api/personas/${userID}` - ); - console.log(response.data); - return response.data; + const response = await axios.get(`${API_BASE_URL}/users/${userID}/persona`); + return response.data as IPersona; } catch (error) { - throw error.response.data; + throw new Error('Error fetching persona'); } }; diff --git a/client-new/src/services/SubTaskService.ts b/client-new/src/services/SubTaskService.ts index 367d263..edb7b2f 100644 --- a/client-new/src/services/SubTaskService.ts +++ b/client-new/src/services/SubTaskService.ts @@ -9,6 +9,6 @@ export const getActions = async (subtask_id: number) => { ); return JSON.parse(res.data); } catch (error) { - throw new Error(error); + throw new Error('Error fetching actions'); } }; diff --git a/client-new/src/services/TaskService.ts b/client-new/src/services/TaskService.ts index 26731e0..86d9352 100644 --- a/client-new/src/services/TaskService.ts +++ b/client-new/src/services/TaskService.ts @@ -4,18 +4,25 @@ import { API_BASE_URL } from '@/services/const'; import { sleep } from '@/utils/MockDelayUtil'; export const fetchUserTasks = async (userId: number, tag?: string) => { - let response; - if (tag) { - response = await axios.get(`${API_BASE_URL}/tasks/${userId}/user`, {params: {tag: tag}}); - } else { - response = await axios.get(`${API_BASE_URL}/tasks/${userId}/user`); + try { + let response; + if (tag) { + response = await axios.get(`${API_BASE_URL}/tasks/${userId}/user`, {params: {tag: tag}}); + } else { + response = await axios.get(`${API_BASE_URL}/tasks/${userId}/user`); + } + + return response.data as ITask[]; + } catch (error) { + throw new Error('Error fetching user tasks'); } - - return response.data as ITask[]; - // return response.status === 200 ? response.data : []; }; export const fetchTaskTag = async (taskId: number) => { - const response = await axios.get(`${API_BASE_URL}/tasks/${taskId}/tag`); - return response.data as string; + try { + const response = await axios.get(`${API_BASE_URL}/tasks/${taskId}/tag`); + return response.data as string; + } catch (error) { + throw new Error('Error fetching task tag'); + } } diff --git a/client-new/src/services/UserService.ts b/client-new/src/services/UserService.ts index bfce7a5..c7d720a 100644 --- a/client-new/src/services/UserService.ts +++ b/client-new/src/services/UserService.ts @@ -12,63 +12,87 @@ import { API_BASE_URL } from '@/services/const'; * @returns the user [IUser] */ export const fetchUser = async (userID: number): Promise> => { - const response = await axios.get(`${API_BASE_URL}/users/${userID}`); - console.log('[user service] fetching user', `${API_BASE_URL}/users/${userID}`, 'with status', response.status) - return response; + try { + const response = await axios.get(`${API_BASE_URL}/users/${userID}`); + console.log('[user service] fetching user', `${API_BASE_URL}/users/${userID}`, 'with status', response.status) + return response; + } catch (error) { + throw new Error('Error fetching user'); + } } export const fetchUserByFirebaseID = async (firebaseID: string): Promise> => { - const response = await axios.get(`${API_BASE_URL}/users/firebase/${firebaseID}`); - console.log('[user service] fetching user by firebase id', `${API_BASE_URL}/users/firebase/${firebaseID}`, 'with status', response.status) - return response; + try { + const response = await axios.get(`${API_BASE_URL}/users/firebase/${firebaseID}`); + console.log('[user service] fetching user by firebase id', `${API_BASE_URL}/users/firebase/${firebaseID}`, 'with status', response.status) + return response; + } catch (error) { + throw new Error('Error fetching user using firebase id'); + } } export const fetchProfile = async (userID: number): Promise> => { - const response = await axios.get(`${API_BASE_URL}/users/${userID}/profile`); - console.log('[user service] fetching profile', `${API_BASE_URL}/users/${userID}/profile`, 'with status', response.status) - return response; + try { + const response = await axios.get(`${API_BASE_URL}/users/${userID}/profile`); + console.log('[user service] fetching profile', `${API_BASE_URL}/users/${userID}/profile`, 'with status', response.status) + return response; + } catch (error) { + throw new Error('Error fetching profile'); + } } export const fetchUserAndProfile = async (firebaseID: string): Promise<{ user: AxiosResponse; profile: AxiosResponse; }> => { - const user = await fetchUserByFirebaseID(firebaseID); - console.log("USER", user.data); - const profile = await fetchProfile(user.data.id); - console.log("PROFILE", profile.data); - return { user, profile }; + try { + const user = await fetchUserByFirebaseID(firebaseID); + console.log("USER", user.data); + const profile = await fetchProfile(user.data.id); + console.log("PROFILE", profile.data); + return { user, profile }; + } catch (error) { + throw new Error('Error fetching user and profile'); + } }; export const createUserAndProfile = async (user: IUser) => { - const newUser: AxiosResponse = await axios.post( - `${API_BASE_URL}/users/`, - { - username: user.username, - password: user.password, - email: user.email, - firebase_id: user.firebase_id - } - ).catch((err) => { - return err; - }); + try { + const newUser: AxiosResponse = await axios.post( + `${API_BASE_URL}/users/`, + { + username: user.username, + password: user.password, + email: user.email, + firebase_id: user.firebase_id + } + ).catch((err) => { + return err; + }); - const _: AxiosResponse = await axios.post( - `${API_BASE_URL}/profiles/`, - { - name: user.email.split('@')[0], - date_of_birth: new Date(2000, 10, 7), - phone_number: '123456789', - user_id: newUser.data.id - } - ).catch((err) => { - return err; - }); + const _: AxiosResponse = await axios.post( + `${API_BASE_URL}/profiles/`, + { + name: user.email.split('@')[0], + date_of_birth: new Date(2000, 10, 7), + phone_number: '123456789', + user_id: newUser.data.id + } + ).catch((err) => { + return err; + }); - return newUser; + return newUser; + } catch (error) { + throw new Error('Error creating user and profile'); + } }; export const initalizeAllProgress = async (userID: number) => { console.log("INITIALIZING PROGRESS"); - await axios.post(`${API_BASE_URL}/users/${userID}/progress`).then((res) => console.log(res.data)) + try { + await axios.post(`${API_BASE_URL}/users/${userID}/progress`).then((res) => console.log(res.data)) + } catch (error) { + throw new Error('Error initializing progress'); + } } \ No newline at end of file