5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'app/controllers/dscf/credit/users_controller.rb', line 5
def index
super do
if params[:business_type].present?
business_type_name = params[:business_type].downcase
business_type = Dscf::Core::BusinessType.find_by(name: business_type_name)
unless business_type
return render_error(
"validation.invalid",
errors: "Invalid business type: #{params[:business_type]}",
status: :not_found
)
end
users = @clazz
.joins(businesses: :business_type)
.where(dscf_core_business_types: { id: business_type.id })
.where(
<<-SQL.squish
NOT EXISTS (
SELECT 1
FROM dscf_credit_facilitator_applications fa
WHERE fa.user_id = dscf_core_users.id
AND NOT EXISTS (
SELECT 1
FROM dscf_core_reviews r
WHERE r.reviewable_type = 'Dscf::Credit::FacilitatorApplication'
AND r.reviewable_id = fa.id
AND r.status = 'rejected'
)
)
SQL
)
.distinct
users
else
@clazz.all
end
end
end
|