mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-17 06:09:53 +05:00
*usage and *startTime in ApiOpts for rates and accounts
This commit is contained in:
committed by
Dan Christian Bogos
parent
d7bd43b0bc
commit
96b7c979bf
@@ -896,17 +896,20 @@ func (args *ArgsCostForEvent) StartTime(tmz string) (sTime time.Time, err error)
|
||||
if tIface, has := args.APIOpts[OptsRatesStartTime]; has {
|
||||
return IfaceAsTime(tIface, tmz)
|
||||
}
|
||||
if tIface, has := args.APIOpts[MetaStartTime]; has {
|
||||
return IfaceAsTime(tIface, tmz)
|
||||
}
|
||||
return time.Now(), nil
|
||||
}
|
||||
|
||||
// usage returns the event time used to check active rate profiles
|
||||
func (args *ArgsCostForEvent) Usage() (usage *decimal.Big, err error) {
|
||||
// first search for the usage in opts
|
||||
// first search for the rateUsage in opts
|
||||
if uIface, has := args.APIOpts[OptsRatesUsage]; has {
|
||||
return IfaceAsBig(uIface)
|
||||
}
|
||||
// if the usage is not present in opts search in event
|
||||
if uIface, has := args.Event[Usage]; has {
|
||||
// second search for the usage in opts
|
||||
if uIface, has := args.APIOpts[MetaUsage]; has {
|
||||
return IfaceAsBig(uIface)
|
||||
}
|
||||
// if the usage is not found in the event populate with default value and overwrite the NOT_FOUND error with nil
|
||||
|
||||
@@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package utils
|
||||
|
||||
import (
|
||||
"github.com/ericlagergren/decimal"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
@@ -83,14 +84,14 @@ func (ev *CGREvent) FieldAsDuration(fldName string) (d time.Duration, err error)
|
||||
return IfaceAsDuration(iface)
|
||||
}
|
||||
|
||||
// OptAsDuration returns an option as Duration instance
|
||||
func (ev *CGREvent) OptAsDuration(optName string) (d time.Duration, err error) {
|
||||
// OptsAsDecimal OptAsDecimal returns an option as decimal.Big instance
|
||||
func (ev *CGREvent) OptsAsDecimal(optName string) (d *decimal.Big, err error) {
|
||||
iface, has := ev.APIOpts[optName]
|
||||
if !has {
|
||||
err = ErrNotFound
|
||||
return
|
||||
}
|
||||
return IfaceAsDuration(iface)
|
||||
return IfaceAsBig(iface)
|
||||
}
|
||||
|
||||
func (ev *CGREvent) Clone() (clned *CGREvent) {
|
||||
|
||||
@@ -850,6 +850,7 @@ const (
|
||||
MetaExporterIDs = "*exporterIDs"
|
||||
MetaAsync = "*async"
|
||||
MetaUsage = "*usage"
|
||||
MetaStartTime = "*startTime"
|
||||
Weights = "Weights"
|
||||
UnitFactors = "UnitFactors"
|
||||
CostIncrements = "CostIncrements"
|
||||
|
||||
Reference in New Issue
Block a user