router.post('/comment', (req, res, next) => { const comment = { id: Date.now().toString(), text: req.body.text, date: new Date(), user: req.body.user, article: req.body.article } const article = mocks.articles.filter(article => article.id == req.body.article)[0] const id = mocks.articles.indexOf(article) mocks.comments.push(comment) mocks.articles[id].comments.push(comment.id) res.json(comment) })
function seedDB(){ //add article data.forEach(function(seed){ Article.create(seed, function(err, article){ if(err){ console.log(err); }else{ Comment.create( { text: "This is the first article", author: "Author" }, function(err, comment){ if(err){ console.log(err); } else{ article.comments.push(comment); article.save(); console.log("Comment added"); } }); } }); }); }
} else { console.log('Comment Created!') campground.comments.push(comment._id) campground.save()
expect(postCommentResult.insertedId).not.toBe(null) const kingKongComments = (await MoviesDAO.getMovieByID(movieId)).comments
comments(comments = defaultState.comments) { return comments; },
console.log(err); }else{ campground.comments.push(comment); campground.save(); console.log("Created New Comment!")
case LOAD_COMMENTS_SUCCESS: console.log(LOAD_COMMENTS_SUCCESS); console.log(action.comments); return { ...state, isFetching: false, comments: action.comments, lastUpdated: action.receivedAt, }; return { ...state, comments: [...state.comments, { id: 4, user: action.payloads.user, text: action.payloads.text }], }; default: