AllenYuan

comment model

May 12th, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var mongoose = require('mongoose');
  2.  
  3. // schema
  4. var CommentSchema = new mongoose.Schema({
  5.   body: String,
  6.   author: { type: mongoose.Schema.Types.ObjectId, ref: 'User' },
  7.   article: { type: mongoose.Schema.Types.ObjectId, ref: 'Article' }
  8. }, {timestamps: true});
  9.  
  10. CommentSchema.methods.toJSONFor = function(user){
  11.   return {
  12.     id: this._id,
  13.     body: this.body,
  14.     createdAt: this.createdAt,
  15.     author: this.author.toProfileJSONFor(user)
  16.   };
  17. };
  18.  
  19. mongoose.model('Comment', CommentSchema);
Advertisement
Add Comment
Please, Sign In to add comment