2021-03-04 21:28:02 +02:00
|
|
|
const mongoose = require("mongoose");
|
|
|
|
const User = require("./User");
|
|
|
|
|
2021-03-26 22:50:21 +02:00
|
|
|
const channelSchema = new mongoose.Schema({
|
2021-03-04 21:28:02 +02:00
|
|
|
title: String,
|
2021-10-22 01:21:03 +03:00
|
|
|
creator: {type: mongoose.Schema.Types.ObjectId, ref: "User"}
|
2021-03-04 21:28:02 +02:00
|
|
|
});
|
|
|
|
|
2021-03-26 22:50:21 +02:00
|
|
|
channelSchema.method("getPublicObject", function() {
|
2021-03-04 21:28:02 +02:00
|
|
|
return {
|
|
|
|
title: this.title,
|
|
|
|
creator: this.populate("creator", User.getPulicFields()).creator,
|
|
|
|
_id: this._id
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2021-03-26 22:50:21 +02:00
|
|
|
const Channel = mongoose.model("Channel", channelSchema);
|
2021-03-04 21:28:02 +02:00
|
|
|
|
2021-03-26 22:50:21 +02:00
|
|
|
module.exports = Channel;
|