pricing - fix objectId convertion when filtering
MODIFY
src/integration/pricing/PricingEngine.ts
src/integration/pricing/PricingEngine.ts
@@ -67,7 +67,7 @@ export default class PricingEngine {
}
private static async getPricingDefinitions4Entity(tenant: Tenant, transaction: Transaction, chargingStation: ChargingStation, entityType: PricingEntity, entityID: string): Promise<ResolvedPricingDefinition[]> {
- let pricingDefinitions = await PricingEngine.fetchPricingDefinitions4Entity(tenant, entityID);
+ let pricingDefinitions = await PricingEngine.fetchPricingDefinitions4Entity(tenant, entityType, entityID);
pricingDefinitions = pricingDefinitions || [];
const actualPricingDefinitions = pricingDefinitions.filter((pricingDefinition) =>
PricingEngine.checkEntityType(pricingDefinition, entityType)
@@ -87,9 +87,9 @@ export default class PricingEngine {
return actualPricingDefinitions || [];
}
- private static async fetchPricingDefinitions4Entity(tenant: Tenant, entityID: string): Promise<PricingDefinition[]> {
+ private static async fetchPricingDefinitions4Entity(tenant: Tenant, entityType: PricingEntity, entityID: string): Promise<PricingDefinition[]> {
if (entityID) {
- const pricingModelResults = await PricingStorage.getPricingDefinitions(tenant, { entityID }, {
+ const pricingModelResults = await PricingStorage.getPricingDefinitions(tenant, { entityType, entityID }, {
limit: Constants.DB_RECORD_COUNT_NO_LIMIT, skip: 0, sort: { createdOn: -1 }
});
if (pricingModelResults.count > 0) {

MODIFY
src/server/rest/v1/service/PricingService.ts
src/server/rest/v1/service/PricingService.ts
@@ -48,8 +48,8 @@ export default class PricingService {
// Get the pricing definitions
const pricingDefinitions = await PricingStorage.getPricingDefinitions(req.tenant,
{
- entityID: filteredRequest.entityID ? filteredRequest.entityID : null,
- entityType: filteredRequest.entityType ? filteredRequest.entityType : null,
+ entityID: filteredRequest.entityID || null,
+ entityType: filteredRequest.entityType || null,
withEntityInformation: filteredRequest?.WithEntityInformation,
...authorizationPricingDefinitionsFilter.filters
}, {

MODIFY
src/storage/mongodb/PricingStorage.ts
src/storage/mongodb/PricingStorage.ts
@@ -75,7 +75,7 @@ export default class PricingStorage {
}
public static async getPricingDefinitions(tenant: Tenant,
- params: { pricingDefinitionIDs?: string[], entityID?: string; entityType?: string; withEntityInformation?: boolean; },
+ params: { pricingDefinitionIDs?: string[], entityType?: string; entityID?: string; withEntityInformation?: boolean; },
dbParams: DbParams, projectFields?: string[]): Promise<DataResult<PricingDefinition>> {
const uniqueTimerID = Logging.traceDatabaseRequestStart();
// Check Tenant
@@ -97,10 +97,10 @@ export default class PricingStorage {
}
// Context IDs
if (!Utils.isNullOrEmptyString(params.entityID)) {
- if (params.entityType !== PricingEntity.CHARGING_STATION) {
- filters.entityID = { $in: [DatabaseUtils.convertToObjectID(params.entityID)] };
- } else {
+ if (params.entityType === PricingEntity.CHARGING_STATION) {
filters.entityID = { $in: [params.entityID] };
+ } else {
+ filters.entityID = { $in: [DatabaseUtils.convertToObjectID(params.entityID)] };
}
}
// Remove deleted

pricing - fix objectId convertion when filtering