Typed OCPI method
MODIFY
src/server/rest/v1/service/TenantService.ts
src/server/rest/v1/service/TenantService.ts
@@ -2,7 +2,7 @@ import { Action, Entity } from '../../../../types/Authorization';
import { CryptoSettings, CryptoSettingsType, SettingDB, SettingDBContent, TechnicalSettings, UserSettings, UserSettingsType } from '../../../../types/Setting';
import { HTTPAuthError, HTTPError } from '../../../../types/HTTPError';
import { NextFunction, Request, Response } from 'express';
-import Tenant, { TenantLogo } from '../../../../types/Tenant';
+import Tenant, { TenantComponents , TenantLogo } from '../../../../types/Tenant';
import User, { UserRole } from '../../../../types/User';
import AppAuthError from '../../../../exception/AppAuthError';
@@ -21,7 +21,7 @@ import { ServerAction } from '../../../../types/Server';
import SettingStorage from '../../../../storage/mongodb/SettingStorage';
import SiteAreaStorage from '../../../../storage/mongodb/SiteAreaStorage';
import { StatusCodes } from 'http-status-codes';
-import { TenantComponents } from '../../../../types/Tenant';
+
import TenantStorage from '../../../../storage/mongodb/TenantStorage';
import TenantValidator from '../validator/TenantValidator';
import UserStorage from '../../../../storage/mongodb/UserStorage';
@@ -419,12 +419,7 @@ export default class TenantService {
}
// Create
const newSettingContent = Utils.createDefaultSettingContent(
- {
- ...tenant.components[componentName],
- name: componentName
- },
- currentSetting ? currentSetting.content : null
- );
+ componentName, tenant.components[componentName], currentSetting?.content);
if (newSettingContent) {
// Create & Save
if (!currentSetting) {

MODIFY
src/utils/Utils.ts
src/utils/Utils.ts
@@ -20,8 +20,8 @@ import QRCode from 'qrcode';
import { Request } from 'express';
import { ServerAction } from '../types/Server';
import Tag from '../types/Tag';
-import Tenant from '../types/Tenant';
-import { TenantComponents } from '../types/Tenant';
+import Tenant, { TenantComponentContent , TenantComponents } from '../types/Tenant';
+
import UserToken from '../types/UserToken';
import { WebSocketCloseEventStatusString } from '../types/WebSocket';
import _ from 'lodash';
@@ -1255,19 +1255,19 @@ export default class Utils {
return await QRCode.toDataURL(data);
}
- public static createDefaultSettingContent(activeComponent: any, currentSettingContent: SettingDBContent): SettingDBContent {
- switch (activeComponent.name) {
+ public static createDefaultSettingContent(componentName: string, activeComponentContent: TenantComponentContent, currentSettingContent: SettingDBContent): SettingDBContent {
+ switch (componentName) {
// Pricing
case TenantComponents.PRICING:
- if (!currentSettingContent || currentSettingContent.type !== activeComponent.type) {
+ if (!currentSettingContent || currentSettingContent.type !== activeComponentContent.type) {
// Create default settings
- if (activeComponent.type === PricingSettingsType.SIMPLE) {
+ if (activeComponentContent.type === PricingSettingsType.SIMPLE) {
// Simple Pricing
return {
'type': PricingSettingsType.SIMPLE,
'simple': {}
} as SettingDBContent;
- } else if (activeComponent.type === PricingSettingsType.CONVERGENT_CHARGING) {
+ } else if (activeComponentContent.type === PricingSettingsType.CONVERGENT_CHARGING) {
// SAP CC
return {
'type': PricingSettingsType.CONVERGENT_CHARGING,
@@ -1278,7 +1278,7 @@ export default class Utils {
break;
// Billing
case TenantComponents.BILLING:
- if (!currentSettingContent || currentSettingContent.type !== activeComponent.type) {
+ if (!currentSettingContent || currentSettingContent.type !== activeComponentContent.type) {
// Only Stripe
return {
'type': BillingSettingsType.STRIPE,
@@ -1288,7 +1288,7 @@ export default class Utils {
break;
// Refund
case TenantComponents.REFUND:
- if (!currentSettingContent || currentSettingContent.type !== activeComponent.type) {
+ if (!currentSettingContent || currentSettingContent.type !== activeComponentContent.type) {
// Only Concur
return {
'type': RefundSettingsType.CONCUR,
@@ -1318,7 +1318,7 @@ export default class Utils {
break;
// SAC
case TenantComponents.ANALYTICS:
- if (!currentSettingContent || currentSettingContent.type !== activeComponent.type) {
+ if (!currentSettingContent || currentSettingContent.type !== activeComponentContent.type) {
// Only SAP Analytics
return {
'type': AnalyticsSettingsType.SAC,
@@ -1328,7 +1328,7 @@ export default class Utils {
break;
// Smart Charging
case TenantComponents.SMART_CHARGING:
- if (!currentSettingContent || currentSettingContent.type !== activeComponent.type) {
+ if (!currentSettingContent || currentSettingContent.type !== activeComponentContent.type) {
// Only SAP sapSmartCharging
return {
'type': SmartChargingContentType.SAP_SMART_CHARGING,

Typed OCPI method