billing - authorizations - hiding synchronize invoice feature
MODIFY
src/authorization/AuthorizationsDefinition.ts
src/authorization/AuthorizationsDefinition.ts
@@ -93,8 +93,13 @@ const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
{ resource: Entity.PRICING, action: [Action.READ, Action.UPDATE], attributes: ['*'] },
{ resource: Entity.BILLING, action: [Action.CHECK_CONNECTION] },
{ resource: Entity.TAXES, action: [Action.LIST], attributes: ['*'] },
- { resource: Entity.INVOICES, action: [Action.LIST, Action.SYNCHRONIZE], attributes: ['*'] },
- { resource: Entity.INVOICE, action: [Action.DOWNLOAD, Action.CREATE], attributes: ['*'] },
+ // -----------------------------------------------------------------------------------------------
+ // TODO - put it pack as soon as BILLING has been validated on SLF
+ // -----------------------------------------------------------------------------------------------
+ // { resource: Entity.INVOICES, action: [Action.LIST, Action.SYNCHRONIZE], attributes: ['*'] },
+ // { resource: Entity.INVOICE, action: [Action.DOWNLOAD, Action.CREATE], attributes: ['*'] },
+ { resource: Entity.INVOICES, action: [Action.LIST], attributes: ['*'] },
+ { resource: Entity.INVOICE, action: [Action.DOWNLOAD], attributes: ['*'] },
{
resource: Entity.ASSET, action: [Action.CREATE, Action.READ, Action.UPDATE, Action.DELETE,
Action.CHECK_CONNECTION, Action.RETRIEVE_CONSUMPTION], attributes: ['*']
@@ -178,7 +183,7 @@ const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
attributes: ['id', 'name', 'issuer', 'logo', 'address']
},
// -----------------------------------------------------------------------------------------------
- // TODO - put it pack as soon as BILLING has been validated of SLF
+ // TODO - put it pack as soon as BILLING has been validated on SLF
// -----------------------------------------------------------------------------------------------
// { resource: Entity.INVOICES, action: [Action.LIST, Action.SYNCHRONIZE], attributes: ['*'] },
// {

MODIFY
src/server/rest/v1/service/BillingService.ts
src/server/rest/v1/service/BillingService.ts
@@ -418,60 +418,65 @@ export default class BillingService {
next();
}
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/require-await
public static async handleCreateTransactionInvoice(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
- // Check if component is active
- UtilsService.assertComponentIsActiveFromToken(req.user, TenantComponents.BILLING,
- Action.CREATE, Entity.INVOICE, MODULE_NAME, 'handleCreateTransactionInvoice');
- // Check Auth
- if (!await Authorizations.canCreateTransactionInvoice(req.user)) {
- throw new AppAuthError({
- errorCode: HTTPAuthError.FORBIDDEN,
- user: req.user,
- entity: Entity.INVOICE, action: Action.CREATE,
- module: MODULE_NAME, method: 'handleCreateTransactionInvoice',
- });
- }
- const filteredRequest = BillingSecurity.filterLinkTransactionToInvoiceRequest(req.body);
- // Get Billing impl
- const billingImpl = await BillingFactory.getBillingImpl(req.user.tenantID);
- if (!billingImpl) {
- throw new AppError({
- source: Constants.CENTRAL_SERVER,
- errorCode: HTTPError.GENERAL_ERROR,
- message: 'Billing service is not configured',
- module: MODULE_NAME, method: 'handleCreateTransactionInvoice',
- action: action,
- user: req.user
- });
- }
- // Get the Transaction
- const transaction = await TransactionStorage.getTransaction(req.user.tenantID,
- Utils.convertToInt(filteredRequest.transactionID));
- UtilsService.assertObjectExists(action, transaction, `Transaction ID '${filteredRequest.transactionID}' does not exist`,
- MODULE_NAME, 'handleCreateTransactionInvoice', req.user);
+ // TODO - no use-case for this endpoint so far!
+ throw new Error('Method not implemented.');
+ // // Check if component is active
+ // UtilsService.assertComponentIsActiveFromToken(req.user, TenantComponents.BILLING,
+ // Action.CREATE, Entity.INVOICE, MODULE_NAME, 'handleCreateTransactionInvoice');
+ // // Check Auth
+ // if (!await Authorizations.canCreateTransactionInvoice(req.user)) {
+ // throw new AppAuthError({
+ // errorCode: HTTPAuthError.FORBIDDEN,
+ // user: req.user,
+ // entity: Entity.INVOICE, action: Action.CREATE,
+ // module: MODULE_NAME, method: 'handleCreateTransactionInvoice',
+ // });
+ // }
+ // const filteredRequest = BillingSecurity.filterLinkTransactionToInvoiceRequest(req.body);
+ // // Get Billing impl
+ // const billingImpl = await BillingFactory.getBillingImpl(req.user.tenantID);
+ // if (!billingImpl) {
+ // throw new AppError({
+ // source: Constants.CENTRAL_SERVER,
+ // errorCode: HTTPError.GENERAL_ERROR,
+ // message: 'Billing service is not configured',
+ // module: MODULE_NAME, method: 'handleCreateTransactionInvoice',
+ // action: action,
+ // user: req.user
+ // });
+ // }
+ // // Get the Transaction
+ // const transaction = await TransactionStorage.getTransaction(req.user.tenantID,
+ // Utils.convertToInt(filteredRequest.transactionID));
+ // UtilsService.assertObjectExists(action, transaction, `Transaction ID '${filteredRequest.transactionID}' does not exist`,
+ // MODULE_NAME, 'handleCreateTransactionInvoice', req.user);
// Create an invoice for the transaction
// ----------------------------------------------------------------------
// TODO - Rethink that part!
// Calling StopTransaction without calling startTransaction may have
// unpredictable side-effects.
// ----------------------------------------------------------------------
- const billingDataStop = await billingImpl.stopTransaction(transaction);
- // Update transaction billing data
- transaction.billingData.stop = billingDataStop;
- transaction.billingData.lastUpdate = new Date();
- // Save it
- await TransactionStorage.saveTransaction(req.user.tenantID, transaction);
- // Ok
- await Logging.logInfo({
- tenantID: req.user.tenantID,
- user: req.user, actionOnUser: transaction.userID,
- module: MODULE_NAME, method: 'handleCreateTransactionInvoice',
- message: `Transaction ID '${transaction.id}' has been billed successfully`,
- action: action,
- });
+ // const billingDataStop = await billingImpl.stopTransaction(transaction);
+ // // Update transaction billing data
+ // if (transaction.billingData) {
+ // transaction.billingData.stop = billingDataStop;
+ // transaction.billingData.lastUpdate = new Date();
+ // }
+ // // Save it
+ // await TransactionStorage.saveTransaction(req.user.tenantID, transaction);
+ // // Ok
+ // await Logging.logInfo({
+ // tenantID: req.user.tenantID,
+ // user: req.user, actionOnUser: transaction.userID,
+ // module: MODULE_NAME, method: 'handleCreateTransactionInvoice',
+ // message: `Transaction ID '${transaction.id}' has been billed successfully`,
+ // action: action,
+ // });
// Ok
- res.json(Object.assign(Constants.REST_RESPONSE_SUCCESS));
- next();
+ // res.json(Object.assign(Constants.REST_RESPONSE_SUCCESS));
+ // next();
}
public static async handleBillingSetupPaymentMethod(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {

billing - authorizations - hiding synchronize invoice feature