Class: Dscf::Marketplace::QuotationsController
Instance Method Summary
collapse
#bypass_permissions_for_demo?, #pundit_user
Instance Method Details
#accept ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'app/controllers/dscf/marketplace/quotations_controller.rb', line 26
def accept
@obj = find_record
authorize @obj, :accept?
fulfillment_type = params[:fulfillment_type]
dropoff_address_id = params[:dropoff_address_id]
payment_method = normalize_payment_method(params[:payment_method]).presence || "cash"
unless fulfillment_type.present? && Dscf::Marketplace::Order.fulfillment_types.keys.include?(fulfillment_type)
render_error("quotations.errors.invalid_fulfillment_type", status: :unprocessable_entity)
return
end
dropoff_address = nil
if dropoff_address_id.present?
dropoff_address = Dscf::Core::Address.find_by(id: dropoff_address_id) if defined?(Dscf::Core::Address)
unless dropoff_address && dropoff_address.user_id == current_user.id
render_error("quotations.errors.invalid_dropoff_address", status: :unprocessable_entity)
return
end
end
if fulfillment_type == "delivery" && dropoff_address.nil?
render_error("quotations.errors.dropoff_address_required", status: :unprocessable_entity)
return
end
unless %w[cash bank_transfer].include?(payment_method)
render_error(errors: "Credit is no longer supported for new marketplace orders", status: :unprocessable_entity)
return
end
if @obj.accept!(fulfillment_type: fulfillment_type, dropoff_address: dropoff_address, payment_method: payment_method)
render_success("quotations.success.accepted", data: @obj)
else
render_error("quotations.errors.accept_failed")
end
end
|
#filter ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'app/controllers/dscf/marketplace/quotations_controller.rb', line 6
def filter
authorize @clazz.new, :filter?
quotations = @clazz.all
if params[:q].present?
quotations = quotations.ransack(params[:q]).result
end
quotations = quotations.includes(eager_loaded_associations) if eager_loaded_associations.present?
includes = serializer_includes_for_action(:index)
options = {}
options[:include] = includes if includes.present?
render_success(data: quotations, serializer_options: options)
end
|
#my_quotes ⇒ Object
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'app/controllers/dscf/marketplace/quotations_controller.rb', line 86
def my_quotes
authorize @clazz.new, :my_quotes?
service = MyResourceService.new(current_user)
quotes = service.my_quotes(params)
options = {
include: default_serializer_includes[:index] || [],
meta: {resource_type: "my_quotes"}
}
render_success("quotations.success.index", data: quotes, serializer_options: options)
end
|
#reject ⇒ Object
66
67
68
69
70
71
72
73
74
|
# File 'app/controllers/dscf/marketplace/quotations_controller.rb', line 66
def reject
@obj = find_record
authorize @obj, :reject?
if @obj.reject!
render_success("quotations.success.rejected", data: @obj)
else
render_error("quotations.errors.reject_failed")
end
end
|
#send_quotation ⇒ Object
76
77
78
79
80
81
82
83
84
|
# File 'app/controllers/dscf/marketplace/quotations_controller.rb', line 76
def send_quotation
@obj = find_record
authorize @obj, :send_quotation?
if @obj.send_quotation!
render_success("quotations.success.sent", data: @obj)
else
render_error("quotations.errors.send_failed")
end
end
|