BlairAllegroTech / js-data-jsonapi

JsonApi Adapter for js-data
MIT License
15 stars 5 forks source link

cb is not a function #11

Closed rgant closed 8 years ago

rgant commented 8 years ago

I'm trying to configure a skeleton website using angularjs and js-data-jsonapi. I'm getting the following error:

angular-1.5.7.js:13708 TypeError: cb is not a function
    at Reports.JsonApiHelper.beforeUpdateJsonApiData (js-data-jsonapi-0.0.0-alpha.6.js:1166)
    at js-data-2.9.0.js:5596
    at processQueue (angular-1.5.7.js:16170)
    at angular-1.5.7.js:16186
    at Scope.$eval (angular-1.5.7.js:17444)
    at Scope.$digest (angular-1.5.7.js:17257)
    at Scope.$apply (angular-1.5.7.js:17552)
    at HTMLButtonElement.<anonymous> (angular-1.5.7.js:25627)
    at HTMLButtonElement.dispatch (jquery-1.12.0.min.js:3)
    at HTMLButtonElement.r.handle (jquery-1.12.0.min.js:3)

In this function:

        JsonApiHelper.beforeUpdateJsonApiData = function (resource, items, cb) {
            var dataList = DSUTILS.isArray(items) ? items : [items];
            DSUTILS.forEach(dataList, function (data) {
                JsonApiHelper.MergeMetaData(resource, data);
            });
            cb(null, items);
        };

This is my controller:

.controller('ReportsListCtrl', function(DS) {
    var _this = this;

    DS.findAll('reports', {'filter[status]': 'Awaiting Feedback,Feedback Provided',
                           'fields[reports]': 'name,stage,status,created_at,updated_at'})
    .then(function(rpts){
        _this.reports = rpts;
    });

    this.get_timestamp = function(rpt) {
        return new Date(rpt.updated_at || rpt.created_at);
    };

    this.toggle_status = function(rpt) {
        if (rpt.status == 'Feedback Provided') {
            rpt.status = 'Awaiting Feedback';
        } else {
            rpt.status = 'Feedback Provided';
        }
        console.log('HERE', rpt);
        return DS.save('reports', rpt.id);
    };
});

And the error is with DS.save('reports', rpt.id); in the toggle_status method.

Not sure if I've missed something trying to setup my new project, do you have any suggestions?

BlairAllegroTech commented 8 years ago

I'm pretty sure i know what the problem is but haven't been able to reproduce it myself ? As per the js-data documentation: cb is optional and is not passed for synchronous operations.

see:http://www.js-data.io/v2.8/docs/model-lifecycle.

So cb needs to be checked before calling it. I'll make this change which should get you running

rgant commented 8 years ago

Thanks, I got past that point and now I have this new error: #12