Return the charging profile id when created
MODIFY
src/server/ocpp/utils/OCPPUtils.ts
src/server/ocpp/utils/OCPPUtils.ts
@@ -386,7 +386,7 @@ export default class OCPPUtils {
});
}
- public static async setAndSaveChargingProfile(tenantID: string, chargingProfile: ChargingProfile, user?: UserToken) {
+ public static async setAndSaveChargingProfile(tenantID: string, chargingProfile: ChargingProfile, user?: UserToken): Promise<string> {
// Get charging station
const chargingStation = await ChargingStationStorage.getChargingStation(tenantID, chargingProfile.chargingStationID);
if (!chargingStation) {
@@ -434,7 +434,7 @@ export default class OCPPUtils {
});
}
// Save
- await ChargingStationStorage.saveChargingProfile(tenantID, chargingProfile);
+ const chargingProfileID = await ChargingStationStorage.saveChargingProfile(tenantID, chargingProfile);
Logging.logInfo({
tenantID: tenantID,
source: chargingStation.id,
@@ -443,6 +443,7 @@ export default class OCPPUtils {
message: 'Charging Profile has been successfully pushed and saved',
detailedMessages: { chargingProfile }
});
+ return chargingProfileID;
}
static isSocMeterValue(meterValue: OCPPNormalizedMeterValue) {

MODIFY
src/server/rest/service/ChargingStationService.ts
src/server/rest/service/ChargingStationService.ts
-import fs from 'fs';
-
+import { Action, Entity } from '../../../types/Authorization';
+import ChargingStation, { Command, OCPPParams, StaticLimitAmps } from '../../../types/ChargingStation';
+import { HTTPAuthError, HTTPError } from '../../../types/HTTPError';
+import { HttpChargingStationCommandRequest, HttpIsAuthorizedRequest } from '../../../types/requests/HttpChargingStationRequest';
import { NextFunction, Request, Response } from 'express';
-import sanitize from 'mongo-sanitize';
+import { OCPPConfigurationStatus, OCPPGetCompositeScheduleCommandResult, OCPPStatus } from '../../../types/ocpp/OCPPClient';
-import Authorizations from '../../../authorization/Authorizations';
-import ChargingStationClientFactory from '../../../client/ocpp/ChargingStationClientFactory';
import AppAuthError from '../../../exception/AppAuthError';
import AppError from '../../../exception/AppError';
+import Authorizations from '../../../authorization/Authorizations';
import BackendError from '../../../exception/BackendError';
+import { ChargingProfile } from '../../../types/ChargingProfile';
+import ChargingStationClientFactory from '../../../client/ocpp/ChargingStationClientFactory';
+import { ChargingStationInErrorType } from '../../../types/InError';
+import ChargingStationSecurity from './security/ChargingStationSecurity';
+import ChargingStationStorage from '../../../storage/mongodb/ChargingStationStorage';
import ChargingStationVendorFactory from '../../../integration/charging-station-vendor/ChargingStationVendorFactory';
-import SmartChargingFactory from '../../../integration/smart-charging/SmartChargingFactory';
+import Constants from '../../../utils/Constants';
+import { DataResult } from '../../../types/DataResult';
+import I18nManager from '../../../utils/I18nManager';
import LockingHelper from '../../../locking/LockingHelper';
import LockingManager from '../../../locking/LockingManager';
-import ChargingStationStorage from '../../../storage/mongodb/ChargingStationStorage';
+import Logging from '../../../utils/Logging';
import OCPPStorage from '../../../storage/mongodb/OCPPStorage';
-import SiteAreaStorage from '../../../storage/mongodb/SiteAreaStorage';
-import SiteStorage from '../../../storage/mongodb/SiteStorage';
-import TransactionStorage from '../../../storage/mongodb/TransactionStorage';
-import { Action, Entity } from '../../../types/Authorization';
-import { ChargingProfile } from '../../../types/ChargingProfile';
-import ChargingStation, { Command, OCPPParams, StaticLimitAmps } from '../../../types/ChargingStation';
-import { DataResult } from '../../../types/DataResult';
-import { HTTPAuthError, HTTPError } from '../../../types/HTTPError';
-import { ChargingStationInErrorType } from '../../../types/InError';
-import { OCPPConfigurationStatus, OCPPGetCompositeScheduleCommandResult, OCPPStatus } from '../../../types/ocpp/OCPPClient';
-import { HttpChargingStationCommandRequest, HttpIsAuthorizedRequest } from '../../../types/requests/HttpChargingStationRequest';
+import OCPPUtils from '../../ocpp/utils/OCPPUtils';
import { ServerAction } from '../../../types/Server';
import SiteArea from '../../../types/SiteArea';
+import SiteAreaStorage from '../../../storage/mongodb/SiteAreaStorage';
+import SiteStorage from '../../../storage/mongodb/SiteStorage';
+import SmartChargingFactory from '../../../integration/smart-charging/SmartChargingFactory';
import TenantComponents from '../../../types/TenantComponents';
+import TransactionStorage from '../../../storage/mongodb/TransactionStorage';
import UserToken from '../../../types/UserToken';
-import Constants from '../../../utils/Constants';
-import I18nManager from '../../../utils/I18nManager';
-import Logging from '../../../utils/Logging';
import Utils from '../../../utils/Utils';
-import OCPPUtils from '../../ocpp/utils/OCPPUtils';
-import ChargingStationSecurity from './security/ChargingStationSecurity';
import UtilsService from './UtilsService';
+import fs from 'fs';
+import sanitize from 'mongo-sanitize';
const MODULE_NAME = 'ChargingStationService';
@@ -504,9 +503,9 @@ export default class ChargingStationService {
});
}
// Apply & Save charging plan
- await OCPPUtils.setAndSaveChargingProfile(req.user.tenantID, filteredRequest, req.user);
+ const chargingProfileID = await OCPPUtils.setAndSaveChargingProfile(req.user.tenantID, filteredRequest, req.user);
// Ok
- res.json(Constants.REST_RESPONSE_SUCCESS);
+ res.json(Object.assign({ id: chargingProfileID }, Constants.REST_RESPONSE_SUCCESS));
next();
}

Return the charging profile id when created