brainlet/models/Category.js

22 lines
580 B
JavaScript
Raw Normal View History

const mongoose = require("mongoose");
const Post = require("./Post");
const User = require("./User");
const categorySchema = new mongoose.Schema({
title: String,
creator: {type: mongoose.Schema.Types.ObjectId, ref: "User"},
posts: [Post.schema]
});
categorySchema.method("getPublicObject", function() {
return {
title: this.title,
creator: this.populate("creator", User.getPulicFields()).creator,
posts: this.posts,
_id: this._id
};
});
const Category = mongoose.model("Category", categorySchema);
2020-10-05 20:36:03 +03:00
module.exports = Category;