implemented *has operator and added Type field

This commit is contained in:
Radu Ioan Fericean
2016-01-19 16:12:21 +02:00
parent f9bcba9745
commit 2812eafc3e
4 changed files with 138 additions and 29 deletions

View File

@@ -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

View File

@@ -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