Class: Dscf::Core::BusinessesController

Inherits:
ApplicationController show all
Includes:
Common, ReviewableController
Defined in:
app/controllers/dscf/core/businesses_controller.rb

Instance Method Summary collapse

Methods included from JsonResponse

#render_error, #render_success, #serialize

Methods included from Common

#index, #show

Methods included from Filterable

#filter_records

Methods included from Pagination

#default_per_page, #order_by, #order_direction, #page_no, #paginate, #paginate_offset, #pagination_links, #per_page

Methods included from TokenAuthenticatable

#require_valid_refresh_token, #validate_device_consistency, #validate_token_expiry

Methods included from Authenticatable

#authenticate_user, #authenticate_user!, #current_user, #refresh_token, #sign_in, #sign_out

Instance Method Details

#createObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/dscf/core/businesses_controller.rb', line 7

def create
  super do
    business = @clazz.new(model_params)
    business.user = current_user
    business.reviews.build(
      status: "draft",
      context: "default"
    )

    if business.save && params[:business][:business_license].present?
      document = business.documents.create!(
        document_type: :business_license
      )
      document.files.attach(params[:business][:business_license])
      document.save!
    end

    business
  end
end

#my_businessObject



39
40
41
42
43
# File 'app/controllers/dscf/core/businesses_controller.rb', line 39

def my_business
  index do
    current_user.businesses
  end
end

#updateObject



28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/dscf/core/businesses_controller.rb', line 28

def update
  unless @obj.editable?
    return render_error(
      errors: ["Cannot update Business after submission. Use modification request workflow instead."],
      status: :unprocessable_entity
    )
  end

  super
end