feat: booking JSON user_nickname/email for owner UI. Refs EventHub/EventHubBack#56
This commit is contained in:
@@ -181,17 +181,4 @@ cancel_booking(Req) ->
|
|||||||
%% Учитывает все поля из records.hrl.
|
%% Учитывает все поля из records.hrl.
|
||||||
-spec booking_to_json(#booking{}) -> map().
|
-spec booking_to_json(#booking{}) -> map().
|
||||||
booking_to_json(Booking) ->
|
booking_to_json(Booking) ->
|
||||||
#{
|
handler_utils:booking_to_json(Booking).
|
||||||
id => Booking#booking.id,
|
|
||||||
event_id => Booking#booking.event_id,
|
|
||||||
user_id => Booking#booking.user_id,
|
|
||||||
status => Booking#booking.status,
|
|
||||||
notes => Booking#booking.notes,
|
|
||||||
reminder_sent => Booking#booking.reminder_sent,
|
|
||||||
confirmed_at => case Booking#booking.confirmed_at of
|
|
||||||
undefined -> null;
|
|
||||||
Dt -> handler_utils:datetime_to_iso8601(Dt)
|
|
||||||
end,
|
|
||||||
created_at => handler_utils:datetime_to_iso8601(Booking#booking.created_at),
|
|
||||||
updated_at => handler_utils:datetime_to_iso8601(Booking#booking.updated_at)
|
|
||||||
}.
|
|
||||||
@@ -167,17 +167,4 @@ list_bookings(Req) ->
|
|||||||
%% @private Формирует JSON-представление записи #booking{}.
|
%% @private Формирует JSON-представление записи #booking{}.
|
||||||
-spec booking_to_json(#booking{}) -> map().
|
-spec booking_to_json(#booking{}) -> map().
|
||||||
booking_to_json(Booking) ->
|
booking_to_json(Booking) ->
|
||||||
#{
|
handler_utils:booking_to_json(Booking).
|
||||||
id => Booking#booking.id,
|
|
||||||
event_id => Booking#booking.event_id,
|
|
||||||
user_id => Booking#booking.user_id,
|
|
||||||
status => Booking#booking.status,
|
|
||||||
notes => Booking#booking.notes,
|
|
||||||
reminder_sent => Booking#booking.reminder_sent,
|
|
||||||
confirmed_at => case Booking#booking.confirmed_at of
|
|
||||||
undefined -> null;
|
|
||||||
Dt -> handler_utils:datetime_to_iso8601(Dt)
|
|
||||||
end,
|
|
||||||
created_at => handler_utils:datetime_to_iso8601(Booking#booking.created_at),
|
|
||||||
updated_at => handler_utils:datetime_to_iso8601(Booking#booking.updated_at)
|
|
||||||
}.
|
|
||||||
Regular → Executable
+1
-14
@@ -89,17 +89,4 @@ list_user_bookings(Req) ->
|
|||||||
%% @private Формирует JSON-представление записи #booking{}.
|
%% @private Формирует JSON-представление записи #booking{}.
|
||||||
-spec booking_to_json(#booking{}) -> map().
|
-spec booking_to_json(#booking{}) -> map().
|
||||||
booking_to_json(Booking) ->
|
booking_to_json(Booking) ->
|
||||||
#{
|
handler_utils:booking_to_json(Booking).
|
||||||
id => Booking#booking.id,
|
|
||||||
event_id => Booking#booking.event_id,
|
|
||||||
user_id => Booking#booking.user_id,
|
|
||||||
status => Booking#booking.status,
|
|
||||||
notes => Booking#booking.notes,
|
|
||||||
reminder_sent => Booking#booking.reminder_sent,
|
|
||||||
confirmed_at => case Booking#booking.confirmed_at of
|
|
||||||
undefined -> null;
|
|
||||||
Dt -> handler_utils:datetime_to_iso8601(Dt)
|
|
||||||
end,
|
|
||||||
created_at => handler_utils:datetime_to_iso8601(Booking#booking.created_at),
|
|
||||||
updated_at => handler_utils:datetime_to_iso8601(Booking#booking.updated_at)
|
|
||||||
}.
|
|
||||||
@@ -26,6 +26,7 @@
|
|||||||
ticket_to_json/1,
|
ticket_to_json/1,
|
||||||
calendar_to_json/1,
|
calendar_to_json/1,
|
||||||
subscription_to_json/1,
|
subscription_to_json/1,
|
||||||
|
booking_to_json/1,
|
||||||
trails_for_crud/4,
|
trails_for_crud/4,
|
||||||
is_superadmin/1,
|
is_superadmin/1,
|
||||||
pagination_headers/2,
|
pagination_headers/2,
|
||||||
@@ -473,6 +474,44 @@ subscription_to_json(Subscription) ->
|
|||||||
updated_at => datetime_to_iso8601(Subscription#subscription.updated_at)
|
updated_at => datetime_to_iso8601(Subscription#subscription.updated_at)
|
||||||
}.
|
}.
|
||||||
|
|
||||||
|
%% @doc Booking JSON with optional booker nickname/email for owner UI.
|
||||||
|
-spec booking_to_json(#booking{}) -> map().
|
||||||
|
booking_to_json(Booking) ->
|
||||||
|
Base = #{
|
||||||
|
id => Booking#booking.id,
|
||||||
|
event_id => Booking#booking.event_id,
|
||||||
|
user_id => Booking#booking.user_id,
|
||||||
|
status => Booking#booking.status,
|
||||||
|
notes => Booking#booking.notes,
|
||||||
|
reminder_sent => Booking#booking.reminder_sent,
|
||||||
|
confirmed_at => case Booking#booking.confirmed_at of
|
||||||
|
undefined -> null;
|
||||||
|
Dt -> datetime_to_iso8601(Dt)
|
||||||
|
end,
|
||||||
|
created_at => datetime_to_iso8601(Booking#booking.created_at),
|
||||||
|
updated_at => datetime_to_iso8601(Booking#booking.updated_at)
|
||||||
|
},
|
||||||
|
maps:merge(Base, booking_user_fields(Booking#booking.user_id)).
|
||||||
|
|
||||||
|
%% @private
|
||||||
|
booking_user_fields(UserId) when is_binary(UserId) ->
|
||||||
|
case core_user:get_by_id(UserId) of
|
||||||
|
{ok, #user{nickname = Nick, email = Email}} ->
|
||||||
|
#{
|
||||||
|
user_nickname => empty_to_null(Nick),
|
||||||
|
user_email => empty_to_null(Email)
|
||||||
|
};
|
||||||
|
_ ->
|
||||||
|
#{user_nickname => null, user_email => null}
|
||||||
|
end;
|
||||||
|
booking_user_fields(_) ->
|
||||||
|
#{user_nickname => null, user_email => null}.
|
||||||
|
|
||||||
|
empty_to_null(undefined) -> null;
|
||||||
|
empty_to_null(null) -> null;
|
||||||
|
empty_to_null(<<>>) -> null;
|
||||||
|
empty_to_null(V) -> V.
|
||||||
|
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
%%% Вспомогательные внутренние функции
|
%%% Вспомогательные внутренние функции
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
|
|||||||
Reference in New Issue
Block a user