2021-03-04 21:28:02 +02:00
|
|
|
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;
|