ghostguild-org/server/api/members/profile.patch.js
Jennie Robinson Faber 9577929e0d refactor(peer-support): delete provably dead code (Phase 1)
The Skills Exchange + Peer Support feature was replaced by Community
Connections on 2026-04-05, but several files and code paths were left
in place as backward-compat. None are reachable from the live UI:

- usePeerSupport.js composable: not imported anywhere
- PeerSupportBadge.vue: not imported anywhere
- peer-support.vue: stub redirect with no incoming links
- /api/peer-support.get.js: only consumed by usePeerSupport
- /api/members/me/peer-support.patch.js: same
- profile.patch.js offering/lookingFor write branches: profile form
  no longer sends these fields (only writes communityConnections.*)
- PEER_SUPPORT_ENABLED/DISABLED activity types and renderers: only
  written by the deleted peer-support.patch endpoint. The activityText
  formatter has a fallback for unknown types so existing records
  still display ("peer support enabled" with a generic icon).

Tests updated to drop peerSupportUpdateSchema coverage and the
offering/lookingFor passthrough assertion.

schemas.js cleanup deferred — concurrent communityConnections →
communityEcology rename is in flight in the working tree.
2026-04-08 22:28:35 +01:00

106 lines
2.8 KiB
JavaScript

import Member from "../../models/member.js";
import { requireAuth } from "../../utils/auth.js";
import { validateBody } from "../../utils/validateBody.js";
import { memberProfileUpdateSchema } from "../../utils/schemas.js";
export default defineEventHandler(async (event) => {
const authedMember = await requireAuth(event);
const memberId = authedMember._id;
const body = await validateBody(event, memberProfileUpdateSchema);
// Profile fields from validated body
const profileFields = [
"pronouns",
"timeZone",
"avatar",
"studio",
"bio",
"location",
"socialLinks",
"showInDirectory",
"notifications",
];
// Privacy fields from validated body
const privacyFields = [
"pronounsPrivacy",
"timeZonePrivacy",
"avatarPrivacy",
"studioPrivacy",
"bioPrivacy",
"locationPrivacy",
"socialLinksPrivacy",
"craftTagsPrivacy",
"communityConnectionsPrivacy",
];
// Build update object from validated data
const updateData = {};
profileFields.forEach((field) => {
if (body[field] !== undefined) {
updateData[field] = body[field];
}
});
// Handle craftTags (simple array)
if (body.craftTags !== undefined) {
updateData.craftTags = body.craftTags;
}
// Handle privacy settings
privacyFields.forEach((privacyField) => {
if (body[privacyField] !== undefined) {
const baseField = privacyField.replace("Privacy", "");
updateData[`privacy.${baseField}`] = body[privacyField];
}
});
try {
const member = await Member.findByIdAndUpdate(
memberId,
{ $set: updateData },
{ new: true, runValidators: true },
);
if (!member) {
throw createError({
statusCode: 404,
statusMessage: "Member not found",
});
}
// Log which fields were updated
const changedFields = Object.keys(body).filter(k => body[k] !== undefined && !k.endsWith('Privacy'))
if (changedFields.length) {
logActivity(memberId, 'profile_updated', { fields: changedFields })
}
// Return sanitized member data
return {
id: member._id,
email: member.email,
name: member.name,
circle: member.circle,
contributionTier: member.contributionTier,
pronouns: member.pronouns,
timeZone: member.timeZone,
avatar: member.avatar,
studio: member.studio,
bio: member.bio,
location: member.location,
socialLinks: member.socialLinks,
craftTags: member.craftTags,
showInDirectory: member.showInDirectory,
notifications: member.notifications,
};
} catch (error) {
if (error.statusCode) throw error;
console.error("Profile update error:", error);
throw createError({
statusCode: 500,
statusMessage: "Failed to update profile",
});
}
});