Skip to content

Commit

Permalink
hotfix: resolve profile service error
Browse files Browse the repository at this point in the history
  • Loading branch information
Halil-Ibrahim-Kasapoglu committed Dec 16, 2024
1 parent 19f7294 commit 767d7fa
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
14 changes: 14 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 1 addition & 6 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"lightweight-charts": "^4.2.2",
"loglevel": "^1.9.2",
"react": "^18.3.1",
"react-app": "^1.1.2",
"react-dom": "^18.3.1",
"react-financial-charts": "^2.0.1",
"react-google-charts": "^5.1.0",
Expand All @@ -32,12 +33,6 @@
"test": "jest",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
Expand Down
21 changes: 12 additions & 9 deletions frontend/src/service/profileService.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { apiClient } from './apiClient';
import log from '../utils/logger';
import { transformPost } from './postService';

const transformProfile = (userData, profile, posts, comments) => {
const transformProfile = async (userData, profile, posts, comments) => {
profile = {
...profile,
username: userData.username,
Expand All @@ -15,6 +15,15 @@ const transformProfile = (userData, profile, posts, comments) => {
postsCnt: posts.length || 0,
commentsCnt: comments.length || 0,
};

console.log(profile);
profile.following = await Promise.all(
profile.following.map(async (profileId) => await ProfileService.userIdByProfileId(profileId))
);
profile.followers = await Promise.all(
profile.followers.map(async (profileId) => await ProfileService.userIdByProfileId(profileId))
);

return profile;
};

Expand Down Expand Up @@ -45,13 +54,7 @@ const ProfileService = {
try {
const userData = await this.fetchUserById(id);
// Convert followers and following from porfile id to user id
userData.following = await Promise.all(
userData.following.map(async (profileId) => await this.userIdByProfileId(profileId))
);
userData.followers = await Promise.all(
userData.followers.map(async (profileId) => await this.userIdByProfileId(profileId))
);


const posts = await this.fetchPostsByProfileId(id);

const transformedPosts = await Promise.all(
Expand All @@ -60,7 +63,7 @@ const ProfileService = {
const comments = await this.fetchCommentsByProfileId(id);
const response = await apiClient.get(`/profiles/by-user-id/${id}/`);

return transformProfile(userData, response.data, transformedPosts, comments);
return await transformProfile(userData, response.data, transformedPosts, comments);
} catch (error) {
log.error(`Error fetching profile with ID ${id}:`, error);
throw error;
Expand Down

0 comments on commit 767d7fa

Please sign in to comment.