producteca-sdk
Advanced tools
Comparing version 0.0.45 to 0.0.62
@@ -9,22 +9,25 @@ (function() { | ||
function Product(properties) { | ||
this.updatePrice = __bind(this.updatePrice, this); | ||
this.getVariationForAdjustment = __bind(this.getVariationForAdjustment, this); | ||
this.hasVariantes = __bind(this.hasVariantes, this); | ||
this.updateWith = __bind(this.updateWith, this); | ||
this.toJSON = __bind(this.toJSON, this); | ||
this.hasAllDimensions = __bind(this.hasAllDimensions, this); | ||
this.updatePrice = __bind(this.updatePrice, this); | ||
this.firstVariation = __bind(this.firstVariation, this); | ||
this.getVariationForAdjustment = __bind(this.getVariationForAdjustment, this); | ||
this.hasVariantes = __bind(this.hasVariantes, this); | ||
this.findVariationBySku = __bind(this.findVariationBySku, this); | ||
this.hasVariations = __bind(this.hasVariations, this); | ||
_.extend(this, properties); | ||
} | ||
Product.prototype.hasVariantes = function() { | ||
return _.size(this.variations > 1); | ||
Product.prototype.hasVariations = function() { | ||
return _.size(this.variations) > 1; | ||
}; | ||
Product.prototype.getVariationForAdjustment = function(adjustment) { | ||
return _.find(this.variations, (function(_this) { | ||
return function(it) { | ||
return it.barcode === adjustment.identifier; | ||
}; | ||
})(this)); | ||
Product.prototype.findVariationBySku = function(sku) { | ||
if (!this.hasVariations()) { | ||
return this.firstVariation(); | ||
} | ||
return _.find(this.variations, { | ||
sku: sku | ||
}); | ||
}; | ||
@@ -36,11 +39,2 @@ | ||
Product.prototype.updatePrice = function(priceList, amount) { | ||
return this.prices = _(this.prices).reject({ | ||
priceList: priceList | ||
}).concat({ | ||
priceList: priceList, | ||
amount: amount | ||
}).value(); | ||
}; | ||
Product.prototype.hasAllDimensions = function() { | ||
@@ -62,2 +56,23 @@ return ["width", "height", "length", "weight"].every((function(_this) { | ||
Product.prototype.hasVariantes = function() { | ||
return this.hasVariations(); | ||
}; | ||
Product.prototype.getVariationForAdjustment = function(adjustment) { | ||
return _.find(this.variations, (function(_this) { | ||
return function(it) { | ||
return it.barcode === adjustment.identifier; | ||
}; | ||
})(this)); | ||
}; | ||
Product.prototype.updatePrice = function(priceList, amount) { | ||
return this.prices = _(this.prices).reject({ | ||
priceList: priceList | ||
}).concat({ | ||
priceList: priceList, | ||
amount: amount | ||
}).value(); | ||
}; | ||
return Product; | ||
@@ -64,0 +79,0 @@ |
(function() { | ||
var Product, ProductecaApi, Promise, Restify, _, | ||
var ProductecaApi, ProductsApi, Promise, Restify, _, | ||
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; | ||
@@ -11,3 +11,3 @@ | ||
Product = require("./product"); | ||
ProductsApi = require("./productsApi"); | ||
@@ -34,2 +34,12 @@ module.exports = ProductecaApi = (function() { | ||
function ProductecaApi(endpoint) { | ||
if (endpoint == null) { | ||
endpoint = {}; | ||
} | ||
this.createProduct = __bind(this.createProduct, this); | ||
this.updateProduct = __bind(this.updateProduct, this); | ||
this.updatePrice = __bind(this.updatePrice, this); | ||
this.updateStocks = __bind(this.updateStocks, this); | ||
this.getMultipleProducts = __bind(this.getMultipleProducts, this); | ||
this.getProducts = __bind(this.getProducts, this); | ||
this.getProduct = __bind(this.getProduct, this); | ||
this._makeUrlAsync = __bind(this._makeUrlAsync, this); | ||
@@ -43,6 +53,2 @@ this._buildSalesOrdersFilters = __bind(this._buildSalesOrdersFilters, this); | ||
this.getShipment = __bind(this.getShipment, this); | ||
this.createProduct = __bind(this.createProduct, this); | ||
this.updateProduct = __bind(this.updateProduct, this); | ||
this.updatePrice = __bind(this.updatePrice, this); | ||
this.updateStocks = __bind(this.updateStocks, this); | ||
this.updateSalesOrder = __bind(this.updateSalesOrder, this); | ||
@@ -52,57 +58,10 @@ this.getSalesOrderAndFullProducts = __bind(this.getSalesOrderAndFullProducts, this); | ||
this.getSalesOrders = __bind(this.getSalesOrders, this); | ||
this._createProducts = __bind(this._createProducts, this); | ||
this.getMultipleProducts = __bind(this.getMultipleProducts, this); | ||
this._getProductsPageByPage = __bind(this._getProductsPageByPage, this); | ||
this.getProducts = __bind(this.getProducts, this); | ||
this.getProduct = __bind(this.getProduct, this); | ||
this.initializeClients = __bind(this.initializeClients, this); | ||
this.initializeClients(endpoint); | ||
this.productsApi = new ProductsApi({ | ||
client: this.client, | ||
asyncClient: this.asyncClient | ||
}); | ||
} | ||
ProductecaApi.prototype.getProduct = function(id) { | ||
return this["return"](this.client.getAsync("/products/" + id)); | ||
}; | ||
ProductecaApi.prototype.getProducts = function() { | ||
return this._getProductsPageByPage().then((function(_this) { | ||
return function(products) { | ||
return _this._createProducts(products); | ||
}; | ||
})(this)); | ||
}; | ||
ProductecaApi.prototype._getProductsPageByPage = function(skip) { | ||
var TOP; | ||
if (skip == null) { | ||
skip = 0; | ||
} | ||
TOP = 500; | ||
return this["return"](this.client.getAsync("/products?$top=" + TOP + "&$skip=" + skip)).then((function(_this) { | ||
return function(obj) { | ||
var products; | ||
products = obj.results; | ||
if (products.length < TOP) { | ||
return products; | ||
} | ||
return _this._getProductsPageByPage(skip + TOP).then(function(moreProducts) { | ||
return products.concat(moreProducts); | ||
}); | ||
}; | ||
})(this)); | ||
}; | ||
ProductecaApi.prototype.getMultipleProducts = function(ids) { | ||
return this["return"](this.client.getAsync("/products?ids=" + ids)).then((function(_this) { | ||
return function(products) { | ||
return _this._createProducts(products); | ||
}; | ||
})(this)); | ||
}; | ||
ProductecaApi.prototype._createProducts = function(products) { | ||
return products.map(function(it) { | ||
return new Product(it); | ||
}); | ||
}; | ||
ProductecaApi.prototype.getSalesOrders = function(filters) { | ||
@@ -140,36 +99,2 @@ var querystring; | ||
ProductecaApi.prototype.updateStocks = function(adjustment) { | ||
var body, url; | ||
body = _.map(adjustment.stocks, function(it) { | ||
return { | ||
variation: it.variation, | ||
stocks: [ | ||
{ | ||
warehouse: adjustment.warehouse, | ||
quantity: it.quantity | ||
} | ||
] | ||
}; | ||
}); | ||
url = "/products/" + adjustment.id + "/stocks"; | ||
return this["return"](this.asyncClient.putAsync(url, body)); | ||
}; | ||
ProductecaApi.prototype.updatePrice = function(product, priceList, amount) { | ||
product.updatePrice(priceList, amount); | ||
return this.updateProduct(product); | ||
}; | ||
ProductecaApi.prototype.updateProduct = function(product) { | ||
var url; | ||
url = "/products/" + product.id; | ||
return this["return"](this.asyncClient.putAsync(url, _.omit(product.toJSON(), ["variations"]))); | ||
}; | ||
ProductecaApi.prototype.createProduct = function(product) { | ||
var url; | ||
url = "/products"; | ||
return this["return"](this.asyncClient.postAsync(url, product)); | ||
}; | ||
ProductecaApi.prototype.getShipment = function(salesOrderId, shipmentId) { | ||
@@ -237,2 +162,30 @@ return this["return"](this.client.getAsync("/salesorders/" + salesOrderId + "/shipments/" + shipmentId)); | ||
ProductecaApi.prototype.getProduct = function(id) { | ||
return this.productsApi.getProduct(id); | ||
}; | ||
ProductecaApi.prototype.getProducts = function() { | ||
return this.productsApi.getProducts(); | ||
}; | ||
ProductecaApi.prototype.getMultipleProducts = function(ids) { | ||
return this.productsApi.getMultipleProducts(ids); | ||
}; | ||
ProductecaApi.prototype.updateStocks = function(adjustment) { | ||
return this.productsApi.updateStocks(adjustment); | ||
}; | ||
ProductecaApi.prototype.updatePrice = function(product, priceList, amount) { | ||
return this.productsApi.updatePrice(product, priceList, amount); | ||
}; | ||
ProductecaApi.prototype.updateProduct = function(product) { | ||
return this.productsApi.updateProductAsync(product); | ||
}; | ||
ProductecaApi.prototype.createProduct = function(product) { | ||
return this.productsApi.createProductAsync(product); | ||
}; | ||
return ProductecaApi; | ||
@@ -239,0 +192,0 @@ |
@@ -195,3 +195,5 @@ (function() { | ||
}) : void 0; | ||
withCodeAdjustments = _.values(_.omit(groupedAdjustmentsObj, void 0)); | ||
withCodeAdjustments = _.values(_.omit(groupedAdjustmentsObj, function(it) { | ||
return it === void 0; | ||
})); | ||
return withCodeAdjustments.concat(noCodeAdjustments || []).map((function(_this) { | ||
@@ -198,0 +200,0 @@ return function(adjustments) { |
@@ -8,3 +8,3 @@ { | ||
}, | ||
"version": "0.0.45", | ||
"version": "0.0.62", | ||
"main": "build/sdk.js", | ||
@@ -11,0 +11,0 @@ "dependencies": { |
# Producteca SDK |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
96572
31
1672