Skip to content

Commit

Permalink
number services reconcile (2600hz#2982)
Browse files Browse the repository at this point in the history
* don't crash if account has no numbers to reconcile

* use reset if no results

* use macro and add missing categories
  • Loading branch information
lazedo authored and fenollp committed Dec 13, 2016
1 parent fad0408 commit df7581c
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions core/kazoo_services/src/services/kz_service_phone_numbers.erl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
-define(FEATURES, [?KEY_VALUE, <<"features">>]).
-define(MODULES, [?KEY_VALUE, <<"modules">>]).

-define(DEFAULT_RESET_CATEGORIES, [?PHONE_NUMBERS
,?NUMBER_SERVICES
,?PHONE_NUMBERS_NON_BILLABLE
,?NUMBER_CARRIERS
]).

-type pn() :: knm_phone_number:knm_phone_number().
-type pns() :: [pn()].

Expand All @@ -42,6 +48,7 @@ reconcile(Services) ->
{error, _R} ->
lager:debug("unable to get reconcile_services for phone numbers: ~p", [_R]),
Services;
{ok, []} -> reset(Services);
{ok, [JObj]} ->
Categories = #{?BILLABLE => ?PHONE_NUMBERS
,?NON_BILLABLE => ?PHONE_NUMBERS_NON_BILLABLE
Expand All @@ -53,9 +60,16 @@ reconcile(Services) ->
end.

reconcile(Services, PNs) ->
S1 = kz_services:reset_category(?PHONE_NUMBERS, Services),
S2 = kz_services:reset_category(?NUMBER_SERVICES, S1),
update_numbers(S2, PNs).
update_numbers(reset(Services), PNs).

-spec reset(kz_services:services()) -> kz_services:services().
reset(Services) ->
reset(Services, ?DEFAULT_RESET_CATEGORIES).

-spec reset(kz_services:services(), ne_binaries()) -> kz_services:services().
reset(Services, []) -> Services;
reset(Services, [Category | Categories]) ->
reset(kz_services:reset_category(Category, Services), Categories).

%%--------------------------------------------------------------------
%% @public
Expand Down

0 comments on commit df7581c

Please sign in to comment.