producteca-sdk
Advanced tools
Comparing version 0.0.8 to 0.0.18
@@ -34,2 +34,3 @@ (function() { | ||
this._makeUrlAsync = __bind(this._makeUrlAsync, this); | ||
this._buildSalesOrdersFilters = __bind(this._buildSalesOrdersFilters, this); | ||
this.returnMany = __bind(this.returnMany, this); | ||
@@ -39,2 +40,3 @@ this["return"] = __bind(this["return"], this); | ||
this.updateStocks = __bind(this.updateStocks, this); | ||
this.updateSalesOrder = __bind(this.updateSalesOrder, this); | ||
this.getSalesOrder = __bind(this.getSalesOrder, this); | ||
@@ -48,9 +50,18 @@ this.getSalesOrders = __bind(this.getSalesOrders, this); | ||
ProductecaApi.prototype.getProducts = function() { | ||
return this.returnMany(this.client.getAsync("/products")).map(function(json) { | ||
return new Product(json); | ||
}); | ||
return this.returnMany(this.client.getAsync("/products")).then((function(_this) { | ||
return function(products) { | ||
return products.map(function(it) { | ||
return new Product(it); | ||
}); | ||
}; | ||
})(this)); | ||
}; | ||
ProductecaApi.prototype.getSalesOrders = function() { | ||
return this.returnMany(this.client.getAsync("/salesorders")); | ||
ProductecaApi.prototype.getSalesOrders = function(filters) { | ||
var querystring; | ||
if (filters == null) { | ||
filters = {}; | ||
} | ||
querystring = this._buildSalesOrdersFilters(filters); | ||
return this.returnMany(this.client.getAsync("/salesorders" + querystring)); | ||
}; | ||
@@ -62,2 +73,6 @@ | ||
ProductecaApi.prototype.updateSalesOrder = function(id, update) { | ||
return this["return"](this.client.putAsync("/salesorders/" + id, update)); | ||
}; | ||
ProductecaApi.prototype.updateStocks = function(adjustment) { | ||
@@ -106,2 +121,29 @@ var body, url; | ||
ProductecaApi.prototype._buildSalesOrdersFilters = function(filters) { | ||
var addAnd, brandsFilter, querystring; | ||
querystring = "?$filter=(IsOpen%20eq%20true)%20and%20(IsCanceled%20eq%20false)"; | ||
addAnd = (function(_this) { | ||
return function(condition) { | ||
return querystring += "%20and%20(" + condition + ")"; | ||
}; | ||
})(this); | ||
brandsFilter = (function(_this) { | ||
return function(brandIds) { | ||
return brandIds.map(function(id) { | ||
return "(Lines%2Fany(line%3Aline%2FVariation%2FDefinition%2FBrand%2FId%20eq%20" + id + "))"; | ||
}).join("%20or%20"); | ||
}; | ||
})(this); | ||
if (filters.paid != null) { | ||
addAnd("PaymentStatus%20eq%20%27Done%27"); | ||
} | ||
if (filters.brands != null) { | ||
addAnd(brandsFilter(filters.brands)); | ||
} | ||
if (filters.other != null) { | ||
addAnd(filters.other); | ||
} | ||
return querystring; | ||
}; | ||
ProductecaApi.prototype._makeUrlAsync = function(url) { | ||
@@ -108,0 +150,0 @@ var parts; |
@@ -8,3 +8,3 @@ { | ||
}, | ||
"version": "0.0.8", | ||
"version": "0.0.18", | ||
"main": "build/sdk.js", | ||
@@ -14,2 +14,3 @@ "dependencies": { | ||
"lodash": "~2.4.1", | ||
"q": "~1.0.1", | ||
"restify": "^2.8.2" | ||
@@ -23,3 +24,2 @@ }, | ||
"grunt-mocha-test": "~0.10.2", | ||
"q": "~1.0.1", | ||
"sinon": "^1.10.3", | ||
@@ -26,0 +26,0 @@ "sinon-chai": "^2.5.0" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
39826
7
660
4