Adding features
This commit is contained in:
parent
600fef2b7c
commit
2b55ca4104
75 changed files with 9796 additions and 2759 deletions
50
server/models/update.js
Normal file
50
server/models/update.js
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
import mongoose from "mongoose";
|
||||
|
||||
const updateSchema = new mongoose.Schema({
|
||||
author: {
|
||||
type: mongoose.Schema.Types.ObjectId,
|
||||
ref: "Member",
|
||||
required: true,
|
||||
},
|
||||
content: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
images: [
|
||||
{
|
||||
url: String,
|
||||
publicId: String,
|
||||
alt: String,
|
||||
},
|
||||
],
|
||||
privacy: {
|
||||
type: String,
|
||||
enum: ["public", "members", "private"],
|
||||
default: "members",
|
||||
},
|
||||
commentsEnabled: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
},
|
||||
createdAt: {
|
||||
type: Date,
|
||||
default: Date.now,
|
||||
},
|
||||
updatedAt: {
|
||||
type: Date,
|
||||
default: Date.now,
|
||||
},
|
||||
});
|
||||
|
||||
// Update the updatedAt timestamp on save
|
||||
updateSchema.pre("save", function (next) {
|
||||
this.updatedAt = Date.now();
|
||||
next();
|
||||
});
|
||||
|
||||
// Indexes for performance
|
||||
updateSchema.index({ createdAt: -1 }); // For sorting by date
|
||||
updateSchema.index({ privacy: 1, createdAt: -1 }); // Compound index for filtering and sorting
|
||||
updateSchema.index({ author: 1 }); // For author lookups
|
||||
|
||||
export default mongoose.models.Update || mongoose.model("Update", updateSchema);
|
||||
Loading…
Add table
Add a link
Reference in a new issue