obs-portal/models/Comment.js

23 lines
536 B
JavaScript
Raw Normal View History

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