express-blog-api/models/post.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

20 lines
613 B
JavaScript

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