Skip to content

Commit

Permalink
Merge pull request #84 from pliancy/feature/auto-add-to-pool
Browse files Browse the repository at this point in the history
Feature/auto add to pool
  • Loading branch information
santese authored Aug 17, 2021
2 parents 3d4bd75 + dded07e commit 812bf3c
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ class Egnyte {
Cookie: `${authCookie}; csrftoken=${csrfToken}`,
'X-Requested-With': 'XMLHttpRequest',
'X-CSRFToken': csrfToken,
Referer: 'https://resellers.egnyte.com',
},
data: {
plan_id: planId,
Expand All @@ -315,10 +316,14 @@ class Egnyte {
* @param numOfUsers how many licenses to assign to customer
* @returns response object
*/
async updateCustomerPowerUsers(customerId: string, numOfUsers: number): Promise<any> {
async updateCustomerPowerUsers(
customerId: string,
numOfUsers: number,
autoAddToPool?: boolean,
): Promise<any> {
customerId = customerId.toLowerCase()
const customer = await this.getOneCustomer(customerId)
if (customer.powerUsers.available <= 0)
if (customer.powerUsers.available <= 0 && !autoAddToPool)
throw new Error('No available licenses on customers reseller plan.')
if (numOfUsers < customer.powerUsers.used && this._config.forceLicenseChange !== true) {
const response: EgnyteUpdateResponse = {
Expand All @@ -333,6 +338,19 @@ class Egnyte {
}
return response
}
if (autoAddToPool) {
const plans = await this.getPlans()
const { planId, totalPowerUsers, availablePowerUsers } = plans.find(
(e: any) => e.planId === customer.planId,
)
const usersNeeded = numOfUsers - customer.powerUsers.total
if (usersNeeded > availablePowerUsers) {
const licensesToAdd = Math.ceil((usersNeeded - availablePowerUsers) / 5) * 5
const updatedLicenesTotal = licensesToAdd + totalPowerUsers

await this.UpdatePowerUserLicensing(planId, updatedLicenesTotal)
}
}
const { authCookie, csrfToken } = await this._authenticate()

const res = await this._egnyteRequest(`/msp/change_power_users/${this.resellerId}/`, {
Expand Down

0 comments on commit 812bf3c

Please sign in to comment.