diff --git a/src/service/api/user/follow-requests.get.ts b/src/service/api/user/follow-requests.get.ts index 3b9d9aa8..25741085 100644 --- a/src/service/api/user/follow-requests.get.ts +++ b/src/service/api/user/follow-requests.get.ts @@ -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) { diff --git a/src/service/api/user/followers.get.ts b/src/service/api/user/followers.get.ts index 1e04195b..4064f998 100644 --- a/src/service/api/user/followers.get.ts +++ b/src/service/api/user/followers.get.ts @@ -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) { @@ -49,4 +49,3 @@ const GET_Followers = async (req: Request, res: Response) => { }; export default GET_Followers; - diff --git a/src/utils/user.ts b/src/utils/user.ts index aebb0172..7697523b 100644 --- a/src/utils/user.ts +++ b/src/utils/user.ts @@ -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; } } };