express-blog-api/models/comment.js
ak e69fe69d90 revised to use httpOnly cookie to store jwt
comments can no longer be updated or deleted - out of scope
users can now be created, updated and deleted
2023-09-27 16:50:58 -07:00

19 lines
609 B
JavaScript

const mongoose = require("mongoose");
const Schema = mongoose.Schema;
const CommentSchema = new Schema({
date: { type: Date, required: true },
text: { type: String, required: true },
author: { type: String, required: true },
post: { type: mongoose.ObjectId, required: true },
_id: { type: mongoose.ObjectId, required: true },
});
// Virtual for comment RESTful functions
CommentSchema.virtual("url").get(function () {
// We don't use an arrow function as we'll need the this object
return `/${post}/${this._id}`;
});
// Export model
module.exports = mongoose.model("Comment", CommentSchema);