ghostguild-org/server/api/members/me/community-ecology.patch.js
Jennie Robinson Faber 0b3896d984
Some checks failed
Test / vitest (push) Successful in 11m42s
Test / playwright (push) Failing after 9m27s
Test / visual (push) Failing after 9m53s
Test / Notify on failure (push) Successful in 2s
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)
2026-04-09 09:07:15 +01:00

70 lines
2.1 KiB
JavaScript

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',
})
}
})