Skip to content

Commit

Permalink
Merge pull request #124 from pliancy/fix/skip-failed-customers
Browse files Browse the repository at this point in the history
Fix/skip failed customers
  • Loading branch information
santese authored Aug 9, 2024
2 parents bfe5846 + 6690045 commit f71108c
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/lib/customers/customers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class Customers extends Base {

/**
* retrieves all customer data from multiple egnyte resellers API endpoints and models it to be actually readable
* this will skip any customers whose plan throws an error
* @returns array of customer objects containing useful stuff
*/
async getAllCustomers(): Promise<EgnyteCustomer[]> {
Expand All @@ -31,13 +32,20 @@ export class Customers extends Base {

const customers = []
for (const planId of planIds) {
const usageStatsRes = await this.http.get(
`/msp/usage_stats/${this.resellerId}/${planId}/`,
{
headers: { cookie: authCookie, 'X-CSRFToken': csrfToken },
},
)
for (const customer of usageStatsRes.data) {
let usageStats: EgnyteCustomer[]
try {
const res = await this.http.get(`/msp/usage_stats/${this.resellerId}/${planId}/`, {
headers: {
cookie: authCookie,
'X-CSRFToken': csrfToken,
},
})
usageStats = res.data
} catch (e) {
continue
}

for (const customer of usageStats) {
const [customerEgnyteId, ref] = Object.entries(customer)[0] as [string, UsageStats]

const obj: EgnyteCustomer = {
Expand Down

0 comments on commit f71108c

Please sign in to comment.