Clear the tariff ID when the Site is not public
MODIFY
src/server/rest/v1/service/SiteAreaService.ts
src/server/rest/v1/service/SiteAreaService.ts
@@ -279,25 +279,30 @@ export default class SiteAreaService {
});
}
// Check Site auth
- await UtilsService.checkAndGetSiteAuthorization(
+ const site = await UtilsService.checkAndGetSiteAuthorization(
req.tenant, req.user, filteredRequest.siteID, Action.UPDATE, action);
// Create Site Area
- const newSiteArea: SiteArea = {
+ const siteArea: SiteArea = {
...filteredRequest,
issuer: true,
createdBy: { id: req.user.id },
createdOn: new Date()
} as SiteArea;
+ if (Utils.isComponentActiveFromToken(req.user, TenantComponents.OCPI)) {
+ if (!site.public) {
+ delete siteArea.tariffID;
+ }
+ }
// Save
- newSiteArea.id = await SiteAreaStorage.saveSiteArea(req.tenant, newSiteArea, true);
+ siteArea.id = await SiteAreaStorage.saveSiteArea(req.tenant, siteArea, true);
await Logging.logInfo({
tenantID: req.user.tenantID,
user: req.user, module: MODULE_NAME, method: 'handleCreateSiteArea',
- message: `Site Area '${newSiteArea.name}' has been created successfully`,
+ message: `Site Area '${siteArea.name}' has been created successfully`,
action: action,
- detailedMessages: { siteArea: newSiteArea }
+ detailedMessages: { siteArea: siteArea }
});
- res.json(Object.assign({ id: newSiteArea.id }, Constants.REST_RESPONSE_SUCCESS));
+ res.json(Object.assign({ id: siteArea.id }, Constants.REST_RESPONSE_SUCCESS));
next();
}
@@ -313,9 +318,10 @@ export default class SiteAreaService {
const siteArea = await UtilsService.checkAndGetSiteAreaAuthorization(
req.tenant, req.user, filteredRequest.id, Action.UPDATE, action, filteredRequest, {
withChargingStations: true,
+ withSite: true,
}, false);
// Check Site auth
- await UtilsService.checkAndGetSiteAuthorization(
+ const site = await UtilsService.checkAndGetSiteAuthorization(
req.tenant, req.user, filteredRequest.siteID, Action.READ, action);
// Update
siteArea.name = filteredRequest.name;
@@ -346,6 +352,9 @@ export default class SiteAreaService {
if (Utils.objectHasProperty(filteredRequest, 'tariffID')) {
siteArea.tariffID = filteredRequest.tariffID;
}
+ if (!site.public) {
+ delete siteArea.tariffID;
+ }
}
let actionsResponse: ActionsResponse;
if (siteArea.smartCharging && !filteredRequest.smartCharging) {

MODIFY
src/server/rest/v1/service/SiteService.ts
src/server/rest/v1/service/SiteService.ts
@@ -366,6 +366,11 @@ export default class SiteService {
createdBy: { id: req.user.id },
createdOn: new Date()
} as Site;
+ if (Utils.isComponentActiveFromToken(req.user, TenantComponents.OCPI)) {
+ if (!filteredRequest.public) {
+ delete site.tariffID;
+ }
+ }
// Save
site.id = await SiteStorage.saveSite(req.tenant, site);
await Logging.logInfo({
@@ -398,6 +403,7 @@ export default class SiteService {
site.companyID = filteredRequest.companyID;
if (Utils.objectHasProperty(filteredRequest, 'public')) {
if (!filteredRequest.public) {
+ // Check that there is no public charging stations
const publicChargingStations = await ChargingStationStorage.getChargingStations(req.tenant, {
siteIDs: [site.id],
public: true,
@@ -417,6 +423,9 @@ export default class SiteService {
if (Utils.objectHasProperty(filteredRequest, 'tariffID')) {
site.tariffID = filteredRequest.tariffID;
}
+ if (!filteredRequest.public) {
+ delete site.tariffID;
+ }
}
if (Utils.objectHasProperty(filteredRequest, 'autoUserSiteAssignment')) {
site.autoUserSiteAssignment = filteredRequest.autoUserSiteAssignment;

Clear the tariff ID when the Site is not public