upload files

This commit is contained in:
sbinsalman
2025-11-25 11:11:42 -07:00
commit 36f9a5e69b
41 changed files with 1971 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
import mongoose, { model } from "mongoose";
const { Schema } = mongoose;
const CommentUserStorySchema = new Schema(
{
userStoryId: { type: Schema.Types.ObjectId, ref: "UserStory", required: true },
commentText: { type: String, required: true },
commentedBy: { type: String, required: true },
},
{ timestamps: true }
);
CommentUserStorySchema.post("save", async function (doc, next) {
try {
await mongoose.model("UserStory").findByIdAndUpdate(
doc.userStoryId,
{ $addToSet: { comments: doc._id } } // $addToSet avoids duplicates
);
next();
} catch (err) {
next(err);
}
});
export default model("Comment", CommentUserStorySchema);