const mongoose = require('mongoose')

mongoose.connect('mongodb://db/lucaschmid-net')

const commentSchema = new mongoose.Schema({
  author: {
    required: true,
    type: String
  },
  text: {
    required: true,
    type: String
  },
  post: {
    required: true,
    type: String
  }
})

const Comment = mongoose.model('Comments', commentSchema)

module.exports = {
  getComments: post => Comment.find({ post: post }),
  postComment: com => new Promise((res, rej) => {
    const comment = (new Comment(com))
    comment
      .validate()
      .then(() => comment.save())
      .then(res)
      .catch(rej)
  })
}


const mongoose = require('mongoose')

mongoose.connect('mongodb://db/lucaschmid-net')

const commentSchema = new mongoose.Schema({
  author: {
    required: true,
    type: String
  },
  text: {
    required: true,
    type: String
  },
  post: {
    required: true,
    type: String
  }
})

const Comment = mongoose.model('Comments', commentSchema)

module.exports = {
  getComments: post =>
    Comment
      .find({ post: post })
      .then(arr =>
        arr.map(el => ({
          post: el.post,
          text: el.text,
          author: el.author
        }))
      ),
  postComment: com => new Promise((res, rej) => {
    const comment = (new Comment(com))
    comment
      .validate()
      .then(() => comment.save())
      .then(res)
      .catch(rej)
  })
}


Stop sending comment IDs to the client
Stop sending comment IDs to the client
