0

I’ve been following the Scotch.io tutorial of using Stamplay and Angular to build an Etsy clone from here https://scotch.io/tutorials/build-an-etsy-clone-with-angular-and-stamplay-part-1

I have been trying to update a record. I have a service with the following function:

function update(id, data) {
    var def = $q.defer();

    // instantiate a new product model from the stamplay js sdk
    var product = new $stamplay.Cobject(‘product’).Model;
    product.fetch(id)
      .then(function() {
        // loop over the fields in data and update the product
        angular.forEach(data, function(value, key) {
          product.set(key, value);
        });
    return product.save();
  })
  .then(function() {
    // return the record
    def.resolve(product);
  });

return def.promise;
}

Then in my actual controller I have another function to connect to the service and do the update:

function update() {
      Product.update(main.productData)
        .then(function (data) {
          main.successMessage = 'Record Updated!';
        });
       }

The issue is i don’t get an id, even though the function does/should fetch the id.

The error i get is [Error] Failed to load resource: the server responded with a status of 400 (Bad Request) ([object Object], line 0)

and the url its going to is /api/cobject/v1/prdouct/[object%20Object]

obviously not getting the id.

Any ideas are appreciated.

devon93
  • 165
  • 2
  • 11
  • Seems like whatever is being passed into the url is not a primitive value type, rather an array or object. Can you log this value out to see what is being passed into the url? – Isaiah Grey Mar 13 '16 at 01:19

1 Answers1

0

The update method takes two parameters and you only supply it with one

Robbert Draaisma
  • 463
  • 4
  • 14
  • product.set and product.save? Does that still have to be defined in the controller? - I'm fairly new to Angular. – devon93 Dec 16 '15 at 12:01
  • I'm guessing this call: Product.update(main.productData) is using the above defined update method, in that case the main.productData object is passed as id parameter and use by the fetch, which would explain the url – Robbert Draaisma Dec 16 '15 at 14:02