feat: Add APIs to create custom views on the dashboard (#2498)

This commit is contained in:
Pranav Raj S
2021-06-29 19:29:57 +05:30
committed by GitHub
parent fa37f8e185
commit 30832d8a34
27 changed files with 654 additions and 9 deletions

View File

@@ -0,0 +1,50 @@
class Api::V1::Accounts::CustomFiltersController < Api::V1::Accounts::BaseController
protect_from_forgery with: :null_session
before_action :fetch_custom_filters, except: [:create]
before_action :fetch_custom_filter, only: [:show, :update, :destroy]
DEFAULT_FILTER_TYPE = 'conversation'.freeze
def index; end
def show; end
def create
@custom_filter = current_user.custom_filters.create!(
permitted_payload.merge(account_id: Current.account.id)
)
end
def update
@custom_filter.update!(permitted_payload)
end
def destroy
@custom_filter.destroy
head :no_content
end
private
def fetch_custom_filters
@custom_filters = current_user.custom_filters.where(
account_id: Current.account.id,
filter_type: permitted_params[:filter_type] || DEFAULT_FILTER_TYPE
)
end
def fetch_custom_filter
@custom_filter = @custom_filters.find(permitted_params[:id])
end
def permitted_payload
params.require(:custom_filter).permit(
:name,
:filter_type,
query: {}
)
end
def permitted_params
params.permit(:id, :filter_type)
end
end