-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(list-orders): fix method to output errors, add pagination
- Loading branch information
Showing
1 changed file
with
11 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |