1

I got problem while I move into https://github.com/DaftMonk/generator-angular-fullstack.

Before my project was working. Here is code for frontend and backend part related to comment. I am getting all time error 404. I don't know why I cannot find following path.

POST http://localhost:9000/api/providers/554a1dba53d9ca8c2a2a31ff/posts/554b1726f1116e00256e3d82/comments 404 (Not Found)

I am struggling couple of days to discover which part of my code have problem but I couldn't realize that.

server side

in comment.controller

// Creates a new comment in the DB.
exports.create = function(req, res) {
  console.log('i ma inside api');

    Post.findById(req.originalUrl.split('/')[3], function (err, post) { //here can not find post at all.
      if (err) {
        return handleError(res, err);
      }
      if (!post) {
        return res.status(404).send('Post not found');
      }

      Comment.create(req.body, function (err, comment) {
        if (err) {
          return handleError(res, err);
        }

        post.comments.push(comment.id);
        post.save(function (err) {
          if (err) return handleError(res, err);
          return res.status(201).json(comment);
        });
      });
    });

  };

route.js

 app.use('/api/providers/:providerId/posts/:postId/comments', require('./api/provider/post/comment'));

index.js

var controller = require('./comment.controller.js');

var router = express.Router();

router.get('/', controller.index);
router.get('/:id', controller.show);
router.post('/', controller.create);
router.put('/:id', controller.update);
router.patch('/:id', controller.update);
router.delete('/:id', controller.destroy);
router.put('/:id/upvote', controller.upvote);

in client side: factory:

//create new comment for post
    ob.createComment = function(providerId, postId,comment) {
      console.log('i am inside factory');
        return $http.post('/api/providers/'+ providerId + '/posts/' + postId + '/comments' ,comment, {
          headers: {Authorization: 'Bearer '+Auth.getToken()}
        }).success(function(data){
          _.forEach(ob.provider.posts,function(value,index){
            if(value._id === post._id){
              ob.posts[index].comments.push(data);
            }
          })
          ob.current.comments.push(data)
          // ob.provider1._id.posts.push(data);
        });
    };

in my controller

 $scope.addComment = function(){
        // if(!$scope.title || $scope.title === '') { return; }
        if(!$scope.body || $scope.body === '') { return; }
        console.log('$stateParams',$stateParams);
        providers.createComment($stateParams.providerId, $stateParams.postId,{
          //title: $scope.title,
          body: $scope.body
        });
        $scope.body = '';
        $scope.title = '';
      };

This is my model in whole the project. enter image description here

pm1359
  • 622
  • 1
  • 10
  • 31
  • @Jason Cust ,Since i have posted this anybody couldn't help me. Would you please to guide me? – pm1359 May 10 '15 at 09:34

0 Answers0