Избавление от undefined, всем необязательным полям присваиваются дефолтные значения #22
This commit is contained in:
@@ -101,8 +101,12 @@ update_report(Req) ->
|
||||
ReportId = cowboy_req:binding(id, Req1),
|
||||
{ok, Body, Req2} = cowboy_req:read_body(Req1),
|
||||
try jsx:decode(Body, [return_maps]) of
|
||||
#{<<"status">> := Status} ->
|
||||
case logic_report:update_report_status(AdminId, ReportId, Status) of
|
||||
#{<<"status">> := StatusBin} ->
|
||||
% Преобразуем бинарный статус в атом
|
||||
StatusAtom = try binary_to_existing_atom(StatusBin, utf8)
|
||||
catch _:_ -> StatusBin
|
||||
end,
|
||||
case logic_report:update_report_status(AdminId, ReportId, StatusAtom) of
|
||||
{ok, Report} ->
|
||||
% Аудит изменения статуса жалобы
|
||||
admin_utils:log_admin_action(AdminId, <<"update_report_status">>, <<"report">>, ReportId, Req2),
|
||||
|
||||
@@ -1,8 +1,3 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% @doc Административный обработчик списка жалоб.
|
||||
%%% GET – список с пагинацией, фильтрацией и сортировкой.
|
||||
%%% @end
|
||||
%%%-------------------------------------------------------------------
|
||||
-module(admin_handler_reports).
|
||||
-behaviour(cowboy_handler).
|
||||
-export([init/2]).
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
-include("records.hrl").
|
||||
|
||||
%%% cowboy_handler callback
|
||||
-spec init(cowboy_req:req(), any()) -> {ok, cowboy_req:req(), any()}.
|
||||
init(Req, _Opts) ->
|
||||
case cowboy_req:method(Req) of
|
||||
@@ -84,12 +83,13 @@ ticket_update_schema() ->
|
||||
list_tickets(Req) ->
|
||||
case handler_utils:auth_admin(Req) of
|
||||
{ok, AdminId, Req1} ->
|
||||
Qs = cowboy_req:parse_qs(Req1),
|
||||
Filters = parse_ticket_filters(Req1),
|
||||
Pagination0 = handler_utils:parse_pagination_params(Req1),
|
||||
Pagination = Pagination0#{
|
||||
sort => maps:get(sort, Pagination0, <<"first_seen">>),
|
||||
order => maps:get(order, Pagination0, <<"desc">>)
|
||||
},
|
||||
% Явно извлекаем sort и order с нормализацией регистра
|
||||
SortBy = proplists:get_value(<<"sort">>, Qs, <<"first_seen">>),
|
||||
SortOrder = proplists:get_value(<<"order">>, Qs, <<"desc">>),
|
||||
Pagination = Pagination0#{sort => SortBy, order => SortOrder},
|
||||
TicketsResult = case maps:get(status, Filters, undefined) of
|
||||
undefined -> logic_ticket:list_tickets(AdminId);
|
||||
StatusBin ->
|
||||
@@ -173,7 +173,7 @@ sort_tickets(Tickets, #{sort := Sort, order := Order}) ->
|
||||
|
||||
ticket_field(#ticket{first_seen = V}, first_seen) -> V;
|
||||
ticket_field(#ticket{last_seen = V}, last_seen) -> V;
|
||||
ticket_field(#ticket{status = V}, status) -> V;
|
||||
ticket_field(#ticket{status = V}, status) -> atom_to_binary(V, utf8);
|
||||
ticket_field(_, _) -> undefined.
|
||||
|
||||
apply_ticket_changes(AdminId, TicketId, Data) ->
|
||||
|
||||
@@ -162,7 +162,7 @@ cancel_booking(Req) ->
|
||||
case handler_utils:auth_user(Req) of
|
||||
{ok, UserId, Req1} ->
|
||||
BookingId = cowboy_req:binding(id, Req1),
|
||||
case logic_booking:cancel_booking(UserId, BookingId) of
|
||||
case logic_booking:cancel_booking(BookingId, UserId) of
|
||||
{ok, Booking} ->
|
||||
handler_utils:send_json(Req1, 200, booking_to_json(Booking));
|
||||
{error, access_denied} ->
|
||||
|
||||
Reference in New Issue
Block a user