Current section

Files

Jump to
ami lib ami template_result.ex
Raw

lib/ami/template_result.ex

defmodule Ami.TemplateResult do
use Ecto.Schema
import Ecto.{Query}
alias Ami.{
TemplateResult,
Repo,
User
}
schema "assessment_template_results" do
@timestamps_opts [type: :naive_datetime_usec]
field(:note_actions, :string)
field(:note_evidence, :string)
field(:note_objectives, :string)
field(:note_skills, :string)
field(:report_created_at, :utc_datetime_usec)
field(:status, :integer)
field(:created_at, :utc_datetime_usec)
field(:updated_at, :utc_datetime_usec)
belongs_to(:user, User)
belongs_to(:owner_result, TemplateResult)
# belongs_to :template, Template
# belongs_to :owner_respondent, RespondentRequest, foreign_key: :owner_respondent_id
has_many(:respondent_results, TemplateResult, foreign_key: :owner_result_id)
# has_many :section_results, SectionResult
# has_many :respondent_requests, RespondentRequest
end
def get_done_self_assessments_for(user) do
Repo.all(
from(
tp in TemplateResult,
where: tp.user_id == ^user.id,
where: tp.status == 1,
where: is_nil(tp.owner_result_id),
order_by: tp.created_at,
preload: :respondent_results
)
)
end
end