This repository has been archived on 2022-05-17. You can view files and clone it, but cannot push or open issues or pull requests.
brainlet/models/Channel.js

22 lines
574 B
JavaScript
Raw Normal View History

const mongoose = require("mongoose");
const Post = require("./Post");
const User = require("./User");
const channelSchema = new mongoose.Schema({
title: String,
creator: {type: mongoose.Schema.Types.ObjectId, ref: "User"},
posts: [Post.schema]
});
channelSchema.method("getPublicObject", function() {
return {
title: this.title,
creator: this.populate("creator", User.getPulicFields()).creator,
posts: this.posts,
_id: this._id
};
});
const Channel = mongoose.model("Channel", channelSchema);
module.exports = Channel;