Пример #1
0
// Queries specific DerivedCharge on tariff plan
func (self *ApierV1) GetTPAccountActions(attrs AttrGetTPAccountActions, reply *utils.TPAccountActions) error {
	if missing := utils.MissingStructFields(&attrs, []string{"TPid", "AccountActionsId"}); len(missing) != 0 { //Params missing
		return utils.NewErrMandatoryIeMissing(missing...)
	}
	tmpAa := &utils.TPAccountActions{TPid: attrs.TPid}
	if err := tmpAa.SetAccountActionsId(attrs.AccountActionsId); err != nil {
		return err
	}
	tmpAaa := engine.APItoModelAccountAction(tmpAa)
	if aas, err := self.StorDb.GetTpAccountActions(tmpAaa); err != nil {
		return utils.NewErrServerError(err)
	} else if len(aas) == 0 {
		return utils.ErrNotFound
	} else {
		tpAaa, err := engine.TpAccountActions(aas).GetAccountActions()
		if err != nil {
			return err
		}
		aa := tpAaa[tmpAa.KeyId()]
		tpdc := utils.TPAccountActions{
			TPid:             attrs.TPid,
			ActionPlanId:     aa.ActionPlanId,
			ActionTriggersId: aa.ActionTriggersId,
		}
		if err := tpdc.SetAccountActionsId(attrs.AccountActionsId); err != nil {
			return err
		}
		*reply = tpdc
	}
	return nil
}
Пример #2
0
// Queries specific AccountActions profile on tariff plan
func (self *ApierV1) GetTPAccountActionsByLoadId(attrs utils.TPAccountActions, reply *[]*utils.TPAccountActions) error {
	mndtryFlds := []string{"TPid", "LoadId"}
	if len(attrs.Account) != 0 { // If account provided as filter, make all related fields mandatory
		mndtryFlds = append(mndtryFlds, "Tenant", "Account")
	}
	if missing := utils.MissingStructFields(&attrs, mndtryFlds); len(missing) != 0 { //Params missing
		return utils.NewErrMandatoryIeMissing(missing...)
	}
	aas := engine.APItoModelAccountAction(&attrs)
	if aa, err := self.StorDb.GetTpAccountActions(aas); err != nil {
		return utils.NewErrServerError(err)
	} else if len(aa) == 0 {
		return utils.ErrNotFound
	} else {

		tpAa, err := engine.TpAccountActions(aa).GetAccountActions()
		if err != nil {
			return err
		}
		var acts []*utils.TPAccountActions
		if len(attrs.Account) != 0 {
			acts = []*utils.TPAccountActions{tpAa[attrs.KeyId()]}
		} else {
			for _, actLst := range tpAa {
				acts = append(acts, actLst)
			}
		}
		*reply = acts
	}
	return nil
}