1+ defmodule CodeCorpsWeb.TaskJsonapiView do
2+ @ moduledoc false
3+ use CodeCorpsWeb , :view
4+ use JSONAPI.View , type: "task"
5+
6+ def fields , do: [
7+ :archived , :body , :created_at , :created_from , :has_github_pull_request ,
8+ :inserted_at , :markdown , :modified_at , :modified_from , :number , :order ,
9+ :overall_status , :status , :title , :updated_at
10+ ]
11+
12+ # def relationships do
13+ # [github_issue]
14+ # end
15+
16+ # has_one :github_issue, type: "github-issue", field: :github_issue_id
17+ # has_one :github_pull_request, serializer: CodeCorpsWeb.GithubPullRequestView, identifiers: :always
18+ # has_one :github_repo, type: "github-repo", field: :github_repo_id
19+ # has_one :project, type: "project", field: :project_id
20+ # has_one :task_list, type: "task-list", field: :task_list_id
21+ # has_one :user, type: "user", field: :user_id
22+ # has_one :user_task, serializer: CodeCorpsWeb.UserTaskView, identifiers: :always
23+
24+ # has_many :comments, serializer: CodeCorpsWeb.CommentView, identifiers: :always
25+ # has_many :task_skills, serializer: CodeCorpsWeb.TaskSkillView, identifiers: :always
26+
27+ def has_github_pull_request ( % {
28+ github_pull_request: % CodeCorps.GithubPullRequest { }
29+ } ) , do: true
30+ def has_github_pull_request ( % { github_pull_request: nil } ) , do: false
31+
32+ def overall_status ( % {
33+ github_pull_request: % CodeCorps.GithubPullRequest { merged: merged , state: state }
34+ } , _conn ) do
35+ case merged do
36+ true -> "merged"
37+ false -> state
38+ end
39+ end
40+ def overall_status ( % { github_pull_request: nil , status: status } , _conn ) do
41+ status
42+ end
43+ end
0 commit comments