signalpoint / angular-drupal

An Angular JS module for Drupal.
GNU General Public License v2.0
116 stars 33 forks source link

comment_save - 500 (Internal Server Error : An error occurred (0): A nid must be provided) #18

Closed CosyStudios closed 8 years ago

CosyStudios commented 8 years ago

Post

Using the basic example

drupal.comment_save(comment).then(function (data) {
          console.log('Created comment: ' + data.cid + data.nid);

}); where comment is: var commment = { nid: 12 //author: 'BOBBOOB', subject: 'Songs About Animals', comment_body: { und: [{ value: 'ttttttttttt test' }] } };

I get a messagew from drupal_angular noting the token is grabbed from memory.

I get POST http://data.songsaboutanimals.co.uk/?q=api/comment.json 500 (Internal Server Error : An error occurred (0): A nid must be provided) in the console.

Format

Ive also tried altering the json to be 'nid' : '12' single quotes around everything, just single quotes around the values, the raw integer..

Permissions?

Happens logged in as administrator. Anonymous users also have the post comment permission on.

using the basic get drupal.comment_load(1).then(function (comment) { console.log("Comment:"); console.dir(comment); });
I get comment 1 back and structure of json is as expected, with an nid.

SO far in my application, ive used the views_json get several times with success/

Also notes:

Request payload in network tab of console is {} no properties .... is this correct?

signalpoint commented 8 years ago

It looks like there is a comma missing after your nid value in the JSON data....?

CosyStudios commented 8 years ago

Interestingly, I stuck a console.dir(comment); statement inside the this.comment_save function in angular-drupal.js and confirms that comment variable is empty.

CosyStudios commented 8 years ago

Yes I realised this, but that was only because id been fiddling with it to try different formats. now using var commment = { nid: 12, subject: 'Songs About Animals', comment_body: { und: [{ value: 'ttttttttttt test' }] } };

but issue appears to be that comment is undefined by the time the script reaches the innards of this.comment_save

CosyStudios commented 8 years ago

My entire service is declared as:

.service('CommentsService', ['drupal', function Commentsservice(drupal) {
  // AngularJS will instantiate a singleton by calling "new" on this function
  var that = this;
  that.comments = [];
  that.loaded = false;

  var postComment = function (formModel) {
      console.dir(formModel);
      var commment = {
          nid: 12,
          subject: 'Songs About Animals',
          comment_body: {
              und: [{
                  value: 'ttttttttttt test'
              }]
          }
      };
      drupal.comment_load(1).then(function (comment) {
          console.log("COmment:");
          console.dir(comment);
      });      
      drupal.comment_save(comment).then(function (data) {
          console.log('Created comment: ' + data.cid + data.nid);
      });
  }

  return {
      postComment: postComment
  }

}]);

CosyStudios commented 8 years ago

Apologies., It seems the long day has turned me into an idiot. "var commment" has 3 mmm's !

Oh the shame