add CUSTOMS type to priority configs and update related logic

This commit is contained in:
Marshal
2026-07-07 16:42:57 +00:00
parent f300600bfa
commit b57840c907
26 changed files with 352 additions and 120 deletions

View File

@@ -176,13 +176,12 @@ export class RuleEngineService {
}
const serviceType = await this.serviceTypesRepo.findById(input.serviceTypeId);
if (serviceType) {
priorityScore += serviceType.priorityBonusPoints;
}
const includesCustoms = serviceType?.includesCustoms ?? false;
// Additive priority blocks, each keyed on the booking's total wagon count:
// - WAGON rules apply regardless of currency.
// - CURRENCY rules apply only when the payment currency matches.
// - CUSTOMS rules apply only when the service type includes customs.
const priorityConfigs = await this.priorityConfigsRepo.findAllActive();
const wagonsInRange = (cfg: { minWagonCount: number; maxWagonCount: number }) =>
input.totalWagons >= cfg.minWagonCount &&
@@ -191,7 +190,8 @@ export class RuleEngineService {
for (const cfg of priorityConfigs) {
const applies =
cfg.type === 'WAGON' ||
(cfg.type === 'CURRENCY' && cfg.currency === input.paymentCurrency);
(cfg.type === 'CURRENCY' && cfg.currency === input.paymentCurrency) ||
(cfg.type === 'CUSTOMS' && includesCustoms);
if (applies && wagonsInRange(cfg)) {
priorityScore += cfg.scorePoints;
}