Skip to content

Commit

Permalink
Fixed profile pictures attached only when customData is present.
Browse files Browse the repository at this point in the history
  • Loading branch information
shrihari-prakash committed Jan 3, 2024
1 parent 2f51ecd commit db73108
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/service/api/user/follow-requests.get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const GET_FollowRequests = async (req: Request, res: Response) => {
},
]).exec();
for (let i = 0; i < records.length; i++) {
await hydrateUserProfile(records[i].source);
await hydrateUserProfile(records[i].source, { customData: false });
}
res.status(statusCodes.success).json(new SuccessResponse({ records }));
} catch (err) {
Expand Down
3 changes: 1 addition & 2 deletions src/service/api/user/followers.get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const GET_Followers = async (req: Request, res: Response) => {
}
const records = await FollowModel.aggregate(query).exec();
for (let i = 0; i < records.length; i++) {
await hydrateUserProfile(records[i].source);
await hydrateUserProfile(records[i].source, { customData: false });
}
res.status(statusCodes.success).json(new SuccessResponse({ records }));
} catch (err) {
Expand All @@ -49,4 +49,3 @@ const GET_Followers = async (req: Request, res: Response) => {
};

export default GET_Followers;

23 changes: 16 additions & 7 deletions src/utils/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,29 @@ export const sanitizeEditableFields = () => {
}
};

export const hydrateUserProfile = async (user: UserInterface | UserInterface[]) => {
export const hydrateUserProfile = async (
user: UserInterface | UserInterface[],
ctx: { customData: boolean } = { customData: true }
) => {
if (Array.isArray(user)) {
for (let i = 0; i < user.length; i++) {
if (user[i].customData) {
checkSubscription(user[i]);
await attachProfilePicture(user[i]);
checkSubscription(user[i]);
await attachProfilePicture(user[i]);
if (user[i].customData && ctx.customData) {
user[i].customData = JSON.parse(user[i].customData);
} else {
// @ts-expect-error
user.customData = undefined;
}
}
} else {
if (user.customData) {
checkSubscription(user);
await attachProfilePicture(user);
checkSubscription(user);
await attachProfilePicture(user);
if (user.customData && ctx.customData) {
user.customData = JSON.parse(user.customData);
} else {
// @ts-expect-error
user.customData = undefined;
}
}
};

0 comments on commit db73108

Please sign in to comment.