Current section
Files
Jump to
Current section
Files
src/kitazith@internal@validation@poll.erl
-module(kitazith@internal@validation@poll).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/kitazith/internal/validation/poll.gleam").
-export([validate_poll/2]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(false).
-file("src/kitazith/internal/validation/poll.gleam", 57).
?DOC(false).
-spec validate_poll_answer(binary(), kitazith@poll:poll_answer()) -> list(kitazith@validation:validation_error()).
validate_poll_answer(Path, Answer) ->
case erlang:element(2, erlang:element(2, Answer)) of
{some, Text} ->
kitazith@internal@validation@common:validate_string_length(
kitazith@internal@validation@common:join_path(
Path,
<<"poll_media.text"/utf8>>
),
Text,
1,
55
);
none ->
[]
end.
-file("src/kitazith/internal/validation/poll.gleam", 8).
?DOC(false).
-spec validate_poll(binary(), kitazith@poll:poll()) -> list(kitazith@validation:validation_error()).
validate_poll(Path, Poll) ->
Max_poll_duration_hours = 24 * 32,
lists:append(
[kitazith@internal@validation@common:validate_string_length(
kitazith@internal@validation@common:join_path(
Path,
<<"question.text"/utf8>>
),
erlang:element(2, erlang:element(2, Poll)),
1,
300
),
kitazith@internal@validation@common:validate_list_max_length(
kitazith@internal@validation@common:join_path(
Path,
<<"answers"/utf8>>
),
erlang:element(3, Poll),
10,
<<"answers"/utf8>>
),
case erlang:element(4, Poll) of
{some, Duration} ->
case Duration > Max_poll_duration_hours of
true ->
[kitazith@internal@validation@common:error(
kitazith@internal@validation@common:join_path(
Path,
<<"duration"/utf8>>
),
{numeric_maximum_exceeded,
Max_poll_duration_hours,
Duration,
<<"hours"/utf8>>}
)];
false ->
[]
end;
none ->
[]
end,
begin
_pipe = erlang:element(3, Poll),
_pipe@1 = gleam@list:index_map(
_pipe,
fun(Answer, Index) ->
validate_poll_answer(
kitazith@internal@validation@common:indexed_path(
kitazith@internal@validation@common:join_path(
Path,
<<"answers"/utf8>>
),
Index
),
Answer
)
end
),
lists:append(_pipe@1)
end]
).