Make Product service more simple, there's no need to keep the data structure, that is already kept in the controller

This commit is contained in:
luisramos0
2019-11-22 14:51:31 +00:00
parent a66a4c3edb
commit f5ddbfbac3

View File

@@ -1,22 +1,15 @@
angular.module('admin.orderCycles').factory('Product', ($resource) ->
Product = $resource('/api/exchanges/:exchange_id/products.json', {}, {
ProductResource = $resource('/api/exchanges/:exchange_id/products.json', {}, {
'index':
method: 'GET'
isArray: true
})
{
Product: Product
products: {}
ProductResource: ProductResource
loaded: false
index: (params={}, callback=null) ->
Product.index params, (data) =>
@products[params.enterprise_id] = []
for product in data
@products[params.enterprise_id].push(product)
ProductResource.index params, (data) =>
@loaded = true
(callback || angular.noop)(@products[params.enterprise_id])
this.products
(callback || angular.noop)(data)
})