jxmono / crud

:fork_and_knife: CRUD for mono
MIT License
0 stars 1 forks source link

Invalid templates #19

Closed IonicaBizau closed 11 years ago

IonicaBizau commented 11 years ago

I get "Invalid templates" error when making the following crud request:

Request URL:http://crm.mono.ch:8000/@/crud/getTemplates/
Request Method:POST
Status Code:400 Bad Request

Request Payloadview source
[00000000000000000000002]
IonicaBizau commented 11 years ago

Marking as invalid.

The problem was that I was trying to get basic templates that probably crud stop access to them.

The solution found is:

var query = {}; 
var options = {}; 
var fields = { 
    _id: 1
};

var crudObj = { 
    t: '000000000000000000000000',
    q: query,
    o: options,
    f: fields
};

// get all template ids 
self.emit("find", crudObj, function (err, data) {

    // handle error
    if (err) {
        console.error(err);
        return;
    }   

    // an array with template ids 
    var _ids = []; 
    for (var i = 0; i < data.length; ++i) {
        if (data[i]._id === '000000000000000000000004') { continue; }
        _ids.push(data[i]._id);
    }   

    // get templates
    self.emit('getTemplates', _ids, function(err, data) {
        // do something with data
    }); 
});