|
1 | 1 | defmodule CodeCorps.OrganizationMembershipController do |
2 | 2 | use CodeCorps.Web, :controller |
3 | 3 |
|
4 | | - import CodeCorps.ControllerHelpers |
5 | | - |
6 | 4 | alias JaSerializer.Params |
7 | 5 | alias CodeCorps.OrganizationMembership |
8 | 6 |
|
9 | 7 | plug :scrub_params, "data" when action in [:create, :update] |
10 | 8 |
|
11 | 9 | def index(conn, params) do |
12 | 10 | memberships = |
13 | | - case params do |
14 | | - %{"organization_id" => organization_id, "role" => roles, "filter" => id_list} -> |
15 | | - roles = roles |> coalesce_string |
16 | | - ids = id_list |> coalesce_id_string |
17 | | - OrganizationMembership |
18 | | - |> where([om], om.organization_id == ^organization_id) |
19 | | - |> where([om], om.member_id in ^ids) |
20 | | - |> where([om], om.role in ^roles) |
21 | | - %{"organization_id" => organization_id, "role" => roles} -> |
22 | | - roles = roles |> coalesce_string |
23 | | - OrganizationMembership |
24 | | - |> where([om], om.organization_id == ^organization_id) |
25 | | - |> where([om], om.role in ^roles) |
26 | | - %{"organization_id" => organization_id, "filter" => id_list} -> |
27 | | - id_list = id_list |> coalesce_id_string |
28 | | - OrganizationMembership |
29 | | - |> where([om], om.organization_id == ^organization_id) |
30 | | - |> where([om], om.id in ^id_list) |
31 | | - %{"role" => roles, "filter" => id_list} -> |
32 | | - roles = roles |> coalesce_string |
33 | | - ids = id_list |> coalesce_id_string |
34 | | - OrganizationMembership |
35 | | - |> where([om], om.member_id in ^ids) |
36 | | - |> where([om], om.role in ^roles) |
37 | | - %{"organization_id" => organization_id} -> |
38 | | - OrganizationMembership |
39 | | - |> where([om], om.organization_id == ^organization_id) |
40 | | - %{"filter" => id_list} -> |
41 | | - ids = id_list |> coalesce_id_string |
42 | | - OrganizationMembership |
43 | | - |> where([om], om.member_id in ^ids) |
44 | | - %{"role" => roles} -> |
45 | | - roles = roles |> coalesce_string |
46 | | - OrganizationMembership |
47 | | - |> where([om], om.role in ^roles) |
48 | | - _ -> |
49 | | - OrganizationMembership |
50 | | - end |
51 | | - |
52 | | - memberships = |
53 | | - memberships |
| 11 | + OrganizationMembership |
| 12 | + |> OrganizationMembership.add_filters(params) |
54 | 13 | |> preload([:organization, :member]) |
55 | 14 | |> Repo.all |
56 | 15 |
|
|
0 commit comments