fix: owner event bookings list and paid plan durations from plan_to_months.
CI / test (push) Successful in 6m55s
CI / deploy-ift (push) Successful in 3m33s
CI / e2e-ift (push) Failing after 1m4s
CI / deploy-stage (push) Has been skipped
CI / e2e-stage (push) Has been skipped

Fixes EventHub/EventHubBack#51
Fixes EventHub/EventHubBack#52

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-07-21 20:18:49 +03:00
parent 7368adfb37
commit 5ac23219ca
6 changed files with 133 additions and 26 deletions
+6 -19
View File
@@ -8,35 +8,27 @@
-export([count_subscriptions_by_plan/0, count_subscriptions_by_status/0,
count_trial_subscriptions/0, get_ending_paid_subscriptions/1]).
-define(TRIAL_DAYS, 30).
%%%-------------------------------------------------------------------
%%% @doc Создание подписки.
%%% `TrialUsed` `true`, если подписка платная; `false` для пробного периода.
%%% `TrialUsed` флаг (использован ли trial); на длительность не влияет.
%%% Длительность всегда считается из `Plan` через `plan_to_months/1`.
%%% Все поля записи инициализированы, `undefined` не возникает.
%%% @end
%%%-------------------------------------------------------------------
-spec create(UserId :: binary(), Plan :: monthly | quarterly | biannual | annual,
-spec create(UserId :: binary(), Plan :: monthly | quarterly | biannual | annual | trial,
TrialUsed :: boolean()) -> {ok, #subscription{}} | {error, term()}.
create(UserId, Plan, TrialUsed) ->
Id = infra_utils:generate_id(16),
Now = calendar:universal_time(),
{StartDate, EndDate} = case TrialUsed of
true ->
DurationMonths = plan_to_months(Plan),
End = add_months(Now, DurationMonths),
{Now, End};
false ->
End = add_days(Now, ?TRIAL_DAYS),
{Now, End}
end,
DurationMonths = plan_to_months(Plan),
EndDate = add_months(Now, DurationMonths),
Subscription = #subscription{
id = Id,
user_id = UserId,
plan = Plan,
status = active,
trial_used = TrialUsed,
started_at = StartDate,
started_at = Now,
expires_at = EndDate,
created_at = Now,
updated_at = Now
@@ -167,11 +159,6 @@ add_months(DateTime, Months) ->
NewDays = Days + (Months * 30),
calendar:gregorian_seconds_to_datetime(NewDays * 86400).
-spec add_days(calendar:datetime(), pos_integer()) -> calendar:datetime().
add_days(DateTime, Days) ->
Seconds = calendar:datetime_to_gregorian_seconds(DateTime),
calendar:gregorian_seconds_to_datetime(Seconds + (Days * 86400)).
%%%===================================================================
%%% Новые обёртки для админки
%%%===================================================================