Skip to content

Commit

Permalink
CHE-53 Adjusted profile thumbs to display images if present and updat…
Browse files Browse the repository at this point in the history
…ed getAllProfiles controller to obtain presigned URLS for S3
  • Loading branch information
brok3turtl3 committed Apr 3, 2024
1 parent e12e267 commit d16374a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
9 changes: 8 additions & 1 deletion client/src/components/ProfileThumb/ProfileThumb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ const ProfileThumb = ({ profile }: ProfileThumbProps): JSX.Element => {
const dispatch = useAppDispatch();

return (
<div className="min-h-screen bg-gray-100 flex flex-col items-center justify-center">
<div className="bg-gray-100 flex flex-col items-center justify-center p-4 rounded-lg shadow-lg">
{profile.profilePhoto && (
<img
src={profile.profilePhoto}
alt="Profile"
className="rounded-full h-20 w-20 object-cover mb-4"
/>
)}
<h1 className="text-4xl font-extrabold mb-4">{profile.fullName}</h1>
<h2 className="text-4xl font-extrabold mb-4">{profile.personalBio}</h2>
</div>
Expand Down
16 changes: 15 additions & 1 deletion server/controllers/profileController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,21 @@ const getAllProfiles = async (
message: { err: "There were no profiles to retrieve" },
});
} else {
return res.status(201).json(profiles);
const processedProfiles = await Promise.all(
profiles.map(async (profile) => {
if (profile.profilePhoto) {
const presignedUrl = s3.getSignedUrl("getObject", {
Bucket: process.env.BUCKET_NAME,
Key: profile.profilePhoto,
Expires: 60 * 5,
});
profile.profilePhoto = presignedUrl;
}
return profile.toObject();
})
);

return res.status(201).json(processedProfiles);
}
} catch (error) {
return next({
Expand Down

0 comments on commit d16374a

Please sign in to comment.