refactor(subaccounts): use internal ID instead of external ID in requests
MODIFY
src/assets/server/rest/v1/schemas/billing/billing-activate-sub-account.json
src/assets/server/rest/v1/schemas/billing/billing-activate-sub-account.json
"type": "object",
"properties": {
"subAccountID": {
- "type": "string",
- "sanitize": "mongo"
+ "$ref": "common#/definitions/id"
}
},
"required": [

MODIFY
src/server/rest/v1/service/BillingService.ts
src/server/rest/v1/service/BillingService.ts
@@ -520,7 +520,7 @@ export default class BillingService {
user: req.user
});
}
- const subAccount = await BillingStorage.getSubAccountByAccountID(req.tenant, filteredRequest.subAccountID);
+ const subAccount = await BillingStorage.getSubAccountByID(req.tenant, filteredRequest.subAccountID);
UtilsService.assertObjectExists(action, subAccount, `Sub account ID '${filteredRequest.subAccountID}' does not exist`, MODULE_NAME, 'handleActivateSubAccount', req.user);
// Check if the sub account is already activated
if (!subAccount.pending) {

MODIFY
src/storage/mongodb/BillingStorage.ts
src/storage/mongodb/BillingStorage.ts
@@ -339,9 +339,9 @@ export default class BillingStorage {
};
}
- public static async getSubAccountByAccountID(tenant: Tenant, accountID: string): Promise<BillingAccount> {
+ public static async getSubAccountByID(tenant: Tenant, id: string): Promise<BillingAccount> {
const subAccountMDB = await BillingStorage.getSubAccounts(tenant, {
- subAccountAccountIDs: [accountID]
+ subAccountIDs: [id]
}, Constants.DB_PARAMS_SINGLE_RECORD);
return subAccountMDB.count === 1 ? subAccountMDB.result[0] : null;
}

MODIFY
test/api/BillingTest.ts
test/api/BillingTest.ts
@@ -412,13 +412,13 @@ describeif(isBillingProperlyConfigured)('Billing', () => {
});
expect(response.status).to.be.eq(StatusCodes.CREATED);
- const activationResponse = await billingTestHelper.userService.billingApi.activateSubAccount({ accountID: response.data.accountID });
+ const activationResponse = await billingTestHelper.userService.billingApi.activateSubAccount({ accountID: response.data.id });
expect(activationResponse.status).to.be.eq(StatusCodes.OK);
expect(activationResponse.data.pending).to.be.false;
});
it('should not activate an inexistent sub account', async () => {
- const activationResponse = await billingTestHelper.userService.billingApi.activateSubAccount({ accountID: 'xxx' });
+ const activationResponse = await billingTestHelper.userService.billingApi.activateSubAccount({ accountID: '5ce249a1a39ae1c056c389bd' });
expect(activationResponse.status).to.be.eq(HTTPError.OBJECT_DOES_NOT_EXIST_ERROR);
});
@@ -428,9 +428,9 @@ describeif(isBillingProperlyConfigured)('Billing', () => {
});
expect(response.status).to.be.eq(StatusCodes.CREATED);
- let activationResponse = await billingTestHelper.userService.billingApi.activateSubAccount({ accountID: response.data.accountID });
+ let activationResponse = await billingTestHelper.userService.billingApi.activateSubAccount({ accountID: response.data.id });
expect(activationResponse.status).to.be.eq(StatusCodes.OK);
- activationResponse = await billingTestHelper.userService.billingApi.activateSubAccount({ accountID: response.data.accountID });
+ activationResponse = await billingTestHelper.userService.billingApi.activateSubAccount({ accountID: response.data.id });
expect(activationResponse.status).to.be.eq(StatusCodes.INTERNAL_SERVER_ERROR);
});
});
@@ -501,7 +501,7 @@ describeif(isBillingProperlyConfigured)('Billing', () => {
});
it('should not activate an inexistent sub account', async () => {
- const activationResponse = await billingTestHelper.userService.billingApi.activateSubAccount({ accountID: 'xxx' });
+ const activationResponse = await billingTestHelper.userService.billingApi.activateSubAccount({ accountID: '5ce249a1a39ae1c056c389bd' });
expect(activationResponse.status).to.be.eq(HTTPError.OBJECT_DOES_NOT_EXIST_ERROR);
});
});

refactor(subaccounts): use internal ID instead of external ID in requests