Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getOrdersByUserId(userId, month = 4) {
- const apiService = new ApiService();
- return apiService.getOrdersList(`?OrderingUser=${userId}`)
- .then(orders => {
- const monthOrders = orders.filter(order => new Date(order.FromTime)
- .getMonth() === month);
- return monthOrders;
- });
- }
- getOrdersList(queryString = '') {
- return httpsRequest.createRequest(this.URL.ordersList + queryString, {}, this.requestHeaders, 'GET')
- .then(result => JSON.parse(result).Records);
- }
- const promises = userIds.map(userId => {
- return getOrdersByUserId(userId, month)
- .then(orders => {
- return orders;
- });
- });
- Promise.all(promises).then(results => {
- console.log(results);
- }).catch(err => {
- console.log(err);
- });
- (node:1) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): SyntaxError: Unexpected end of JSON input
- const results =
- userIds.reduce((acc, userId, index) => {
- acc.p =
- p.then(getOrdersByUserId(userId, month))
- .then(orders => {
- return acc.results[index] = orders;
- });
- return acc;
- }, {p: Promise.resolve(), results: []})
- .then(acc => acc.results)
- .then(results => {
- // `results` is an array of results, in the same order as `userIds`
- })
- .catch(err => {
- console.log(err);
- });
Add Comment
Please, Sign In to add comment