mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-24 00:28:44 +05:00
implemented *has operator and added Type field
This commit is contained in:
@@ -697,17 +697,24 @@ func (acc *Account) DebitConnectionFee(cc *CallCost, usefulMoneyBalances Balance
|
||||
}
|
||||
}
|
||||
|
||||
func (acc *Account) matchConditions(condition, balanceType string) (bool, error) {
|
||||
|
||||
func (acc *Account) matchConditions(condition string) (bool, error) {
|
||||
cl := &utils.CondLoader{}
|
||||
cl.Parse(condition)
|
||||
for _, b := range acc.BalanceMap[balanceType] {
|
||||
check, err := cl.Check(b)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if check {
|
||||
return true, nil
|
||||
for balanceType, balanceChain := range acc.BalanceMap {
|
||||
for _, b := range balanceChain {
|
||||
check, err := cl.Check(&struct {
|
||||
Type string
|
||||
*Balance
|
||||
}{
|
||||
Type: balanceType,
|
||||
Balance: b,
|
||||
})
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if check {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return false, nil
|
||||
|
||||
@@ -628,7 +628,7 @@ func transferMonetaryDefault(acc *Account, sq *StatsQueueTriggered, a *Action, a
|
||||
}
|
||||
|
||||
func conditionalDebitAction(acc *Account, sq *StatsQueueTriggered, a *Action, acs Actions) error {
|
||||
if matched, err := acc.matchConditions(a.ExtraParameters, a.BalanceType); matched {
|
||||
if matched, err := acc.matchConditions(a.ExtraParameters); matched {
|
||||
return debitAction(acc, sq, a, acs)
|
||||
} else {
|
||||
return err
|
||||
@@ -636,7 +636,7 @@ func conditionalDebitAction(acc *Account, sq *StatsQueueTriggered, a *Action, ac
|
||||
}
|
||||
|
||||
func conditionalDebitResetAction(acc *Account, sq *StatsQueueTriggered, a *Action, acs Actions) error {
|
||||
if matched, err := acc.matchConditions(a.ExtraParameters, a.BalanceType); matched {
|
||||
if matched, err := acc.matchConditions(a.ExtraParameters); matched {
|
||||
return debitResetAction(acc, sq, a, acs)
|
||||
} else {
|
||||
return err
|
||||
@@ -644,7 +644,7 @@ func conditionalDebitResetAction(acc *Account, sq *StatsQueueTriggered, a *Actio
|
||||
}
|
||||
|
||||
func conditionalTopupAction(acc *Account, sq *StatsQueueTriggered, a *Action, acs Actions) error {
|
||||
if matched, err := acc.matchConditions(a.ExtraParameters, a.BalanceType); matched {
|
||||
if matched, err := acc.matchConditions(a.ExtraParameters); matched {
|
||||
return topupAction(acc, sq, a, acs)
|
||||
} else {
|
||||
return err
|
||||
@@ -652,7 +652,7 @@ func conditionalTopupAction(acc *Account, sq *StatsQueueTriggered, a *Action, ac
|
||||
}
|
||||
|
||||
func conditionalTopupResetAction(acc *Account, sq *StatsQueueTriggered, a *Action, acs Actions) error {
|
||||
if matched, err := acc.matchConditions(a.ExtraParameters, a.BalanceType); matched {
|
||||
if matched, err := acc.matchConditions(a.ExtraParameters); matched {
|
||||
return topupResetAction(acc, sq, a, acs)
|
||||
} else {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user