Skip to content

Commit

Permalink
fix(list-orders): fix method to output errors, add pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
leomp12 committed Aug 22, 2019
1 parent c625092 commit 5bef449
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions src/methods/list-orders.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
export default (self) => {
const customer = self.getCustomer()
let list = []
// public api
list = customer.orders.map(async order => {
const options = {
url: `/orders/${order._id}.json`
}
let result = await self.ecomClient
.store(options)
.then(resp => resp.data)
.catch(err => console.error('E-Com Plus API request failed:', err))
return result
})
return Promise.all(list)
import { store } from '@ecomplus/client'

export default (self, from = 0, size = 10) => {
const { orders } = self.getCustomer()
const results = []
const promises = []
for (let i = 0; i < orders.length && i < (from + size); i++) {
promises.push(store({ url: `/orders/${orders[i]._id}.json` })
.then(data => results.push(data)))
}
return Promise.all(promises).then(() => results)
}

0 comments on commit 5bef449

Please sign in to comment.