-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: create migration and schema for new table relatorios * feat: create new liveview for relatorios * fix: remove old alias and add new alis for relatorio_pesquisa model * chore: mix format * chore: fix credo * fix: fix tests * fix: fix tests * fix: report is not saving * feat: blocks editing when the report has been delivered --------- Co-authored-by: Zoey de Souza Pessanha <[email protected]>
- Loading branch information
1 parent
ac7bf76
commit b423733
Showing
29 changed files
with
718 additions
and
673 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
apps/modulo_pesquisa/lib/modulo_pesquisa/handlers/relatorios_handler.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 0 additions & 78 deletions
78
apps/modulo_pesquisa/lib/modulo_pesquisa/models/relatorio_anual_pesquisa.ex
This file was deleted.
Oops, something went wrong.
81 changes: 0 additions & 81 deletions
81
apps/modulo_pesquisa/lib/modulo_pesquisa/models/relatorio_mensal_pesquisa.ex
This file was deleted.
Oops, something went wrong.
82 changes: 82 additions & 0 deletions
82
apps/modulo_pesquisa/lib/modulo_pesquisa/models/relatorio_pesquisa.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
defmodule ModuloPesquisa.Models.RelatorioPesquisa do | ||
use Database, :model | ||
|
||
alias ModuloPesquisa.Models.Pesquisador | ||
alias ModuloPesquisa.Schemas.ConteudoAnual | ||
alias ModuloPesquisa.Schemas.ConteudoMensal | ||
alias ModuloPesquisa.Schemas.ConteudoTrimestral | ||
|
||
@type t :: %RelatorioPesquisa{ | ||
tipo: atom, | ||
data_inicio: Date.t(), | ||
data_fim: Date.t(), | ||
data_entrega: Date.t(), | ||
data_limite: Date.t(), | ||
link: binary, | ||
status: atom, | ||
pesquisador: Pesquisador.t(), | ||
id_publico: binary | ||
} | ||
|
||
@tipo ~w(mensal bimestral trimestral anual)a | ||
@status ~w(entregue atrasado pendente)a | ||
|
||
@required_fields ~w(tipo data_inicio data_fim status pesquisador_id)a | ||
@optional_fields ~w(data_entrega data_limite link)a | ||
|
||
@primary_key false | ||
schema "relatorio_pesquisa" do | ||
field(:link, :string) | ||
field(:data_inicio, :date, primary_key: true) | ||
field(:data_fim, :date, primary_key: true) | ||
field(:data_entrega, :date) | ||
field(:data_limite, :date) | ||
field(:tipo, Ecto.Enum, values: @tipo) | ||
field(:status, Ecto.Enum, values: @status) | ||
field(:id_publico, Database.Types.PublicId, autogenerate: true) | ||
|
||
embeds_one(:conteudo_anual, ConteudoAnual, source: :conteudo, on_replace: :update) | ||
embeds_one(:conteudo_mensal, ConteudoMensal, source: :conteudo, on_replace: :update) | ||
embeds_one(:conteudo_trimestral, ConteudoTrimestral, source: :conteudo, on_replace: :update) | ||
|
||
belongs_to(:pesquisador, Pesquisador, | ||
on_replace: :update, | ||
references: :id_publico, | ||
type: :string, | ||
primary_key: true | ||
) | ||
|
||
timestamps() | ||
end | ||
|
||
@spec changeset(RelatorioPesquisa.t(), map) :: changeset | ||
def changeset(%RelatorioPesquisa{} = relatorio, attrs) do | ||
relatorio | ||
|> cast(attrs, @required_fields ++ @optional_fields) | ||
|> cast_embed(:conteudo_anual) | ||
|> cast_embed(:conteudo_mensal) | ||
|> cast_embed(:conteudo_trimestral) | ||
|> validate_required(@required_fields) | ||
|> validate_inclusion(:tipo, @tipo) | ||
|> validate_inclusion(:status, @status) | ||
|> foreign_key_constraint(:pesquisador_id) | ||
|> validate_period() | ||
end | ||
|
||
defp validate_period(changeset) do | ||
start_date = get_field(changeset, :data_inicio) | ||
end_date = get_field(changeset, :data_fim) | ||
|
||
case {start_date, end_date} do | ||
{start_date, end_date} when is_nil(start_date) or is_nil(end_date) -> | ||
changeset | ||
|
||
{_, _} -> | ||
if Date.compare(start_date, end_date) == :gt do | ||
add_error(changeset, :data_inicio, "A data de início deve ser anterior à data de fim") | ||
else | ||
changeset | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.