Simplify the feature to pure discovery (filter by topic, see matching members, copy Slack handle). Drop the connection request/confirm flow entirely — Connection model, 7 API endpoints, useConnections composable, and TagInput component deleted. - Rename communityConnections → communityEcology in schema, API, pages - Delete legacy fields: offering, lookingFor, peerSupport - New /ecology page, /api/ecology/suggestions, community-ecology.patch - Nav: "Connections" → "Ecology", remove pending-count badge - Fix auth/member.get.js missing craftTags + communityEcology - Add community_ecology_updated activity log type - Expose slackHandle conditionally when offerPeerSupport is true - Add migration script at scripts/migrate-to-ecology.js (run before deploy)
96 lines
2.6 KiB
JavaScript
96 lines
2.6 KiB
JavaScript
import Member from '../../models/member.js'
|
|
import { requireAuth } from '../../utils/auth.js'
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const member = await requireAuth(event)
|
|
const memberId = member._id
|
|
|
|
const topics = member.communityEcology?.topics || []
|
|
if (!topics.length) {
|
|
return { suggestions: [] }
|
|
}
|
|
|
|
const query = getQuery(event)
|
|
const filterTag = query.tag || null
|
|
|
|
let myTopics = topics
|
|
if (filterTag) {
|
|
myTopics = myTopics.filter((t) => t.tagSlug === filterTag)
|
|
}
|
|
if (!myTopics.length) {
|
|
return { suggestions: [] }
|
|
}
|
|
|
|
const mySlugs = myTopics.map((t) => t.tagSlug)
|
|
|
|
const candidates = await Member.find({
|
|
_id: { $ne: memberId },
|
|
status: 'active',
|
|
'communityEcology.topics.tagSlug': { $in: mySlugs },
|
|
})
|
|
.select('name avatar craftTags circle communityEcology privacy')
|
|
.lean()
|
|
|
|
if (!candidates.length) {
|
|
return { suggestions: [] }
|
|
}
|
|
|
|
const myTopicMap = {}
|
|
for (const t of myTopics) {
|
|
myTopicMap[t.tagSlug] = t.state
|
|
}
|
|
|
|
const suggestions = []
|
|
for (const candidate of candidates) {
|
|
const theirTopics = candidate.communityEcology?.topics || []
|
|
const matchingTags = []
|
|
|
|
for (const theirTopic of theirTopics) {
|
|
const myState = myTopicMap[theirTopic.tagSlug]
|
|
if (!myState) continue
|
|
|
|
matchingTags.push({
|
|
tagSlug: theirTopic.tagSlug,
|
|
yourState: myState,
|
|
theirState: theirTopic.state,
|
|
})
|
|
}
|
|
|
|
if (!matchingTags.length) continue
|
|
|
|
// Privacy filter: only expose fields the candidate allows to other members
|
|
const privacy = candidate.privacy || {}
|
|
const filtered = {
|
|
_id: candidate._id,
|
|
name: candidate.name,
|
|
circle: candidate.circle,
|
|
}
|
|
|
|
const avatarPrivacy = privacy.avatar || 'public'
|
|
if (avatarPrivacy === 'public' || avatarPrivacy === 'members') {
|
|
filtered.avatar = candidate.avatar
|
|
}
|
|
|
|
const craftTagsPrivacy = privacy.craftTags || 'members'
|
|
if (craftTagsPrivacy === 'public' || craftTagsPrivacy === 'members') {
|
|
filtered.craftTags = candidate.craftTags
|
|
}
|
|
|
|
// Expose slackHandle only when the candidate has opted into peer support.
|
|
// Slack handle is the contact-in-place path — without it, there is no way
|
|
// for the current member to reach out.
|
|
if (candidate.communityEcology?.offerPeerSupport && candidate.communityEcology?.slackHandle) {
|
|
filtered.slackHandle = candidate.communityEcology.slackHandle
|
|
}
|
|
|
|
suggestions.push({
|
|
member: filtered,
|
|
matchingTags,
|
|
matchCount: matchingTags.length,
|
|
})
|
|
}
|
|
|
|
suggestions.sort((a, b) => b.matchCount - a.matchCount)
|
|
|
|
return { suggestions }
|
|
})
|