Skip to content

Commit

Permalink
[master] HELP-44761: fixed crashes in quantities view query (2600hz#5870
Browse files Browse the repository at this point in the history
)

* HELP-44761: fixed crashes in quantities view query

* HELP-44761: fmt fix
  • Loading branch information
swysor authored and lazedo committed Jun 26, 2019
1 parent 9992053 commit bfb2314
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions core/kazoo_services/src/kz_services_quantities.erl
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,19 @@ fetch_port(AccountId, View) ->
,{'startkey', [AccountId]}
,{'endkey', [AccountId, kz_json:new()]}
],
{'ok', JObjs} = kz_datamgr:get_results(?KZ_PORT_REQUESTS_DB, View, ViewOptions),
Quantities = [{port_key(kz_json:get_value(<<"key">>, JObj))
,kz_json:get_integer_value(<<"value">>, JObj, 0)
}
|| JObj <- JObjs
],
kz_json:set_values(Quantities, kz_json:new()).
case kz_datamgr:get_results(?KZ_PORT_REQUESTS_DB, View, ViewOptions) of
{'ok', JObjs} ->
Quantities = [{port_key(kz_json:get_value(<<"key">>, JObj))
,kz_json:get_integer_value(<<"value">>, JObj, 0)
}
|| JObj <- JObjs
],
kz_json:set_values(Quantities, kz_json:new());
{'error', _Message} ->
?SUP_LOG_ERROR("failed to query port quantities account: ~s with error: ~p", [AccountId, _Message]),
kz_json:new()
end.


-spec port_key(kz_term:ne_binaries()) -> kz_term:ne_binaries().
port_key([_AccountId, State]) ->
Expand All @@ -93,13 +99,18 @@ fetch_account_cascade(AccountId) ->

-spec fetch(kz_term:ne_binary(), kz_term:ne_binary(), kz_term:proplist()) -> kz_json:object().
fetch(Database, View, ViewOptions) ->
{'ok', JObjs} = kz_datamgr:get_results(Database, View, ViewOptions),
Quantities = [{kz_json:get_value(<<"key">>, JObj)
,kz_json:get_integer_value(<<"value">>, JObj, 0)
}
|| JObj <- JObjs
],
fetch_to_json(Quantities).
case kz_datamgr:get_results(Database, View, ViewOptions) of
{'ok', JObjs} ->
Quantities = [{kz_json:get_value(<<"key">>, JObj)
,kz_json:get_integer_value(<<"value">>, JObj, 0)
}
|| JObj <- JObjs
],
fetch_to_json(Quantities);
{'error', _Message} ->
?SUP_LOG_ERROR("failed to query account quantities: ~s with error: ~p", [Database, _Message]),
kz_json:new()
end.

-spec fetch_to_json(quantities_prop()) -> kz_json:object().
fetch_to_json(Quantities) ->
Expand Down

0 comments on commit bfb2314

Please sign in to comment.