pricing  - withEntityInformation
MODIFY
src/authorization/AuthorizationsDefinition.ts
src/authorization/AuthorizationsDefinition.ts
@@ -214,9 +214,18 @@ export const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
{ resource: Entity.LOGGINGS, action: Action.LIST },
{ resource: Entity.LOGGING, action: Action.READ },
{ resource: Entity.PRICING, action: [Action.READ, Action.UPDATE] },
- { resource: Entity.PRICING_DEFINITIONS, action: [Action.LIST] },
+ { resource: Entity.PRICING_DEFINITIONS, action: [Action.LIST],
+ attributes: ['id', 'entityID', 'entityType', 'name', 'description', 'entityName',
+ 'staticRestrictions.validFrom', 'staticRestrictions.validTo', 'staticRestrictions.connectorType', 'staticRestrictions.connectorPowerkW',
+ 'restrictions.minEnergyKWh', 'restrictions.maxEnergyKWh', 'restrictions.minDurationSecs', 'restrictions.maxDurationSecs',
+ 'dimensions.flatFee.active', 'dimensions.flatFee.price', 'dimensions.flatFee.stepSize', 'dimensions.flatFee.pricedData',
+ 'dimensions.energy.active', 'dimensions.energy.price', 'dimensions.energy.stepSize', 'dimensions.energy.pricedData',
+ 'dimensions.chargingTime.active', 'dimensions.chargingTime.price', 'dimensions.chargingTime.stepSize', 'dimensions.chargingTime.pricedData',
+ 'dimensions.parkingTime.active', 'dimensions.parkingTime.price', 'dimensions.parkingTime.stepSize', 'dimensions.parkingTime.pricedData',
+ ]
+ },
{ resource: Entity.PRICING_DEFINITION, action: [Action.CREATE, Action.READ, Action.UPDATE, Action.DELETE],
- attributes: ['id', 'entityID', 'entityType', 'name', 'description',
+ attributes: ['id', 'entityID', 'entityType', 'name', 'description', 'entityName',
'staticRestrictions.validFrom', 'staticRestrictions.validTo', 'staticRestrictions.connectorType', 'staticRestrictions.connectorPowerkW',
'restrictions.minEnergyKWh', 'restrictions.maxEnergyKWh', 'restrictions.minDurationSecs', 'restrictions.maxDurationSecs',
'dimensions.flatFee.active', 'dimensions.flatFee.price', 'dimensions.flatFee.stepSize', 'dimensions.flatFee.pricedData',

MODIFY
src/server/rest/v1/service/PricingService.ts
src/server/rest/v1/service/PricingService.ts
@@ -46,9 +46,11 @@ export default class PricingService {
return;
}
// Get the pricing definitions
- const pricingDefinitions = await PricingStorage.getPricingDefinitions(req.tenant, {
+ const pricingDefinitions = await PricingStorage.getPricingDefinitions(req.tenant,
+ {
entityIDs: filteredRequest.entityID ? filteredRequest.entityID.split('|') : null,
entityTypes: filteredRequest.entityType ? filteredRequest.entityType.split('|') : null,
+ withEntityInformation: filteredRequest?.WithEntityInformation,
...authorizationPricingDefinitionsFilter.filters
}, {
limit: filteredRequest.Limit,
@@ -58,6 +60,10 @@ export default class PricingService {
},
authorizationPricingDefinitionsFilter.projectFields
);
+ // Assign projected fields
+ if (authorizationPricingDefinitionsFilter.projectFields) {
+ pricingDefinitions.projectFields = authorizationPricingDefinitionsFilter.projectFields;
+ }
// Add Auth flags
await AuthorizationService.addPricingDefinitionsAuthorizations(req.tenant, req.user, pricingDefinitions as PricingDataResult, authorizationPricingDefinitionsFilter);
// Return

MODIFY
src/server/rest/v1/service/UtilsService.ts
src/server/rest/v1/service/UtilsService.ts
@@ -108,7 +108,7 @@ export default class UtilsService {
}
public static async checkAndGetPricingDefinitionAuthorization(tenant: Tenant, userToken: UserToken, pricingDefinitionID: string, authAction: Action,
- action: ServerAction, entityData?: EntityDataType, additionalFilters: Record<string, any> = {}, applyProjectFields = false, checkIssuer = true): Promise<PricingDefinition> {
+ action: ServerAction, entityData?: EntityDataType, additionalFilters: Record<string, any> = {}, applyProjectFields = false): Promise<PricingDefinition> {
// Check mandatory fields
UtilsService.assertIdIsProvided(action, pricingDefinitionID, MODULE_NAME, 'checkAndGetPricingDefinitionAuthorization', userToken);
// Get dynamic auth
@@ -135,6 +135,14 @@ export default class UtilsService {
MODULE_NAME, 'checkAndGetPricingDefinitionAuthorization', userToken);
// Add actions
await AuthorizationService.addPricingDefinitionAuthorizations(tenant, userToken, pricingDefinition, authorizationFilter);
+ // Assign projected fields
+ if (authorizationFilter.projectFields) {
+ pricingDefinition.projectFields = authorizationFilter.projectFields;
+ }
+ // Assign Metadata
+ if (authorizationFilter.metadata) {
+ pricingDefinition.metadata = authorizationFilter.metadata;
+ }
// Check
const authorized = AuthorizationService.canPerformAction(pricingDefinition, authAction);
if (!authorized) {

MODIFY
src/storage/mongodb/PricingStorage.ts
src/storage/mongodb/PricingStorage.ts
@@ -165,6 +165,21 @@ export default class PricingStorage {
tenantID: tenant.id, aggregation, localField: 'entityID', foreignField: '_id',
asField: 'chargingStation', oneToOneCardinality, oneToOneCardinalityNotNull
});
+ // Check if it has detailed messages
+ aggregation.push({
+ $addFields: {
+ entityName: {
+ $switch: {
+ branches: [
+ { case: { $eq: [ 'Company', '$entityType' ] }, then: '$company.name' },
+ { case: { $eq: [ 'Site', '$entityType' ] }, then: '$company.name' },
+ { case: { $eq: [ 'SiteArea', '$entityType' ] }, then: '$siteArea.name' },
+ ],
+ default: '$entityID'
+ }
+ }
+ }
+ });
}
// Handle the ID
DatabaseUtils.pushRenameDatabaseID(aggregation);

pricing  - withEntityInformation