diff --git a/applications/doodle/src/tf_util.erl b/applications/doodle/src/tf_util.erl index 841f03f4836..1f4fce5fe6b 100644 --- a/applications/doodle/src/tf_util.erl +++ b/applications/doodle/src/tf_util.erl @@ -85,13 +85,13 @@ maybe_do_not_disturb(Endpoint, _Properties, _Im) -> -spec create_im_endpoints(kz_json:object(), kz_json:object(), kapps_im:im()) -> kz_json:objects(). create_im_endpoints(Endpoint, Properties, Im) -> - create_im_endpoints(kz_doc:type(Endpoint), Endpoint, Properties, Im). + create_im_endpoints(kzd_endpoint:type(Endpoint), Endpoint, Properties, Im). -spec create_im_endpoints(kz_term:ne_binary(), kz_json:object(), kz_json:object(), kapps_im:im()) -> kz_json:objects(). create_im_endpoints(<<"device">>, Endpoint, Properties, Im) -> [create_im_endpoint(Endpoint, Properties, Im)]; create_im_endpoints(<<"user">>, Endpoint, Properties, Im) -> - OwnerId = kz_doc:id(Endpoint), + OwnerId = kzd_endpoint:id(Endpoint), EndpointIds = [kz_doc:id(EP) || EP <- kz_attributes:owned_by_docs(OwnerId, kapps_im:account_id(Im)) ,<<"device">> =:= kz_doc:type(EP) @@ -107,7 +107,7 @@ create_im_endpoint(Endpoint, _Properties, Im) -> [{<<"To-Username">>, kzd_devices:sip_username(Endpoint)} ,{<<"To-Realm">>, kzd_devices:sip_realm(Endpoint, kapps_im:to_realm(Im))} ,{<<"To-DID">>, kapps_im:request_user(Im)} - ,{<<"Endpoint-ID">>, kz_doc:id(Endpoint)} + ,{<<"Endpoint-ID">>, kzd_endpoint:id(Endpoint)} ,{<<"Invite-Format">>, kzd_devices:sip_invite_format(Endpoint)} ]). diff --git a/core/kazoo_documents/src/kzd_endpoint.erl b/core/kazoo_documents/src/kzd_endpoint.erl new file mode 100644 index 00000000000..f77774276db --- /dev/null +++ b/core/kazoo_documents/src/kzd_endpoint.erl @@ -0,0 +1,23 @@ +%%%----------------------------------------------------------------------------- +%%% @copyright (C) 2010-2019, 2600Hz +%%% @doc This Source Code Form is subject to the terms of the Mozilla Public +%%% License, v. 2.0. If a copy of the MPL was not distributed with this +%%% file, You can obtain one at https://mozilla.org/MPL/2.0/. +%%% +%%% @end +%%%----------------------------------------------------------------------------- +-module(kzd_endpoint). + +-export([id/1]). +-export([type/1]). + +-type endpoint() :: kz_json:object(). +-export_type([endpoint/0]). + +-spec id(endpoint()) -> kz_term:ne_binary(). +id(Endpoint) -> + kz_json:get_ne_binary_value(<<"Endpoint-ID">>, Endpoint). + +-spec type(endpoint()) -> kz_term:ne_binary(). +type(Endpoint) -> + kz_json:get_ne_binary_value(<<"Endpoint-Type">>, Endpoint). diff --git a/core/kazoo_endpoint/src/kz_endpoint.erl b/core/kazoo_endpoint/src/kz_endpoint.erl index 0f5cf798787..7f49629f9dc 100644 --- a/core/kazoo_endpoint/src/kz_endpoint.erl +++ b/core/kazoo_endpoint/src/kz_endpoint.erl @@ -177,7 +177,10 @@ is_endpoint_enabled(JObj, _) -> -spec cache_store_endpoint(kz_json:object(), kz_term:ne_binary(), kz_term:ne_binary(), kz_term:ne_binary()) -> {'ok', kz_json:object()}. cache_store_endpoint(JObj, EndpointId, AccountDb, EndpointType) -> - Endpoint = kz_json:set_value(<<"Endpoint-ID">>, EndpointId, merge_attributes(JObj, EndpointType)), + Values = [{<<"Endpoint-ID">>, EndpointId} + ,{<<"Endpoint-Type">>, EndpointType} + ], + Endpoint = kz_json:set_values(Values, merge_attributes(JObj, EndpointType)), CacheProps = [{'origin', cache_origin(JObj, EndpointId, AccountDb)}], catch kz_cache:store_local(?CACHE_NAME, {?MODULE, AccountDb, EndpointId}, Endpoint, CacheProps), {'ok', Endpoint}.