/** Viewer (blocked person) cannot see profile/posts of user who blocked them */ function viewerIsBlockedBy(user, viewerId) { if (!user || !viewerId) return false return user.blocked_users.some((id) => String(id) === String(viewerId)) } function blockedProfilePayload(user) { return { _id: user._id, user_name: user.user_name, blocked_you: true, is_self: false, user_type: user.user_type, postsCount: 0, allProjectsCount: 0, successfulProjectsCount: 0, } } /** User IDs who have blocked the viewer */ async function getBlockerUserIds(UserModel, viewerId) { if (!viewerId) return [] return UserModel.find({ blocked_users: viewerId }).distinct('_id') } module.exports = { viewerIsBlockedBy, blockedProfilePayload, getBlockerUserIds, }