Initial commit

This commit is contained in:
payacom
2026-07-08 21:01:30 +03:30
parent 59c7c8e11c
commit 0b01b262fa
38 changed files with 1415 additions and 288 deletions

49
utils/blockVisibility.js Normal file
View File

@@ -0,0 +1,49 @@
function listIncludesUserId(list, userId) {
if (!userId || !list?.length) return false
return list.some((id) => String(id) === String(userId))
}
/** Viewer has blocked the profile owner */
function viewerBlockedUser(user, viewerId) {
if (!user || !viewerId) return false
return listIncludesUserId(user.blocked_by, viewerId)
}
/** Profile owner has blocked the viewer */
function userBlockedViewer(user, viewerId) {
if (!user || !viewerId) return false
return listIncludesUserId(user.blocked_users, viewerId)
}
/** Viewer (blocked person) cannot see profile/posts of user who blocked them */
function viewerIsBlockedBy(user, viewerId) {
return userBlockedViewer(user, 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 = {
listIncludesUserId,
viewerBlockedUser,
userBlockedViewer,
viewerIsBlockedBy,
blockedProfilePayload,
getBlockerUserIds,
}