2020-11-20 10:02:30 +00:00
|
|
|
const mongoose = require('mongoose');
|
2020-04-13 00:02:40 +00:00
|
|
|
|
2020-11-20 10:02:30 +00:00
|
|
|
const CommentSchema = new mongoose.Schema(
|
|
|
|
{
|
|
|
|
body: String,
|
|
|
|
author: { type: mongoose.Schema.Types.ObjectId, ref: 'User' },
|
2020-11-25 14:49:11 +00:00
|
|
|
track: { type: mongoose.Schema.Types.ObjectId, ref: 'Track' },
|
2020-11-20 10:02:30 +00:00
|
|
|
},
|
|
|
|
{ timestamps: true },
|
|
|
|
);
|
2020-04-13 00:02:40 +00:00
|
|
|
|
|
|
|
// Requires population of author
|
2020-11-20 10:02:30 +00:00
|
|
|
CommentSchema.methods.toJSONFor = function (user) {
|
2020-04-13 00:02:40 +00:00
|
|
|
return {
|
|
|
|
id: this._id,
|
|
|
|
body: this.body,
|
|
|
|
createdAt: this.createdAt,
|
2020-11-20 10:02:30 +00:00
|
|
|
author: this.author.toProfileJSONFor(user),
|
2020-04-13 00:02:40 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
mongoose.model('Comment', CommentSchema);
|