ghostguild-org/server/api/members/profile.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

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",
"communityEcologyPrivacy",
];
// 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",
});
}
});