fix subscriptions
This commit is contained in:
@@ -193,7 +193,8 @@ apply_updates(Sub, Updates) ->
|
|||||||
<<"expired">> -> expired;
|
<<"expired">> -> expired;
|
||||||
Other -> Other
|
Other -> Other
|
||||||
end,
|
end,
|
||||||
Acc#subscription{status = NewStatus, updated_at = calendar:universal_time()};
|
Acc#subscription{status = NewStatus,
|
||||||
|
updated_at = calendar:universal_time()};
|
||||||
<<"plan">> ->
|
<<"plan">> ->
|
||||||
NewPlan = case Value of
|
NewPlan = case Value of
|
||||||
<<"monthly">> -> monthly;
|
<<"monthly">> -> monthly;
|
||||||
@@ -203,13 +204,38 @@ apply_updates(Sub, Updates) ->
|
|||||||
<<"annual">> -> annual;
|
<<"annual">> -> annual;
|
||||||
Other -> Other
|
Other -> Other
|
||||||
end,
|
end,
|
||||||
Acc#subscription{plan = NewPlan, updated_at = calendar:universal_time()};
|
Acc#subscription{plan = NewPlan,
|
||||||
|
updated_at = calendar:universal_time()};
|
||||||
<<"trial_used">> ->
|
<<"trial_used">> ->
|
||||||
Acc#subscription{trial_used = Value, updated_at = calendar:universal_time()};
|
Acc#subscription{trial_used = Value,
|
||||||
|
updated_at = calendar:universal_time()};
|
||||||
<<"expires_at">> ->
|
<<"expires_at">> ->
|
||||||
Acc#subscription{expires_at = Value, updated_at = calendar:universal_time()};
|
Acc#subscription{expires_at = parse_iso_datetime(Value),
|
||||||
_ -> Acc
|
updated_at = calendar:universal_time()};
|
||||||
|
<<"started_at">> ->
|
||||||
|
Acc#subscription{started_at = parse_iso_datetime(Value),
|
||||||
|
updated_at = calendar:universal_time()};
|
||||||
|
_ ->
|
||||||
|
Acc
|
||||||
end
|
end
|
||||||
end, Sub, maps:to_list(Updates)).
|
end, Sub, maps:to_list(Updates)).
|
||||||
|
|
||||||
|
parse_iso_datetime(Bin) when is_binary(Bin) ->
|
||||||
|
try
|
||||||
|
[DateStr, TimeStr] = string:split(Bin, "T"),
|
||||||
|
TimeStrNoZ = string:trim(TimeStr, trailing, "Z"),
|
||||||
|
[YearStr, MonthStr, DayStr] = string:split(DateStr, "-", all),
|
||||||
|
[HourStr, MinuteStr, SecondStr] = string:split(TimeStrNoZ, ":", all),
|
||||||
|
Year = binary_to_integer(list_to_binary(YearStr)),
|
||||||
|
Month = binary_to_integer(list_to_binary(MonthStr)),
|
||||||
|
Day = binary_to_integer(list_to_binary(DayStr)),
|
||||||
|
Hour = binary_to_integer(list_to_binary(HourStr)),
|
||||||
|
Minute = binary_to_integer(list_to_binary(MinuteStr)),
|
||||||
|
Second = binary_to_integer(list_to_binary(SecondStr)),
|
||||||
|
{{Year, Month, Day}, {Hour, Minute, Second}}
|
||||||
|
catch
|
||||||
|
_:_ -> Bin % если не получилось разобрать, оставляем как есть
|
||||||
|
end;
|
||||||
|
parse_iso_datetime(Other) -> Other.
|
||||||
|
|
||||||
count_subscription() -> mnesia:table_info(subscription, size).
|
count_subscription() -> mnesia:table_info(subscription, size).
|
||||||
@@ -319,8 +319,13 @@ subscription_to_json(Subscription) ->
|
|||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
|
|
||||||
%% @private
|
%% @private
|
||||||
-spec datetime_to_iso8601(calendar:datetime() | undefined) -> binary() | undefined.
|
-spec datetime_to_iso8601(calendar:datetime() | binary() | undefined) -> binary() | undefined.
|
||||||
datetime_to_iso8601(undefined) -> undefined;
|
datetime_to_iso8601(undefined) -> undefined;
|
||||||
|
datetime_to_iso8601(Bin) when is_binary(Bin) ->
|
||||||
|
case byte_size(Bin) > 0 of
|
||||||
|
true -> Bin;
|
||||||
|
false -> undefined
|
||||||
|
end;
|
||||||
datetime_to_iso8601({{Year, Month, Day}, {Hour, Minute, Second}}) ->
|
datetime_to_iso8601({{Year, Month, Day}, {Hour, Minute, Second}}) ->
|
||||||
iolist_to_binary(
|
iolist_to_binary(
|
||||||
io_lib:format("~4..0B-~2..0B-~2..0BT~2..0B:~2..0B:~2..0BZ",
|
io_lib:format("~4..0B-~2..0B-~2..0BT~2..0B:~2..0B:~2..0BZ",
|
||||||
|
|||||||
Reference in New Issue
Block a user