refactor(board): delete old board routes, absorb slackHandle into profile PATCH
- Delete server/api/members/me/board.patch.js and server/api/board/suggestions.get.js - Add boardSlackHandle to memberProfileUpdateSchema; remove boardPrivacy - profile.patch.js: write boardSlackHandle -> board.slackHandle; drop boardPrivacy - Remove privacy.board field from Member model - onboarding/status.get.js: hasProfileTags now requires only craftTags; hasEngagedBoard uses BoardPost.exists - onboarding/track.post.js: graduation check uses BoardPost.exists instead of board.topics elemMatch - members/[id].get.js and directory.get.js: reduce board response to slackHandle only; drop connectionTag and peerSupport filters
This commit is contained in:
parent
6a440a846d
commit
1fc937a26a
9 changed files with 34 additions and 230 deletions
|
|
@ -70,21 +70,9 @@ export default defineEventHandler(async (event) => {
|
|||
if (isVisible("socialLinks")) filtered.socialLinks = member.socialLinks;
|
||||
if (isVisible("craftTags")) filtered.craftTags = member.craftTags;
|
||||
|
||||
if (isVisible("board")) {
|
||||
const board = member.board || {};
|
||||
filtered.board = {
|
||||
topics: board.topics,
|
||||
offerPeerSupport: board.offerPeerSupport,
|
||||
availability: board.availability,
|
||||
details: board.details,
|
||||
// Contact-in-place: surface the handle + personal message only when
|
||||
// the member has explicitly opted into peer support.
|
||||
...(board.offerPeerSupport && {
|
||||
slackHandle: board.slackHandle,
|
||||
personalMessage: board.personalMessage,
|
||||
}),
|
||||
};
|
||||
}
|
||||
filtered.board = {
|
||||
slackHandle: member.board?.slackHandle,
|
||||
};
|
||||
|
||||
return { member: filtered };
|
||||
} catch (error) {
|
||||
|
|
|
|||
|
|
@ -22,9 +22,7 @@ export default defineEventHandler(async (event) => {
|
|||
const query = getQuery(event);
|
||||
const search = query.search || "";
|
||||
const circle = query.circle || "";
|
||||
const peerSupport = query.peerSupport || "";
|
||||
const craftTag = query.craftTag || "";
|
||||
const connectionTag = query.connectionTag || "";
|
||||
|
||||
const dbQuery = {
|
||||
showInDirectory: true,
|
||||
|
|
@ -37,10 +35,6 @@ export default defineEventHandler(async (event) => {
|
|||
|
||||
const andConditions = [];
|
||||
|
||||
if (peerSupport === "true") {
|
||||
dbQuery["board.offerPeerSupport"] = true;
|
||||
}
|
||||
|
||||
if (search) {
|
||||
const escaped = escapeRegex(search);
|
||||
andConditions.push({
|
||||
|
|
@ -55,10 +49,6 @@ export default defineEventHandler(async (event) => {
|
|||
dbQuery.craftTags = craftTag;
|
||||
}
|
||||
|
||||
if (connectionTag) {
|
||||
dbQuery["board.topics.tagSlug"] = connectionTag;
|
||||
}
|
||||
|
||||
if (andConditions.length > 0) {
|
||||
dbQuery.$and = andConditions;
|
||||
}
|
||||
|
|
@ -96,17 +86,9 @@ export default defineEventHandler(async (event) => {
|
|||
if (isVisible("socialLinks")) filtered.socialLinks = member.socialLinks;
|
||||
if (isVisible("craftTags")) filtered.craftTags = member.craftTags;
|
||||
|
||||
if (isVisible("board")) {
|
||||
const board = member.board || {};
|
||||
filtered.board = {
|
||||
topics: board.topics,
|
||||
offerPeerSupport: board.offerPeerSupport,
|
||||
availability: board.availability,
|
||||
...(board.offerPeerSupport && {
|
||||
slackHandle: board.slackHandle,
|
||||
}),
|
||||
};
|
||||
}
|
||||
filtered.board = {
|
||||
slackHandle: member.board?.slackHandle,
|
||||
};
|
||||
|
||||
return filtered;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,70 +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, boardUpdateSchema)
|
||||
|
||||
const updateData = {
|
||||
'board.topics': body.topics || [],
|
||||
'board.offerPeerSupport': body.offerPeerSupport || false,
|
||||
'board.availability': body.availability || '',
|
||||
'board.slackHandle': body.slackHandle || '',
|
||||
'board.personalMessage': body.personalMessage || '',
|
||||
'board.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(
|
||||
`[Board] Could not find Slack user ID for handle: ${body.slackHandle}`,
|
||||
)
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('[Board] 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, 'board_updated', {
|
||||
topicCount: (body.topics || []).length,
|
||||
offerPeerSupport: body.offerPeerSupport || false,
|
||||
})
|
||||
|
||||
return {
|
||||
success: true,
|
||||
board: updated.board,
|
||||
}
|
||||
} catch (error) {
|
||||
if (error.statusCode) throw error
|
||||
console.error('Board update error:', error)
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
statusMessage: 'Failed to update board settings',
|
||||
})
|
||||
}
|
||||
})
|
||||
|
|
@ -32,7 +32,6 @@ export default defineEventHandler(async (event) => {
|
|||
"locationPrivacy",
|
||||
"socialLinksPrivacy",
|
||||
"craftTagsPrivacy",
|
||||
"boardPrivacy",
|
||||
];
|
||||
|
||||
// Build update object from validated data
|
||||
|
|
@ -49,6 +48,11 @@ export default defineEventHandler(async (event) => {
|
|||
updateData.craftTags = body.craftTags;
|
||||
}
|
||||
|
||||
// Handle board slack handle
|
||||
if (body.boardSlackHandle !== undefined) {
|
||||
updateData["board.slackHandle"] = body.boardSlackHandle;
|
||||
}
|
||||
|
||||
// Handle privacy settings
|
||||
privacyFields.forEach((privacyField) => {
|
||||
if (body[privacyField] !== undefined) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue