express-blog-api/models/comment.js
2023-09-18 13:43:22 -07:00

20 lines
659 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 },
password: { type: String, 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 `/api/${post}/${this._id}`;
});
// Export model
module.exports = mongoose.model("Comment", CommentSchema);