-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathokr.ex
More file actions
32 lines (24 loc) · 764 Bytes
/
okr.ex
File metadata and controls
32 lines (24 loc) · 764 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
defmodule OkrAppWeb.Serializer.Okr do
use Remodel
alias OkrAppWeb.Serializer
attributes([:id, :cycle, :objectives, :owner, :okr_reflection])
def cycle(record) do
Serializer.Cycle.to_map(record.cycle)
end
def objectives(record) do
record.objectives
|> Enum.map(&Serializer.Objective.to_map/1)
end
def okr_reflection(%{okr_reflection: nil}), do: nil
def okr_reflection(%{okr_reflection: reflection}) do
Serializer.OkrReflection.to_map(reflection)
end
def owner(%{user: user}) when not is_nil(user) do
Serializer.PlainUser.to_map(user)
|> Map.put("owner_type", "user")
end
def owner(%{group: group}) when not is_nil(group) do
Serializer.Group.to_map(group)
|> Map.put("owner_type", "group")
end
end