obs-portal/models/Comment.js

26 lines
536 B
JavaScript
Raw Normal View History

2020-11-20 10:02:30 +00:00
const mongoose = require('mongoose');
const schema = new mongoose.Schema(
2020-11-20 10:02:30 +00:00
{
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 },
);
class Comment extends mongoose.Model {
toJSONFor(user) {
return {
id: this._id,
body: this.body,
createdAt: this.createdAt,
author: this.author.toProfileJSONFor(user),
};
}
}
mongoose.model(Comment, schema);
module.exports = Comment;