refactor(community): rename Community Connections → Community Ecology
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)
This commit is contained in:
parent
9577929e0d
commit
0b3896d984
33 changed files with 1002 additions and 2635 deletions
|
|
@ -1,95 +0,0 @@
|
|||
import Member from '../../../models/member.js'
|
||||
import { connectDB } from '../../../utils/mongoose.js'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
await connectDB()
|
||||
const member = await requireAuth(event)
|
||||
|
||||
const body = await validateBody(event, communityConnectionsUpdateSchema)
|
||||
|
||||
// Build update object for community connections settings
|
||||
const updateData = {
|
||||
'communityConnections.topics': body.topics || [],
|
||||
'communityConnections.offerPeerSupport': body.offerPeerSupport || false,
|
||||
'communityConnections.availability': body.availability || '',
|
||||
'communityConnections.slackHandle': body.slackHandle || '',
|
||||
'communityConnections.personalMessage': body.personalMessage || '',
|
||||
'communityConnections.details': body.details || '',
|
||||
}
|
||||
|
||||
// If Slack handle provided and peer support offered, try to fetch Slack user ID and open DM
|
||||
if (body.offerPeerSupport && body.slackHandle) {
|
||||
try {
|
||||
console.log(
|
||||
`[Community Connections] Attempting to fetch Slack user ID for: ${body.slackHandle}`,
|
||||
)
|
||||
|
||||
const { getSlackService } = await import('../../../utils/slack.ts')
|
||||
const slackService = getSlackService()
|
||||
|
||||
if (slackService) {
|
||||
console.log('[Community Connections] Slack service initialized, looking up user...')
|
||||
const slackUserId = await slackService.findUserIdByUsername(body.slackHandle)
|
||||
|
||||
if (slackUserId) {
|
||||
updateData['slackUserId'] = slackUserId
|
||||
console.log(
|
||||
`[Community Connections] ✓ Found Slack user ID for ${body.slackHandle}: ${slackUserId}`,
|
||||
)
|
||||
|
||||
console.log('[Community Connections] Opening DM channel...')
|
||||
const dmChannelId = await slackService.openDMChannel(slackUserId)
|
||||
|
||||
if (dmChannelId) {
|
||||
updateData['communityConnections.slackDMChannelId'] = dmChannelId
|
||||
console.log(`[Community Connections] ✓ Got DM channel ID: ${dmChannelId}`)
|
||||
} else {
|
||||
console.warn('[Community Connections] Could not get DM channel ID')
|
||||
}
|
||||
} else {
|
||||
console.warn(
|
||||
`[Community Connections] Could not find Slack user ID for handle: ${body.slackHandle}`,
|
||||
)
|
||||
}
|
||||
} else {
|
||||
console.log('[Community Connections] Slack service not configured, skipping user ID lookup')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('[Community Connections] Error fetching Slack user ID:', error.message)
|
||||
console.error('[Community Connections] Stack trace:', error.stack)
|
||||
// Continue anyway - we'll still save the handle
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const updated = await Member.findByIdAndUpdate(
|
||||
member._id,
|
||||
{ $set: updateData },
|
||||
{ new: true, runValidators: true },
|
||||
)
|
||||
|
||||
if (!updated) {
|
||||
throw createError({
|
||||
statusCode: 404,
|
||||
statusMessage: 'Member not found',
|
||||
})
|
||||
}
|
||||
|
||||
logActivity(member._id, 'community_connections_updated', {
|
||||
topicCount: (body.topics || []).length,
|
||||
offerPeerSupport: body.offerPeerSupport || false,
|
||||
})
|
||||
|
||||
return {
|
||||
success: true,
|
||||
communityConnections: updated.communityConnections,
|
||||
}
|
||||
} catch (error) {
|
||||
if (error.statusCode) throw error
|
||||
console.error('Community connections update error:', error)
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
statusMessage: 'Failed to update community connections settings',
|
||||
})
|
||||
}
|
||||
})
|
||||
70
server/api/members/me/community-ecology.patch.js
Normal file
70
server/api/members/me/community-ecology.patch.js
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
import Member from '../../../models/member.js'
|
||||
import { connectDB } from '../../../utils/mongoose.js'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
await connectDB()
|
||||
const member = await requireAuth(event)
|
||||
|
||||
const body = await validateBody(event, communityEcologyUpdateSchema)
|
||||
|
||||
const updateData = {
|
||||
'communityEcology.topics': body.topics || [],
|
||||
'communityEcology.offerPeerSupport': body.offerPeerSupport || false,
|
||||
'communityEcology.availability': body.availability || '',
|
||||
'communityEcology.slackHandle': body.slackHandle || '',
|
||||
'communityEcology.personalMessage': body.personalMessage || '',
|
||||
'communityEcology.details': body.details || '',
|
||||
}
|
||||
|
||||
if (body.offerPeerSupport && body.slackHandle) {
|
||||
try {
|
||||
const { getSlackService } = await import('../../../utils/slack.ts')
|
||||
const slackService = getSlackService()
|
||||
|
||||
if (slackService) {
|
||||
const slackUserId = await slackService.findUserIdByUsername(body.slackHandle)
|
||||
if (slackUserId) {
|
||||
updateData.slackUserId = slackUserId
|
||||
} else {
|
||||
console.warn(
|
||||
`[Community Ecology] Could not find Slack user ID for handle: ${body.slackHandle}`,
|
||||
)
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('[Community Ecology] Error fetching Slack user ID:', error.message)
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const updated = await Member.findByIdAndUpdate(
|
||||
member._id,
|
||||
{ $set: updateData },
|
||||
{ new: true, runValidators: true },
|
||||
)
|
||||
|
||||
if (!updated) {
|
||||
throw createError({
|
||||
statusCode: 404,
|
||||
statusMessage: 'Member not found',
|
||||
})
|
||||
}
|
||||
|
||||
logActivity(member._id, 'community_ecology_updated', {
|
||||
topicCount: (body.topics || []).length,
|
||||
offerPeerSupport: body.offerPeerSupport || false,
|
||||
})
|
||||
|
||||
return {
|
||||
success: true,
|
||||
communityEcology: updated.communityEcology,
|
||||
}
|
||||
} catch (error) {
|
||||
if (error.statusCode) throw error
|
||||
console.error('Community ecology update error:', error)
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
statusMessage: 'Failed to update community ecology settings',
|
||||
})
|
||||
}
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue