forked from code-corps/code-corps-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathskill.ex
More file actions
35 lines (29 loc) · 843 Bytes
/
skill.ex
File metadata and controls
35 lines (29 loc) · 843 Bytes
1
2
3
4
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
defmodule CodeCorps.Skill do
use CodeCorps.Web, :model
import CodeCorps.ModelHelpers
schema "skills" do
field :title, :string
field :description, :string
field :original_row, :integer
has_many :role_skills, CodeCorps.RoleSkill
has_many :roles, through: [:role_skills, :role]
has_many :project_skills, CodeCorps.ProjectSkill
has_many :projects, through: [:project_skills, :project]
timestamps()
end
@doc """
Builds a changeset based on the `struct` and `params`.
"""
def changeset(struct, params \\ %{}) do
struct
|> cast(params, [:title, :description, :original_row])
|> validate_required([:title])
|> unique_constraint(:title)
end
def index_filters(query, params) do
query
|> id_filter(params)
|> title_filter(params)
|> limit_filter(params)
end
end