feat: Add APIs for custom attribute definitions (#2689)

This commit is contained in:
Pranav Raj S
2021-07-23 17:04:33 +05:30
committed by GitHub
parent 7e0937f3ed
commit 6e1493501a
13 changed files with 284 additions and 1 deletions

View File

@@ -0,0 +1,50 @@
class Api::V1::Accounts::CustomAttributeDefinitionsController < Api::V1::Accounts::BaseController
before_action :fetch_custom_attributes_definitions, except: [:create]
before_action :fetch_custom_attribute_definition, only: [:show, :update, :destroy]
DEFAULT_ATTRIBUTE_MODEL = 'conversation_attribute'.freeze
def index; end
def show; end
def create
@custom_attribute_definition = Current.account.custom_attribute_definitions.create!(
permitted_payload
)
end
def update
@custom_attribute_definition.update!(permitted_payload)
end
def destroy
@custom_attribute_definition.destroy
head :no_content
end
private
def fetch_custom_attributes_definitions
@custom_attribute_definitions = Current.account.custom_attribute_definitions.where(
attribute_model: permitted_params[:attribute_model] || DEFAULT_ATTRIBUTE_MODEL
)
end
def fetch_custom_attribute_definition
@custom_attribute_definition = @custom_attribute_definitions.find(permitted_params[:id])
end
def permitted_payload
params.require(:custom_attribute_definition).permit(
:attribute_display_name,
:attribute_display_type,
:attribute_key,
:attribute_model,
:default_value
)
end
def permitted_params
params.permit(:id, :filter_type)
end
end