var async = require('async'),
    rest = require('../../../services/rest.js'),
    discussion = require('../../../models/discussion.js'),
    comment = require('../../../models/comment.js');

function discuss(req,res){
    var entry = req.params.entryId,
        model = new discussion({ entry: mongoose.Types.ObjectId(entry) });

    add(req,res,model);
}

function insert(req,res){
    discussion.findOne({ _id: req.params.id }, function(err, discussion){
        if(err){
            throw err;
        }
        add(req,res,discussion);
    });
}

function add(req,res,model){
    var document = {
        text: req.body.comment,
        author: {
            id: mongoose.Types.ObjectId(req.user._id),
            displayName: req.user.displayName
        }
    };

    model.comments.push(document);
    model.save(function(err){
        rest.resHandler(err,{
            res: res
        });
    });
}

module.exports = {
    get: null,
    discuss: discuss,
    ins: insert
};
@@ -1,39 +1,8 @@
 var 
-async = require('async'),%0D%0A    
 rest
@@ -232,21 +232,24 @@
         
-model
+document
  = new d
@@ -321,21 +321,24 @@
 req,res,
-model
+document
 );%0D%0A%7D%0D%0A%0D
@@ -427,25 +427,23 @@
 n(err, d
-iscussion
+ocument
 )%7B%0D%0A    
@@ -512,25 +512,23 @@
 eq,res,d
-iscussion
+ocument
 );%0D%0A    
@@ -558,21 +558,24 @@
 req,res,
-model
+document
 )%7B%0D%0A    
@@ -578,24 +578,21 @@
     var 
-document
+model
  = %7B%0D%0A  
@@ -769,21 +769,24 @@
 %0D%0A%0D%0A    
-model
+document
 .comment
@@ -796,29 +796,29 @@
 ush(
-document);%0D%0A    model
+model);%0D%0A    document
 .sav
@@ -915,16 +915,334 @@
 ;%0D%0A%7D%0D%0A%0D%0A
+function list(req,res)%7B%0D%0A    discussion.query(%7B entry: mongoose.Types.ObjectId(req.params.id) %7D, callback);%0D%0A%0D%0A    function callback(err,documents)%7B%0D%0A        rest.resHandler(err, %7B%0D%0A            res: res,%0D%0A            then: function()%7B%0D%0A                rest.end(res,documents);%0D%0A            %7D%0D%0A        %7D);%0D%0A    %7D%0D%0A%7D%0D%0A%0D%0A
 module.e
@@ -1266,12 +1266,12 @@
 et: 
-null
+list
 ,%0D%0A 

comment api get