Enhance pricing validation and update related components
CI / Backend (build + test) (push) Successful in 1m21s
CI / Frontend (lint + typecheck + build) (push) Successful in 34s

- Added validation logic in `UpdatePricingSettingsCommandValidator` to ensure the annual price does not fall below the equivalent quarterly price, preventing potential pricing discrepancies.
- Updated `PricingSettings` model documentation to clarify that both pricing fields represent monthly rates, with calculations for total costs based on the number of months.
- Modified frontend components to reflect the new validation, including error messages when the annual price is cheaper than the quarterly price.
- Adjusted API documentation to accurately describe the pricing structure and validation rules for the pricing endpoints.
This commit is contained in:
Leonid Pershin
2026-07-18 19:56:21 +03:00
parent ae379f8e0f
commit 6dfd51ae7c
7 changed files with 70 additions and 22 deletions
@@ -13,5 +13,19 @@ public sealed class UpdatePricingSettingsCommandValidator
RuleFor(x => x.PricePerConfigPerYear!.Value)
.GreaterThanOrEqualTo(0)
.When(x => x.PricePerConfigPerYear.HasValue);
// Обе ставки — цена за конфиг В МЕСЯЦ при соответствующем тарифе оплаты; итог за период =
// ставка × число месяцев. Годовая ставка может быть ниже квартальной (скидка за годовую
// оплату), но итог за год (ставка×12) не должен быть дешевле итога за квартал (ставка×3) —
// иначе выгоднее купить "год" и не продлевать, чем платить за квартал.
RuleFor(x => x.PricePerConfigPerYear)
.Must(
(command, year) =>
!year.HasValue
|| !command.PricePerConfigPerQuarter.HasValue
|| (decimal)year.Value * 12 >= (decimal)command.PricePerConfigPerQuarter.Value * 3
)
.WithMessage("Цена за год (в пересчёте на 12 месяцев) не может быть меньше цены за 3 месяца.")
.When(x => x.PricePerConfigPerQuarter.HasValue && x.PricePerConfigPerYear.HasValue);
}
}