ghostguild-org/server/models/member.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

160 lines
3.9 KiB
JavaScript

// server/models/member.js
import mongoose from "mongoose";
import { resolve } from "path";
import { fileURLToPath } from "url";
const __dirname = fileURLToPath(new URL(".", import.meta.url));
// Import configs using dynamic imports to avoid build issues
const getValidCircleValues = () => ["community", "founder", "practitioner"];
const getValidContributionValues = () => ["0", "5", "15", "30", "50"];
const memberSchema = new mongoose.Schema({
email: { type: String, required: true, unique: true },
emailHistory: [
{
email: { type: String, required: true },
changedAt: { type: Date, default: Date.now },
},
],
name: { type: String, required: true },
circle: {
type: String,
enum: getValidCircleValues(),
required: true,
},
contributionTier: {
type: String,
enum: getValidContributionValues(),
required: true,
},
role: {
type: String,
enum: ["member", "admin"],
default: "member",
},
status: {
type: String,
enum: ["pending_payment", "active", "suspended", "cancelled"],
default: "pending_payment",
},
helcimCustomerId: String,
helcimSubscriptionId: String,
paymentMethod: {
type: String,
enum: ["card", "bank", "none"],
default: "none",
},
subscriptionStartDate: Date,
subscriptionEndDate: Date,
nextBillingDate: Date,
slackInvited: { type: Boolean, default: false },
slackInviteStatus: {
type: String,
enum: ["pending", "sent", "failed", "accepted", "joined"],
default: "pending",
},
slackUserId: String,
// Profile fields
pronouns: String,
timeZone: String,
avatar: String,
studio: String,
bio: String,
location: String,
socialLinks: {
mastodon: String,
linkedin: String,
website: String,
other: String,
},
showInDirectory: { type: Boolean, default: true },
craftTags: [String],
communityEcology: {
topics: [
{
tagSlug: String,
state: { type: String, enum: ['help', 'interested', 'seeking'] },
},
],
offerPeerSupport: { type: Boolean, default: false },
availability: String,
slackHandle: String,
personalMessage: String,
details: String,
},
// Privacy settings for profile fields
privacy: {
pronouns: {
type: String,
enum: ["public", "members", "private"],
default: "members",
},
timeZone: {
type: String,
enum: ["public", "members", "private"],
default: "members",
},
avatar: {
type: String,
enum: ["public", "members", "private"],
default: "public",
},
studio: {
type: String,
enum: ["public", "members", "private"],
default: "members",
},
bio: {
type: String,
enum: ["public", "members", "private"],
default: "members",
},
location: {
type: String,
enum: ["public", "members", "private"],
default: "members",
},
socialLinks: {
type: String,
enum: ["public", "members", "private"],
default: "members",
},
craftTags: {
type: String,
enum: ["public", "members", "private"],
default: "members",
},
communityEcology: {
type: String,
enum: ["public", "members", "private"],
default: "members",
},
},
notifications: {
events: { type: Boolean, default: true },
updates: { type: Boolean, default: true },
},
inviteEmailSent: { type: Boolean, default: false },
inviteEmailSentAt: Date,
// Magic link single-use enforcement
magicLinkJti: String,
magicLinkJtiUsed: { type: Boolean, default: false },
// Session revocation via token versioning
tokenVersion: { type: Number, default: 0 },
memberNumber: { type: Number, unique: true, sparse: true },
createdAt: { type: Date, default: Date.now },
lastLogin: Date,
});
// Check if model already exists to prevent re-compilation in development
export default mongoose.models.Member || mongoose.model("Member", memberSchema);