producteca-sdk
Advanced tools
Comparing version 0.0.91 to 1.0.0
(function() { | ||
var Product, ProductecaApi, Promise, Restify, _, | ||
var ProductecaApi, Promise, Restify, | ||
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; | ||
@@ -9,6 +9,2 @@ | ||
_ = require("lodash"); | ||
Product = require("./product"); | ||
module.exports = ProductecaApi = (function() { | ||
@@ -34,23 +30,8 @@ ProductecaApi.prototype.initializeClients = function(endpoint) { | ||
function ProductecaApi(endpoint) { | ||
if (endpoint == null) { | ||
endpoint = {}; | ||
} | ||
this._makeUrlAsync = __bind(this._makeUrlAsync, this); | ||
this._buildSalesOrdersFilters = __bind(this._buildSalesOrdersFilters, this); | ||
this.returnMany = __bind(this.returnMany, this); | ||
this["return"] = __bind(this["return"], this); | ||
this.updateShipmentStatus = __bind(this.updateShipmentStatus, this); | ||
this.updateShipment = __bind(this.updateShipment, this); | ||
this.createShipment = __bind(this.createShipment, 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); | ||
this.getSalesOrderAndFullProducts = __bind(this.getSalesOrderAndFullProducts, this); | ||
this.getSalesOrder = __bind(this.getSalesOrder, 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.respondMany = __bind(this.respondMany, this); | ||
this.respond = __bind(this.respond, this); | ||
this.initializeClients = __bind(this.initializeClients, this); | ||
@@ -60,131 +41,3 @@ this.initializeClients(endpoint); | ||
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) { | ||
var querystring; | ||
if (filters == null) { | ||
filters = {}; | ||
} | ||
querystring = this._buildSalesOrdersFilters(filters); | ||
return this.returnMany(this.client.getAsync("/salesorders" + querystring)); | ||
}; | ||
ProductecaApi.prototype.getSalesOrder = function(id) { | ||
return this["return"](this.client.getAsync("/salesorders/" + id)); | ||
}; | ||
ProductecaApi.prototype.getSalesOrderAndFullProducts = function(id) { | ||
return this.getSalesOrder(id).then((function(_this) { | ||
return function(salesOrder) { | ||
var productIds; | ||
productIds = _.map(salesOrder.lines, "product.id").join(","); | ||
return _this.getMultipleProducts(productIds).then(function(products) { | ||
return { | ||
salesOrder: salesOrder, | ||
products: products | ||
}; | ||
}); | ||
}; | ||
})(this)); | ||
}; | ||
ProductecaApi.prototype.updateSalesOrder = function(id, update) { | ||
return this["return"](this.client.putAsync("/salesorders/" + id, update)); | ||
}; | ||
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) { | ||
return this["return"](this.client.getAsync("/salesorders/" + salesOrderId + "/shipments/" + shipmentId)); | ||
}; | ||
ProductecaApi.prototype.createShipment = function(salesOrderId, shipment) { | ||
return this["return"](this.client.postAsync("/salesorders/" + salesOrderId + "/shipments", shipment)); | ||
}; | ||
ProductecaApi.prototype.updateShipment = function(salesOrderId, shipmentId, shipmentUpdate) { | ||
return this["return"](this.client.putAsync("/salesorders/" + salesOrderId + "/shipments/" + shipmentId, shipmentUpdate)); | ||
}; | ||
ProductecaApi.prototype.updateShipmentStatus = function(salesOrderId, shipmentId, statusDto) { | ||
return this["return"](this.client.putAsync("/salesorders/" + salesOrderId + "/shipments/" + shipmentId + "/status", statusDto)); | ||
}; | ||
ProductecaApi.prototype["return"] = function(promise) { | ||
ProductecaApi.prototype.respond = function(promise) { | ||
return promise.spread(function(req, res, obj) { | ||
@@ -195,3 +48,3 @@ return obj; | ||
ProductecaApi.prototype.returnMany = function(promise) { | ||
ProductecaApi.prototype.respondMany = function(promise) { | ||
return promise.spread(function(req, res, obj) { | ||
@@ -202,29 +55,2 @@ return obj.results; | ||
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%27Approved%27"); | ||
} | ||
if (filters.brands != null) { | ||
addAnd(brandsFilter(filters.brands)); | ||
} | ||
if (filters.other != null) { | ||
addAnd(filters.other); | ||
} | ||
return querystring; | ||
}; | ||
ProductecaApi.prototype._makeUrlAsync = function(url) { | ||
@@ -231,0 +57,0 @@ var parts; |
(function() { | ||
module.exports = { | ||
Api: require("./productecaApi"), | ||
Sync: { | ||
Adjustment: require("./syncer/adjustment"), | ||
Syncer: require("./syncer/syncer") | ||
} | ||
ProductsApi: require("./productsApi"), | ||
SalesOrdersApi: require("./salesOrdersApi") | ||
}; | ||
}).call(this); |
@@ -8,3 +8,3 @@ { | ||
}, | ||
"version": "0.0.91", | ||
"version": "1.0.0", | ||
"main": "build/sdk.js", | ||
@@ -20,8 +20,9 @@ "dependencies": { | ||
"grunt": "~0.4.4", | ||
"grunt-bump": "^0.3.1", | ||
"grunt-contrib-clean": "~0.5.0", | ||
"grunt-contrib-coffee": "^0.10.1", | ||
"grunt-mocha-test": "~0.10.2", | ||
"nock": "^2.17.0", | ||
"sinon": "^1.10.3", | ||
"sinon-chai": "^2.5.0", | ||
"grunt-bump": "^0.3.1" | ||
"sinon-chai": "^2.5.0" | ||
}, | ||
@@ -28,0 +29,0 @@ "engines": { |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
41633
9
24
510
1