Skip to content

Commit

Permalink
feat(updatecustomerpowerusers): check plan total license pool and upd…
Browse files Browse the repository at this point in the history
…ate if flag is passed
  • Loading branch information
zauroch committed Aug 17, 2021
1 parent 3d4bd75 commit 6674ad4
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,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 +337,18 @@ 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
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 6674ad4

Please sign in to comment.