Comparing version 0.1.35 to 0.1.37
10
api.js
@@ -81,10 +81,12 @@ var _ = require('underscore'), | ||
var filtering_field = { field : key }; | ||
if(value) | ||
filtering_field.usages = _.map(value,function(value2,operand) | ||
if(value !== null && typeof(value) === "object") { | ||
filtering_field.usages = _.map(value, function(value2, operand) | ||
{ | ||
var operand_str = operand == 'exact' ? '' : '__' + operand; | ||
var operand_str = operand === 'exact' ? '' : '__' + operand; | ||
return resource.path + '?' + key + operand_str + '=' + self.default_value_per_operand(operand); | ||
}); | ||
else | ||
} | ||
else { | ||
filtering_field.usages = [ resource.path + '?' + key + '=<value>', resource.path + '?' + key + '__in=<value1>,<value2>']; | ||
} | ||
return filtering_field; | ||
@@ -91,0 +93,0 @@ }), |
@@ -102,3 +102,3 @@ var _ = require('underscore'), | ||
query.where(query_key)[query_op](query_value); | ||
count_query.where(query_key)[query_op](query_value); | ||
//count_query.where(query_key)[query_op](query_value); | ||
} | ||
@@ -108,3 +108,3 @@ else | ||
query.where(query_key, query_value); | ||
count_query.where(query_key, query_value); | ||
//count_query.where(query_key, query_value); | ||
} | ||
@@ -132,4 +132,6 @@ } | ||
query.limit(limit); | ||
query.skip(offset); | ||
if(limit > 0) | ||
query.limit(limit); | ||
if(offset > 0) | ||
query.skip(offset); | ||
@@ -153,16 +155,17 @@ var results = null, count = null; | ||
self.authorization.limit_object_list(req, query, function (err, query) { | ||
if (err) callback(err); | ||
else | ||
self.run_query(req,query,function (err, objects) { | ||
if (err) callback(err); | ||
else { | ||
results = objects; | ||
on_finish(); | ||
} | ||
}); | ||
}); | ||
if (err) return callback(err); | ||
self.authorization.limit_object_list(req, count_query, function (err, count_query) { | ||
if (err) callback(err); | ||
else | ||
for(var key in query._conditions){ | ||
count_query._conditions[key] = query._conditions[key]; | ||
} | ||
self.run_query(req,query,function (err, objects,counter) { | ||
if (err) callback(err); | ||
else { | ||
results = objects; | ||
if(!(limit > 0)) | ||
count = counter || objects.length; | ||
on_finish(); | ||
} | ||
}); | ||
if(limit > 0) { | ||
self.run_query(req,count_query,function (err, counter) { | ||
@@ -175,3 +178,9 @@ if (err) callback(err); | ||
}); | ||
} | ||
}); | ||
// self.authorization.limit_object_list(req, count_query, function (err, count_query) { | ||
// if (err) callback(err); | ||
// else | ||
// }); | ||
}, | ||
@@ -178,0 +187,0 @@ |
{ | ||
"name":"jest", | ||
"description":"JavaScriptational State Transfer. JS restful API layer with Mongoose based resources. Inspired by python Tastypie", | ||
"version":"0.1.35", | ||
"author":"Ishai Jaffe <ishai@empeeric.com>", | ||
"contributors": [ | ||
{ "name": "Alon Valadji", "email": "alon@empeeric.com" } | ||
], | ||
"dependencies":{ | ||
"underscore":"", | ||
"sji":"" | ||
}, | ||
"devDependencies":{ | ||
"express":"", | ||
"mongoose":"", | ||
"api-easy":"" | ||
}, | ||
"main":"index", | ||
"keywords":["api", "mongoose", "rest", "restful", "resource"], | ||
"repository":"git@github.com:Empeeric/jest.git", | ||
"engines":{ | ||
"node":">= 0.4.1" | ||
} | ||
} | ||
"name": "jest", | ||
"description": "JavaScriptational State Transfer. JS restful API layer with Mongoose based resources. Inspired by python Tastypie", | ||
"version": "0.1.37", | ||
"author": "Ishai Jaffe <ishai@empeeric.com>", | ||
"contributors": [ | ||
{ | ||
"name": "Alon Valadji", | ||
"email": "alon@empeeric.com" | ||
}, | ||
{ | ||
"name": "Refael Ackermann", | ||
"email": "refael@empeeric.com" | ||
} | ||
], | ||
"dependencies": { | ||
"underscore": "", | ||
"sji": "" | ||
}, | ||
"devDependencies": { | ||
"express": "", | ||
"mongoose": "", | ||
"api-easy": "" | ||
}, | ||
"main": "index", | ||
"keywords": [ | ||
"api", | ||
"mongoose", | ||
"rest", | ||
"restful", | ||
"resource" | ||
], | ||
"repository": "git@github.com:Empeeric/jest.git", | ||
"engines": { | ||
"node": ">= 0.4.1" | ||
} | ||
} |
@@ -10,4 +10,7 @@ var _ = require('underscore'), | ||
var NotImplemented = function(){ | ||
Error.call(this,'Method not implemented',865); | ||
Error.call(this, 'Method not implemented', 865); | ||
}; | ||
NotImplemented.prototype = new Error(); | ||
NotImplemented.prototype.constructor = NotImplemented; | ||
NotImplemented.prototype.name = 'NotImplemented'; | ||
@@ -95,6 +98,6 @@ var Resource = module.exports = Class.extend({ | ||
var max_limit = self.max_limit || self.settings.MAX_LIMIT; | ||
if(limit >= max_limit) | ||
if(limit > max_limit) | ||
{ | ||
if(self.strict) | ||
callback({code:400, message:'limit can be more than ' + max_limit}) | ||
return callback({code:400, message:'limit can be more than ' + max_limit}) | ||
else | ||
@@ -104,9 +107,9 @@ limit = max_limit; | ||
limit = Math.min(limit, self.max_limit || self.settings.MAX_LIMIT); | ||
if (limit <= 0) | ||
{ | ||
if(self.strict) | ||
callback({code:400, message:'limit must be a greater than zero'}); | ||
else | ||
limit = self.max_limit || self.settings.MAX_LIMIT; | ||
} | ||
// if (limit <= 0) | ||
// { | ||
// if(self.strict) | ||
// return callback({code:400, message:'limit must be a greater than zero'}); | ||
// else | ||
// limit = self.max_limit || self.settings.MAX_LIMIT; | ||
// } | ||
@@ -547,5 +550,5 @@ // check if in cache | ||
if (err) | ||
self.internal_error(err, req, res); | ||
self.unauthorized(res,err.message || err); | ||
else { | ||
if (!is_auth) { | ||
if (is_auth === false) { | ||
self.unauthorized(res,'not authenticated'); | ||
@@ -552,0 +555,0 @@ return; |
68244
1798