fix: persist specialist_id on event create; 402 commercial without active sub. Fixes EventHub/EventHubBack#61
This commit is contained in:
@@ -140,6 +140,7 @@ event_create_schema() ->
|
||||
lon => #{type => number, format => float}
|
||||
}
|
||||
},
|
||||
specialist_id => #{type => string, nullable => true},
|
||||
recurrence => #{type => object, description => <<"Recurrence rule (RFC 5545)">>}
|
||||
}
|
||||
}.
|
||||
@@ -176,10 +177,7 @@ create_event(Req) ->
|
||||
undefined ->
|
||||
case logic_event:create_event(UserId, CalendarId, Title, StartTime, Duration, Description) of
|
||||
{ok, Event} ->
|
||||
update_event_fields(UserId, Event#event.id, Location, Decoded),
|
||||
{ok, UpdatedEvent} = core_event:get_by_id(Event#event.id),
|
||||
Response = handler_utils:event_to_json(UpdatedEvent),
|
||||
handler_utils:send_json(Req2, 201, Response);
|
||||
finish_create_event(Req2, UserId, Event, Location, Decoded);
|
||||
{error, access_denied} ->
|
||||
handler_utils:send_error(Req2, 403, <<"Access denied">>);
|
||||
{error, not_found} ->
|
||||
@@ -194,10 +192,7 @@ create_event(Req) ->
|
||||
RRule ->
|
||||
case logic_event:create_recurring_event(UserId, CalendarId, Title, StartTime, Duration, RRule, Description) of
|
||||
{ok, Event} ->
|
||||
update_event_fields(UserId, Event#event.id, Location, Decoded),
|
||||
{ok, UpdatedEvent} = core_event:get_by_id(Event#event.id),
|
||||
Response = handler_utils:event_to_json(UpdatedEvent),
|
||||
handler_utils:send_json(Req2, 201, Response);
|
||||
finish_create_event(Req2, UserId, Event, Location, Decoded);
|
||||
{error, invalid_rrule} ->
|
||||
handler_utils:send_error(Req2, 400, <<"Invalid recurrence rule">>);
|
||||
{error, access_denied} ->
|
||||
@@ -262,6 +257,21 @@ list_events(Req) ->
|
||||
%%% Вспомогательные функции
|
||||
%%%===================================================================
|
||||
|
||||
finish_create_event(Req, UserId, Event, Location, Decoded) ->
|
||||
case update_event_fields(UserId, Event#event.id, Location, Decoded) of
|
||||
ok ->
|
||||
{ok, UpdatedEvent} = core_event:get_by_id(Event#event.id),
|
||||
Response = handler_utils:event_to_json(UpdatedEvent),
|
||||
handler_utils:send_json(Req, 201, Response);
|
||||
{error, invalid_specialist} ->
|
||||
_ = logic_event:delete_event(UserId, Event#event.id),
|
||||
handler_utils:send_error(Req, 400, <<"Invalid specialist_id for this calendar">>);
|
||||
{error, _} ->
|
||||
{ok, UpdatedEvent} = core_event:get_by_id(Event#event.id),
|
||||
Response = handler_utils:event_to_json(UpdatedEvent),
|
||||
handler_utils:send_json(Req, 201, Response)
|
||||
end.
|
||||
|
||||
update_event_fields(UserId, EventId, Location, Decoded) ->
|
||||
Updates = [],
|
||||
Updates1 = case Location of undefined -> Updates; _ -> [{location, Location} | Updates] end,
|
||||
@@ -269,12 +279,18 @@ update_event_fields(UserId, EventId, Location, Decoded) ->
|
||||
Updates3 = case maps:get(<<"tags">>, Decoded, undefined) of undefined -> Updates2; Tags -> [{tags, Tags} | Updates2] end,
|
||||
%% description already applied in create_event/6 when present
|
||||
Updates4 = case maps:get(<<"online_link">>, Decoded, undefined) of undefined -> Updates3; Link -> [{online_link, Link} | Updates3] end,
|
||||
case Updates4 of
|
||||
Updates5 = case maps:get(<<"specialist_id">>, Decoded, undefined) of
|
||||
undefined -> Updates4;
|
||||
null -> [{specialist_id, <<>>} | Updates4];
|
||||
SpecId when is_binary(SpecId) -> [{specialist_id, SpecId} | Updates4];
|
||||
_ -> Updates4
|
||||
end,
|
||||
case Updates5 of
|
||||
[] -> ok;
|
||||
_ ->
|
||||
case logic_event:update_event(UserId, EventId, Updates4) of
|
||||
case logic_event:update_event(UserId, EventId, Updates5) of
|
||||
{ok, _} -> ok;
|
||||
_ -> ok
|
||||
{error, _} = Err -> Err
|
||||
end
|
||||
end.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user