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.