Skip to content

Commit

Permalink
update validator
Browse files Browse the repository at this point in the history
  • Loading branch information
weixiyen committed Jan 17, 2018
1 parent 31242a9 commit d185dc9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions lib/triton/validate.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ defmodule Triton.Validate do
err_list -> {:error, err_list |> Triton.Error.vex_error}
end
end
def validate(:update, query, schema) do
data = query[:prepared] && query[:prepared] ++ (query[:update] |> Enum.filter(fn {_, v} -> !is_atom(v) end)) || query[:update]
fields_to_validate = data |> Enum.map(&(elem(&1, 0)))
vex = schema |> Enum.filter(fn({_, opts}) -> opts[:opts][:validators] end) |> Enum.map(fn {field, opts} -> {field, opts[:opts][:validators]} end) |> Enum.filter(&(elem(&1, 0) in fields_to_validate))
case Vex.errors(data ++ [_vex: vex]) do
[] -> {:ok, query}
err_list -> {:error, err_list |> Triton.Error.vex_error}
end
end
def validate(_, query, _), do: {:ok, query}

defp coerce({:__schema__, v}, _), do: {:__schema__, v}
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Triton.Mixfile do
use Mix.Project

@version "0.1.4"
@version "0.1.5"
@url "https://github.com/blitzstudios/triton"
@maintainers ["Weixi Yen"]

Expand Down

0 comments on commit d185dc9

Please sign in to comment.