refactor(billing): various renaming
MODIFY
src/assets/server/rest/v1/docs/e-mobility-oas.json
src/assets/server/rest/v1/docs/e-mobility-oas.json
"issuer": {
"type": "boolean",
"readOnly": true
+ },
+ "accountData": {
+ "type": "object",
+ "properties": {
+ "accountID": {
+ "type": "string"
+ }
+ }
}
}
},
"id": {
"type": "string",
"readOnly": true
+ },
+ "accountData": {
+ "type": "object",
+ "properties": {
+ "accountID": {
+ "type": "string"
+ }
+ }
}
}
},

MODIFY
src/assets/server/rest/v1/schemas/company/company-create.json
src/assets/server/rest/v1/schemas/company/company-create.json
"logo": {
"$ref": "common#/definitions/logo"
},
- "billingData": {
+ "accountData": {
"type": "object",
"properties": {
"accountID": {

MODIFY
src/assets/server/rest/v1/schemas/company/company-update.json
src/assets/server/rest/v1/schemas/company/company-update.json
"logo": {
"$ref": "common#/definitions/logo"
},
- "billingData": {
+ "accountData": {
"type": "object",
"properties": {
"accountID": {

MODIFY
src/assets/server/rest/v1/schemas/site/site-create.json
src/assets/server/rest/v1/schemas/site/site-create.json
"image": {
"$ref": "site#/definitions/image"
},
- "billingData": {
+ "accountData": {
"type": "object",
"properties": {
"accountID": {

MODIFY
src/assets/server/rest/v1/schemas/site/site-update.json
src/assets/server/rest/v1/schemas/site/site-update.json
"image": {
"$ref": "site#/definitions/image"
},
- "billingData": {
+ "accountData": {
"type": "object",
"properties": {
"accountID": {

MODIFY
src/authorization/AuthorizationsDefinition.ts
src/authorization/AuthorizationsDefinition.ts
@@ -175,7 +175,7 @@ export const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
'id', 'name', 'address.address1', 'address.address2', 'address.postalCode', 'address.city',
'address.department', 'address.region', 'address.country',
'address.coordinates', 'logo', 'issuer', 'distanceMeters', 'createdOn', 'lastChangedOn',
- 'createdBy.name', 'createdBy.firstName', 'lastChangedBy.name', 'lastChangedBy.firstName', 'billingData.accountID'
+ 'createdBy.name', 'createdBy.firstName', 'lastChangedBy.name', 'lastChangedBy.firstName', 'accountData.accountID'
]
},
{
@@ -218,7 +218,7 @@ export const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
attributes: [
'id', 'name', 'issuer', 'logo',
'address.address1', 'address.address2', 'address.postalCode', 'address.city',
- 'address.department', 'address.region', 'address.country', 'address.coordinates', 'billingData.accountID'
+ 'address.department', 'address.region', 'address.country', 'address.coordinates', 'accountData.accountID'
]
},
{
@@ -241,7 +241,7 @@ export const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
'address.department', 'address.region', 'address.country',
'address.coordinates', 'companyID', 'company.name', 'autoUserSiteAssignment', 'issuer',
'autoUserSiteAssignment', 'distanceMeters', 'public', 'createdOn', 'lastChangedOn',
- 'createdBy.name', 'createdBy.firstName', 'lastChangedBy.name', 'lastChangedBy.firstName', 'connectorStats', 'billingData.accountID'
+ 'createdBy.name', 'createdBy.firstName', 'lastChangedBy.name', 'lastChangedBy.firstName', 'connectorStats', 'accountData.accountID'
]
},
{
@@ -250,7 +250,7 @@ export const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
'id', 'name', 'companyID', 'company.name', 'autoUserSiteAssignment', 'issuer',
'autoUserSiteAssignment', 'distanceMeters', 'public', 'createdOn', 'lastChangedOn', 'tariffID',
'address.address1', 'address.address2', 'address.postalCode', 'address.city',
- 'address.department', 'address.region', 'address.country', 'address.coordinates', 'billingData.accountID'
+ 'address.department', 'address.region', 'address.country', 'address.coordinates', 'accountData.accountID'
]
},
{

MODIFY
src/server/rest/v1/service/CompanyService.ts
src/server/rest/v1/service/CompanyService.ts
@@ -147,12 +147,12 @@ export default class CompanyService {
createdOn: new Date()
} as Company;
// If the company is assigned to a billing sub-account, check if the billing is active
- if (filteredRequest.billingData) {
+ if (filteredRequest.accountData) {
UtilsService.assertComponentIsActiveFromToken(req.user, TenantComponents.BILLING_PLATFORM,
Action.CREATE, Entity.COMPANY, MODULE_NAME, 'handleCreateCompany');
- const billingSubAccount = await BillingStorage.getSubAccountByID(req.tenant, filteredRequest.billingData.accountID);
- UtilsService.assertObjectExists(action, billingSubAccount, `Billing Sub-Account ID '${filteredRequest.billingData.accountID}' does not exist`, MODULE_NAME, 'handleCreateCompany', req.user);
- newCompany.billingData = { accountID: billingSubAccount.id };
+ const billingSubAccount = await BillingStorage.getSubAccountByID(req.tenant, filteredRequest.accountData.accountID);
+ UtilsService.assertObjectExists(action, billingSubAccount, `Billing Sub-Account ID '${filteredRequest.accountData.accountID}' does not exist`, MODULE_NAME, 'handleCreateCompany', req.user);
+ newCompany.accountData = { accountID: billingSubAccount.id };
}
// Save
newCompany.id = await CompanyStorage.saveCompany(req.tenant, newCompany);
@@ -185,12 +185,12 @@ export default class CompanyService {
company.lastChangedBy = { 'id': req.user.id };
company.lastChangedOn = new Date();
// If the company is assigned to a billing sub-account, check if the billing is active
- if (filteredRequest.billingData) {
+ if (filteredRequest.accountData) {
UtilsService.assertComponentIsActiveFromToken(req.user, TenantComponents.BILLING_PLATFORM,
Action.CREATE, Entity.COMPANY, MODULE_NAME, 'handleUpdateCompany');
- const billingSubAccount = await BillingStorage.getSubAccountByID(req.tenant, filteredRequest.billingData.accountID);
- UtilsService.assertObjectExists(action, billingSubAccount, `Billing Sub-Account ID '${filteredRequest.billingData.accountID}' does not exist`, MODULE_NAME, 'handleUpdateCompany', req.user);
- company.billingData = { accountID: billingSubAccount.id };
+ const billingSubAccount = await BillingStorage.getSubAccountByID(req.tenant, filteredRequest.accountData.accountID);
+ UtilsService.assertObjectExists(action, billingSubAccount, `Billing Sub-Account ID '${filteredRequest.accountData.accountID}' does not exist`, MODULE_NAME, 'handleUpdateCompany', req.user);
+ company.accountData = { accountID: billingSubAccount.id };
}
// Update Company
await CompanyStorage.saveCompany(req.tenant, company, Utils.objectHasProperty(filteredRequest, 'logo') ? true : false);

MODIFY
src/server/rest/v1/service/SiteService.ts
src/server/rest/v1/service/SiteService.ts
@@ -307,12 +307,12 @@ export default class SiteService {
createdOn: new Date()
} as Site;
// If the site is assigned to a billing sub-account, check if the billing is active
- if (filteredRequest.billingData) {
+ if (filteredRequest.accountData) {
UtilsService.assertComponentIsActiveFromToken(req.user, TenantComponents.BILLING_PLATFORM,
Action.CREATE, Entity.SITE, MODULE_NAME, 'handleCreateSite');
- const billingSubAccount = await BillingStorage.getSubAccountByID(req.tenant, filteredRequest.billingData.accountID);
- UtilsService.assertObjectExists(action, billingSubAccount, `Billing Sub-Account ID '${filteredRequest.billingData.accountID}' does not exist`, MODULE_NAME, 'handleCreateSite', req.user);
- site.billingData = { accountID: billingSubAccount.id };
+ const billingSubAccount = await BillingStorage.getSubAccountByID(req.tenant, filteredRequest.accountData.accountID);
+ UtilsService.assertObjectExists(action, billingSubAccount, `Billing Sub-Account ID '${filteredRequest.accountData.accountID}' does not exist`, MODULE_NAME, 'handleCreateSite', req.user);
+ site.accountData = { accountID: billingSubAccount.id };
}
// Save
site.id = await SiteStorage.saveSite(req.tenant, site, Utils.objectHasProperty(filteredRequest, 'image'));
@@ -379,12 +379,12 @@ export default class SiteService {
site.lastChangedBy = { 'id': req.user.id };
site.lastChangedOn = new Date();
// If the site is assigned to a billing sub-account, check if the billing is active
- if (filteredRequest.billingData) {
+ if (filteredRequest.accountData) {
UtilsService.assertComponentIsActiveFromToken(req.user, TenantComponents.BILLING_PLATFORM,
Action.CREATE, Entity.SITE, MODULE_NAME, 'handleUpdateSite');
- const billingSubAccount = await BillingStorage.getSubAccountByID(req.tenant, filteredRequest.billingData.accountID);
- UtilsService.assertObjectExists(action, billingSubAccount, `Billing Sub-Account ID '${filteredRequest.billingData.accountID}' does not exist`, MODULE_NAME, 'handleUpdateSite', req.user);
- site.billingData = { accountID: billingSubAccount.id };
+ const billingSubAccount = await BillingStorage.getSubAccountByID(req.tenant, filteredRequest.accountData.accountID);
+ UtilsService.assertObjectExists(action, billingSubAccount, `Billing Sub-Account ID '${filteredRequest.accountData.accountID}' does not exist`, MODULE_NAME, 'handleUpdateSite', req.user);
+ site.accountData = { accountID: billingSubAccount.id };
}
// Save
await SiteStorage.saveSite(req.tenant, site, Utils.objectHasProperty(filteredRequest, 'image'));

MODIFY
src/storage/mongodb/BillingStorage.ts
src/storage/mongodb/BillingStorage.ts
@@ -494,20 +494,4 @@ export default class BillingStorage {
}, Constants.DB_PARAMS_SINGLE_RECORD, projectFields);
return transferMDB.count === 1 ? transferMDB.result[0] : null;
}
-
- public static async updateTransferAdditionalData(tenant: Tenant, transfer: BillingTransfer, additionalData: BillingTransferSession[]): Promise<void> {
- const startTime = Logging.traceDatabaseRequestStart();
- DatabaseUtils.checkTenantObject(tenant);
- // Preserve the previous list of sessions
- const sessions: BillingTransferSession[] = transfer.sessions || [];
- sessions.push(...additionalData);
- // Set data
- const updatedTransferMDB: any = {
- sessions,
- };
- await global.database.getCollection(tenant.id, 'billingtransfers').findOneAndUpdate(
- { '_id': DatabaseUtils.convertToObjectID(transfer.id) },
- { $set: updatedTransferMDB });
- await Logging.traceDatabaseRequestEnd(tenant, MODULE_NAME, 'updateTransferAdditionalData', startTime, updatedTransferMDB);
- }
}

MODIFY
src/storage/mongodb/CompanyStorage.ts
src/storage/mongodb/CompanyStorage.ts
@@ -61,9 +61,9 @@ export default class CompanyStorage {
(coordinate) => Utils.convertToFloat(coordinate)) : [],
};
}
- if (companyToSave.billingData) {
- companyMDB.billingData = {
- accountID: DatabaseUtils.convertToObjectID(companyToSave.billingData.accountID),
+ if (companyToSave.accountData) {
+ companyMDB.accountData = {
+ accountID: DatabaseUtils.convertToObjectID(companyToSave.accountData.accountID),
};
}
// Add Last Changed/Created props

MODIFY
src/storage/mongodb/SiteStorage.ts
src/storage/mongodb/SiteStorage.ts
@@ -271,9 +271,9 @@ export default class SiteStorage {
(coordinate) => Utils.convertToFloat(coordinate)) : [],
};
}
- if (siteToSave.billingData) {
- siteMDB.billingData = {
- accountID: DatabaseUtils.convertToObjectID(siteToSave.billingData.accountID)
+ if (siteToSave.accountData) {
+ siteMDB.accountData = {
+ accountID: DatabaseUtils.convertToObjectID(siteToSave.accountData.accountID)
};
}
// Add Last Changed/Created props

MODIFY
src/types/Company.ts
src/types/Company.ts
@@ -14,5 +14,5 @@ export default interface Company extends CreatedUpdatedProps, AuthorizationActio
sites?: Site[];
distanceMeters?: number;
openingTimes?: OpeningTimes;
- billingData?: BillingAccountData;
+ accountData?: BillingAccountData;
}

MODIFY
src/types/Site.ts
src/types/Site.ts
@@ -23,7 +23,7 @@ export default interface Site extends CreatedUpdatedProps, SiteAuthorizationActi
public?: boolean;
openingTimes?: OpeningTimes;
tariffID?: string;
- billingData?: BillingAccountData;
+ accountData?: BillingAccountData;
}
export interface SiteUser {

MODIFY
test/api/BillingTest.ts
test/api/BillingTest.ts
@@ -1037,13 +1037,13 @@ describeif(isBillingProperlyConfigured)('Billing', () => {
let companyResponse = await billingTestHelper.userService.companyApi.create({
...CompanyFactory.build(),
- billingData: {
+ accountData: {
accountID: subAccountResponse.data.id
}
});
expect(companyResponse.status).to.be.eq(StatusCodes.OK);
companyResponse = await billingTestHelper.userService.companyApi.readById(companyResponse.data.id);
- expect(companyResponse.data.billingData.accountID).to.eq(subAccountResponse.data.id);
+ expect(companyResponse.data.accountData.accountID).to.eq(subAccountResponse.data.id);
});
it('should update a company to assign a sub-account', async () => {
@@ -1058,12 +1058,12 @@ describeif(isBillingProperlyConfigured)('Billing', () => {
companyResponse = await billingTestHelper.userService.companyApi.update({
id: companyID,
...CompanyFactory.build(),
- billingData: { accountID: subAccountResponse.data.id }
+ accountData: { accountID: subAccountResponse.data.id }
});
expect(companyResponse.status).to.be.eq(StatusCodes.OK);
companyResponse = await billingTestHelper.userService.companyApi.readById(companyID);
- expect(companyResponse.data.billingData.accountID).to.eq(subAccountResponse.data.id);
+ expect(companyResponse.data.accountData.accountID).to.eq(subAccountResponse.data.id);
});
it('should create a site assigned to a sub-account', async () => {
@@ -1079,13 +1079,13 @@ describeif(isBillingProperlyConfigured)('Billing', () => {
let siteResponse = await billingTestHelper.userService.siteApi.create({
...SiteFactory.build(),
companyID: companyResponse.data.id,
- billingData: {
+ accountData: {
accountID: subAccountResponse.data.id
}
});
expect(siteResponse.status).to.be.eq(StatusCodes.OK);
siteResponse = await billingTestHelper.userService.siteApi.readById(siteResponse.data.id);
- expect(siteResponse.data.billingData.accountID).to.eq(subAccountResponse.data.id);
+ expect(siteResponse.data.accountData.accountID).to.eq(subAccountResponse.data.id);
});
it('should update a site to assign a sub-account', async () => {
@@ -1109,12 +1109,12 @@ describeif(isBillingProperlyConfigured)('Billing', () => {
id: siteID,
...SiteFactory.build(),
companyID: companyResponse.data.id,
- billingData: { accountID: subAccountResponse.data.id }
+ accountData: { accountID: subAccountResponse.data.id }
});
expect(siteResponse.status).to.be.eq(StatusCodes.OK);
siteResponse = await billingTestHelper.userService.siteApi.readById(siteID);
- expect(siteResponse.data.billingData.accountID).to.eq(subAccountResponse.data.id);
+ expect(siteResponse.data.accountData.accountID).to.eq(subAccountResponse.data.id);
});
it('should list sub-accounts', async () => {
@@ -1271,21 +1271,6 @@ describeif(isBillingProperlyConfigured)('Billing', () => {
const retrievedTransfers = await BillingStorage.getTransfers(billingTestHelper.tenantContext.getTenant(), {}, Constants.DB_PARAMS_MAX_LIMIT);
expect(retrievedTransfers.result.map((transfer) => transfer.id)).to.include.members(ids);
});
-
- it('should update a draft billing transfer', async () => {
- let transfer: BillingTransfer = BillingTransferFactory.build();
- const transferID = await BillingStorage.saveTransfer(billingTestHelper.tenantContext.getTenant(), transfer);
- expect(transferID).to.not.be.null;
- transfer.id = transferID;
-
- const nbSessions = transfer.sessions.length;
- const sessions = [BillingTransferSessionFactory.build(), BillingTransferSessionFactory.build()];
- await BillingStorage.updateTransferAdditionalData(billingTestHelper.tenantContext.getTenant(), transfer, sessions);
-
- transfer = await BillingStorage.getTransferByID(billingTestHelper.tenantContext.getTenant(), transfer.id);
- expect(transfer.sessions.length).to.be.eq(nbSessions + 2);
- expect(transfer.sessions).to.include.deep.members(sessions);
- });
});
});

MODIFY
test/factories/BillingFactory.ts
test/factories/BillingFactory.ts
-import { BillingTransferStatus } from '../../src/types/Billing';
+import { BillingTransfer, BillingTransferSession, BillingTransferStatus } from '../../src/types/Billing';
+
import { Factory } from 'rosie';
import faker from 'faker';
-export const BillingTransferFactory = Factory.define('billingtransfer')
+export const BillingTransferFactory = Factory.define<BillingTransfer>('billingtransfer')
.attr('amount', () => faker.datatype.number())
.attr('accountID', () => faker.datatype.hexaDecimal(24).substring(2).toLowerCase())
.attr('status', () => faker.random.arrayElement([BillingTransferStatus.DRAFT, BillingTransferStatus.PENDING, BillingTransferStatus.TRANSFERRED]))
@@ -17,7 +18,7 @@ export const BillingTransferFactory = Factory.define('billingtransfer')
.attr('sessions', () =>
[BillingTransferSessionFactory.build()]);
-export const BillingTransferSessionFactory = Factory.define('billingtransfersession')
+export const BillingTransferSessionFactory = Factory.define<BillingTransferSession>('billingtransfersession')
.attr('transactionID', () => faker.datatype.number())
.attr('amount', () => faker.datatype.number())
.attr('platformFee', () => ({

refactor(billing): various renaming