Skip to content

Commit

Permalink
handle empty doc list to migrate
Browse files Browse the repository at this point in the history
  • Loading branch information
lazedo committed Mar 8, 2016
1 parent 7910fe4 commit 9890108
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions core/kazoo_number_manager/src/knm_port_request.erl
Original file line number Diff line number Diff line change
Expand Up @@ -478,13 +478,18 @@ migrate(StartKey, Limit) ->
-spec migrate_docs(wh_json:objects()) -> 'ok'.
migrate_docs([]) -> 'ok';
migrate_docs(Docs) ->
UpdatedDocs =
[UpdatedDoc
|| Doc <- Docs,
case prepare_docs_for_migrate(Docs) of
[] -> 'ok';
UpdatedDocs ->
{'ok', _} = kz_datamgr:save_docs(?KZ_PORT_REQUESTS_DB, UpdatedDocs),
'ok'
end.

-spec prepare_docs_for_migrate(wh_json:objects()) -> wh_json:objects().
prepare_docs_for_migrate(Docs) ->
[UpdatedDoc || Doc <- Docs,
(UpdatedDoc = migrate_doc(wh_json:get_value(<<"doc">>, Doc))) =/= 'undefined'
],
{'ok', _} = kz_datamgr:save_docs(?KZ_PORT_REQUESTS_DB, UpdatedDocs),
'ok'.
].

-spec migrate_doc(wh_json:object()) -> api_object().
migrate_doc(PortRequest) ->
Expand Down

0 comments on commit 9890108

Please sign in to comment.