Basic pricing definition check
MODIFY
src/server/rest/v1/service/PricingService.ts
src/server/rest/v1/service/PricingService.ts
@@ -108,6 +108,8 @@ export default class PricingService {
Action.CREATE, Entity.PRICING_DEFINITION, MODULE_NAME, 'handleCreatePricingDefinition');
// Filter
const filteredRequest = PricingValidatorRest.getInstance().validatePricingDefinitionCreate(req.body);
+ // Check Pricing Definition
+ UtilsService.checkIfPricingDefinitionValid(filteredRequest, req);
// Get dynamic auth
await AuthorizationService.checkAndGetPricingDefinitionAuthorizations(
req.tenant, req.user, {}, Action.CREATE, filteredRequest);
@@ -145,6 +147,8 @@ export default class PricingService {
Action.UPDATE, Entity.PRICING_DEFINITION, MODULE_NAME, 'handleUpdatePricingDefinition');
// Filter
const filteredRequest = PricingValidatorRest.getInstance().validatePricingDefinitionUpdate(req.body);
+ // Check Pricing Definition
+ UtilsService.checkIfPricingDefinitionValid(filteredRequest, req);
// Check and Get Pricing
let pricingDefinition = await UtilsService.checkAndGetPricingDefinitionAuthorization(
req.tenant, req.user, filteredRequest.id, Action.UPDATE, action, filteredRequest);

MODIFY
src/server/rest/v1/service/UtilsService.ts
src/server/rest/v1/service/UtilsService.ts
@@ -1341,6 +1341,18 @@ export default class UtilsService {
}
}
+ public static checkIfPricingDefinitionValid(pricingDefinition: Partial<PricingDefinition>, req: Request): void {
+ if (pricingDefinition.staticRestrictions?.validFrom && pricingDefinition.staticRestrictions?.validTo &&
+ pricingDefinition.staticRestrictions.validFrom.getTime() > pricingDefinition.staticRestrictions.validTo.getTime()) {
+ throw new AppError({
+ errorCode: HTTPError.GENERAL_ERROR,
+ message: 'The pricing definition validity start date cannot be after the end date',
+ module: MODULE_NAME, method: 'checkIfPricingDefinitionValid',
+ user: req.user.id
+ });
+ }
+ }
+
public static checkIfTenantValid(tenant: Partial<Tenant>, req: Request): void {
if (tenant.components.oicp?.active && tenant.components.ocpi?.active) {
throw new AppError({

Basic pricing definition check