Make all articles public

This commit is contained in:
Jennie Robinson Faber 2025-11-15 13:43:21 +00:00
parent 92e96b9107
commit 555b200ec7
18 changed files with 24541 additions and 94 deletions

View file

@ -1,111 +1,117 @@
import { Schema, model, Document, Types } from 'mongoose'
import { Schema, model, Document, Types } from "mongoose";
export interface IRevision {
content: string
author: Types.ObjectId
message: string
createdAt: Date
content: string;
author: Types.ObjectId;
message: string;
createdAt: Date;
}
export interface IComment {
author: Types.ObjectId
content: string
parentComment?: Types.ObjectId
createdAt: Date
updatedAt: Date
resolved: boolean
author: Types.ObjectId;
content: string;
parentComment?: Types.ObjectId;
createdAt: Date;
updatedAt: Date;
resolved: boolean;
}
export interface IArticle extends Document {
slug: string
title: string
description: string
content: string // Current content in markdown
category: string
tags: string[]
slug: string;
title: string;
description: string;
content: string; // Current content in markdown
category: string;
tags: string[];
// Access control
accessLevel: 'public' | 'member' | 'cohort' | 'admin'
cohorts?: string[] // Specific cohorts if accessLevel is 'cohort'
accessLevel: "public" | "member" | "cohort" | "admin";
cohorts?: string[]; // Specific cohorts if accessLevel is 'cohort'
// Metadata
author: Types.ObjectId
contributors: Types.ObjectId[]
views: number
likes: number
author: Types.ObjectId;
contributors: Types.ObjectId[];
views: number;
likes: number;
// Editing
status: 'draft' | 'published' | 'archived'
lockedBy?: Types.ObjectId // If someone is currently editing
lockedAt?: Date
status: "draft" | "published" | "archived";
lockedBy?: Types.ObjectId; // If someone is currently editing
lockedAt?: Date;
// History
revisions: IRevision[]
comments: IComment[]
revisions: IRevision[];
comments: IComment[];
// Timestamps
createdAt: Date
updatedAt: Date
publishedAt?: Date
createdAt: Date;
updatedAt: Date;
publishedAt?: Date;
}
const revisionSchema = new Schema<IRevision>({
content: { type: String, required: true },
author: { type: Schema.Types.ObjectId, ref: 'User', required: true },
author: { type: Schema.Types.ObjectId, ref: "User", required: true },
message: { type: String, required: true },
createdAt: { type: Date, default: Date.now }
})
createdAt: { type: Date, default: Date.now },
});
const commentSchema = new Schema<IComment>({
author: { type: Schema.Types.ObjectId, ref: 'User', required: true },
content: { type: String, required: true },
parentComment: { type: Schema.Types.ObjectId, ref: 'Comment' },
resolved: { type: Boolean, default: false }
}, {
timestamps: true
})
const articleSchema = new Schema<IArticle>({
slug: { type: String, required: true, unique: true },
title: { type: String, required: true },
description: { type: String, required: true },
content: { type: String, required: true },
category: { type: String, required: true },
tags: [{ type: String }],
accessLevel: {
type: String,
enum: ['public', 'member', 'cohort', 'admin'],
default: 'member'
const commentSchema = new Schema<IComment>(
{
author: { type: Schema.Types.ObjectId, ref: "User", required: true },
content: { type: String, required: true },
parentComment: { type: Schema.Types.ObjectId, ref: "Comment" },
resolved: { type: Boolean, default: false },
},
cohorts: [{ type: String }],
author: { type: Schema.Types.ObjectId, ref: 'User', required: true },
contributors: [{ type: Schema.Types.ObjectId, ref: 'User' }],
views: { type: Number, default: 0 },
likes: { type: Number, default: 0 },
status: {
type: String,
enum: ['draft', 'published', 'archived'],
default: 'draft'
{
timestamps: true,
},
lockedBy: { type: Schema.Types.ObjectId, ref: 'User' },
lockedAt: Date,
);
revisions: [revisionSchema],
comments: [commentSchema],
const articleSchema = new Schema<IArticle>(
{
slug: { type: String, required: true, unique: true },
title: { type: String, required: true },
description: { type: String, required: true },
content: { type: String, required: true },
category: { type: String, required: true },
tags: [{ type: String }],
publishedAt: Date
}, {
timestamps: true
})
accessLevel: {
type: String,
enum: ["public", "member", "cohort", "admin"],
default: "public",
},
cohorts: [{ type: String }],
author: { type: Schema.Types.ObjectId, ref: "User", required: true },
contributors: [{ type: Schema.Types.ObjectId, ref: "User" }],
views: { type: Number, default: 0 },
likes: { type: Number, default: 0 },
status: {
type: String,
enum: ["draft", "published", "archived"],
default: "draft",
},
lockedBy: { type: Schema.Types.ObjectId, ref: "User" },
lockedAt: Date,
revisions: [revisionSchema],
comments: [commentSchema],
publishedAt: Date,
},
{
timestamps: true,
},
);
// Indexes for better query performance
articleSchema.index({ slug: 1 })
articleSchema.index({ accessLevel: 1, status: 1 })
articleSchema.index({ tags: 1 })
articleSchema.index({ category: 1 })
articleSchema.index({ author: 1 })
articleSchema.index({ slug: 1 });
articleSchema.index({ accessLevel: 1, status: 1 });
articleSchema.index({ tags: 1 });
articleSchema.index({ category: 1 });
articleSchema.index({ author: 1 });
export const Article = model<IArticle>('Article', articleSchema)
export const Article = model<IArticle>("Article", articleSchema);