Skip to content

Commit

Permalink
feat: list trip expenses sequentially to better handle rate limiting (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
braaar authored Dec 13, 2023
1 parent e66e8fa commit 6c14b40
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/abax-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,19 @@ export class AbaxClient {
[[]],
);

const expenses = await Promise.all(
tripIdBatches.map(batch =>
this.list150TripExpenses({ query: { trip_ids: batch } }),
),
);
const expenses: listTripExpensesResponse['items'][] = [];

for (const batch of tripIdBatches) {
const response = await this.list150TripExpenses({
query: { trip_ids: batch },
});

return { items: expenses.flatMap(expense => expense.items) };
expenses.push(response.items);
}

const items = expenses.flat(1);

return { items };
}

/** Gets odometer values of trips. Required scopes: `abax_profile`, `open_api`, `open_api.trips`.*/
Expand Down

0 comments on commit 6c14b40

Please sign in to comment.