billing platform - renaming userID
MODIFY
src/assets/server/rest/v1/docs/e-mobility-oas.json
src/assets/server/rest/v1/docs/e-mobility-oas.json
"application/json": {
"schema": {
"required": [
- "userID"
+ "businessOwnerID"
],
"properties": {
- "userID": {
+ "businessOwnerID": {
"type": "string"
}
}
"content": {
"application/json": {
"example": {
- "userID": "###",
- "accountID": "###",
+ "businessOwnerID": "###",
+ "accountExternalID": "###",
"activationLink": "###",
- "pending": true,
+ "status": "idle",
"id": "###"
}
}

MODIFY
src/assets/server/rest/v1/schemas/billing/billing-create-sub-account.json
src/assets/server/rest/v1/schemas/billing/billing-create-sub-account.json
"title": "Create a Billing sub-account Request",
"type": "object",
"properties": {
- "userID": {
+ "businessOwnerID": {
"$ref": "common#/definitions/id"
}
},
"required": [
- "userID"
+ "businessOwnerID"
]
}

MODIFY
src/server/rest/v1/service/BillingService.ts
src/server/rest/v1/service/BillingService.ts
@@ -490,8 +490,8 @@ export default class BillingService {
});
}
// Get the user
- const user = await UserStorage.getUser(req.tenant, filteredRequest.userID);
- UtilsService.assertObjectExists(action, user, `User ID '${filteredRequest.userID}' does not exist`,
+ const user = await UserStorage.getUser(req.tenant, filteredRequest.businessOwnerID);
+ UtilsService.assertObjectExists(action, user, `User ID '${filteredRequest.businessOwnerID}' does not exist`,
MODULE_NAME, 'handleCreateSubAccount', req.user);
// Create the sub account
const subAccount = await billingImpl.createSubAccount();

MODIFY
src/storage/mongodb/BillingStorage.ts
src/storage/mongodb/BillingStorage.ts
@@ -223,9 +223,9 @@ export default class BillingStorage {
// Properties to save
const subAccountMDB: any = {
_id: subAccount.id ? DatabaseUtils.convertToObjectID(subAccount.id) : new ObjectId(),
- accountID: subAccount.accountExternalID,
+ accountExternalID: subAccount.accountExternalID,
status: subAccount.status,
- userID: DatabaseUtils.convertToObjectID(subAccount.businessOwnerID)
+ businessOwnerID: DatabaseUtils.convertToObjectID(subAccount.businessOwnerID)
};
// Modify and return the modified document
await global.database.getCollection<any>(tenant.id, 'billingsubaccounts').findOneAndUpdate(
@@ -258,7 +258,7 @@ export default class BillingStorage {
// Filter by other properties
if (params.search) {
filters.$or = [
- { 'accountID': { $regex: params.search, $options: 'i' } }
+ { 'accountExternalID': { $regex: params.search, $options: 'i' } }
];
}
if (!Utils.isEmptyArray(params.subAccountIDs)) {
@@ -317,7 +317,7 @@ export default class BillingStorage {
});
// Add Users
DatabaseUtils.pushUserLookupInAggregation({
- tenantID: tenant.id, aggregation: aggregation, asField: 'user', localField: 'userID',
+ tenantID: tenant.id, aggregation: aggregation, asField: 'user', localField: 'businessOwnerID',
foreignField: '_id', oneToOneCardinality: true, oneToOneCardinalityNotNull: false
});
// Add Last Changed / Created
@@ -325,7 +325,7 @@ export default class BillingStorage {
// Handle the ID
DatabaseUtils.pushRenameDatabaseID(aggregation);
// Convert Object ID to string
- DatabaseUtils.pushConvertObjectIDToString(aggregation, 'userID');
+ DatabaseUtils.pushConvertObjectIDToString(aggregation, 'businessOwnerID');
// Project
DatabaseUtils.projectFields(aggregation, projectFields);
// Read DB

MODIFY
src/types/requests/HttpBillingRequest.ts
src/types/requests/HttpBillingRequest.ts
@@ -30,7 +30,7 @@ export interface HttpDeletePaymentMethod {
}
export interface HttpBillingSubAccountCreateRequest {
- userID: string;
+ businessOwnerID: string;
}
export interface HttpBillingSubAccountActivateRequest {

MODIFY
test/api/BillingTest.ts
test/api/BillingTest.ts
@@ -979,20 +979,21 @@ describeif(isBillingProperlyConfigured)('Billing', () => {
describe('Sub accounts', () => {
it('should create a sub account', async () => {
const response = await billingTestHelper.userService.billingApi.createSubAccount({
- userID: billingTestHelper.userContext.id
+ businessOwnerID: billingTestHelper.userContext.id
});
+ const subAccount = response.data as BillingAccount;
expect(response.status).to.be.eq(StatusCodes.CREATED);
- expect(response.data.id).to.not.be.null;
- expect(response.data.accountID).to.not.be.null;
- expect(response.data.userID).to.eq(billingTestHelper.userContext.id);
- expect(response.data.activationLink).to.not.be.null;
- expect(response.data.status).to.be.eq(BillingAccountStatus.IDLE);
+ expect(subAccount.id).to.not.be.null;
+ expect(subAccount.accountExternalID).to.not.be.null;
+ expect(subAccount.businessOwnerID).to.eq(billingTestHelper.userContext.id);
+ expect(subAccount.activationLink).to.not.be.null;
+ expect(subAccount.status).to.be.eq(BillingAccountStatus.IDLE);
});
it('should create a sub account and activate it', async () => {
// Create a sub account
const response = await billingTestHelper.userService.billingApi.createSubAccount({
- userID: billingTestHelper.userContext.id
+ businessOwnerID: billingTestHelper.userContext.id
});
expect(response.status).to.be.eq(StatusCodes.CREATED);
// Send the activation link
@@ -1013,7 +1014,7 @@ describeif(isBillingProperlyConfigured)('Billing', () => {
it('should not activate a sub account twice', async () => {
// Create a sub account
const response = await billingTestHelper.userService.billingApi.createSubAccount({
- userID: billingTestHelper.userContext.id
+ businessOwnerID: billingTestHelper.userContext.id
});
expect(response.status).to.be.eq(StatusCodes.CREATED);
// Send the activation link
@@ -1028,7 +1029,7 @@ describeif(isBillingProperlyConfigured)('Billing', () => {
it('should create a company assigned to a sub-account', async () => {
const subAccountResponse = await billingTestHelper.userService.billingApi.createSubAccount({
- userID: billingTestHelper.userContext.id
+ businessOwnerID: billingTestHelper.userContext.id
});
expect(subAccountResponse.status).to.be.eq(StatusCodes.CREATED);
@@ -1045,7 +1046,7 @@ describeif(isBillingProperlyConfigured)('Billing', () => {
it('should update a company to assign a sub-account', async () => {
const subAccountResponse = await billingTestHelper.userService.billingApi.createSubAccount({
- userID: billingTestHelper.userContext.id
+ businessOwnerID: billingTestHelper.userContext.id
});
expect(subAccountResponse.status).to.be.eq(StatusCodes.CREATED);
@@ -1065,7 +1066,7 @@ describeif(isBillingProperlyConfigured)('Billing', () => {
it('should create a site assigned to a sub-account', async () => {
const subAccountResponse = await billingTestHelper.userService.billingApi.createSubAccount({
- userID: billingTestHelper.userContext.id
+ businessOwnerID: billingTestHelper.userContext.id
});
expect(subAccountResponse.status).to.be.eq(StatusCodes.CREATED);
@@ -1087,7 +1088,7 @@ describeif(isBillingProperlyConfigured)('Billing', () => {
it('should update a site to assign a sub-account', async () => {
const subAccountResponse = await billingTestHelper.userService.billingApi.createSubAccount({
- userID: billingTestHelper.userContext.id
+ businessOwnerID: billingTestHelper.userContext.id
});
expect(subAccountResponse.status).to.be.eq(StatusCodes.CREATED);
@@ -1116,7 +1117,7 @@ describeif(isBillingProperlyConfigured)('Billing', () => {
it('should list sub-accounts', async () => {
const subAccountResponse = await billingTestHelper.userService.billingApi.createSubAccount({
- userID: billingTestHelper.userContext.id
+ businessOwnerID: billingTestHelper.userContext.id
});
expect(subAccountResponse.status).to.be.eq(StatusCodes.CREATED);
@@ -1128,7 +1129,7 @@ describeif(isBillingProperlyConfigured)('Billing', () => {
it('should read sub-account', async () => {
const subAccountCreateResponse = await billingTestHelper.userService.billingApi.createSubAccount({
- userID: billingTestHelper.userContext.id
+ businessOwnerID: billingTestHelper.userContext.id
});
expect(subAccountCreateResponse.status).to.be.eq(StatusCodes.CREATED);
@@ -1142,7 +1143,7 @@ describeif(isBillingProperlyConfigured)('Billing', () => {
it('should send sub-account onboarding', async () => {
const subAccountCreateResponse = await billingTestHelper.userService.billingApi.createSubAccount({
- userID: billingTestHelper.userContext.id
+ businessOwnerID: billingTestHelper.userContext.id
});
expect(subAccountCreateResponse.status).to.be.eq(StatusCodes.CREATED);
@@ -1153,7 +1154,7 @@ describeif(isBillingProperlyConfigured)('Billing', () => {
it('should not able to send sub-account onboarding twice', async () => {
const subAccountCreateResponse = await billingTestHelper.userService.billingApi.createSubAccount({
- userID: billingTestHelper.userContext.id
+ businessOwnerID: billingTestHelper.userContext.id
});
expect(subAccountCreateResponse.status).to.be.eq(StatusCodes.CREATED);
@@ -1168,7 +1169,7 @@ describeif(isBillingProperlyConfigured)('Billing', () => {
it('should not able to send sub-account onboarding for an activated sub-account', async () => {
// Create the sub account
const subAccountCreateResponse = await billingTestHelper.userService.billingApi.createSubAccount({
- userID: billingTestHelper.userContext.id
+ businessOwnerID: billingTestHelper.userContext.id
});
expect(subAccountCreateResponse.status).to.be.eq(StatusCodes.CREATED);
// Send onboarding
@@ -1200,7 +1201,7 @@ describeif(isBillingProperlyConfigured)('Billing', () => {
it('should not be able to create a sub account', async () => {
const response = await billingTestHelper.userService.billingApi.createSubAccount({
- userID: billingTestHelper.userContext.id
+ businessOwnerID: billingTestHelper.userContext.id
});
expect(response.status).to.be.eq(StatusCodes.FORBIDDEN);
});

billing platform - renaming userID