1 |
|
-module(mongoose_graphql_session_user_query). |
2 |
|
-behaviour(mongoose_graphql). |
3 |
|
|
4 |
|
-export([execute/4]). |
5 |
|
|
6 |
|
-ignore_xref([execute/4]). |
7 |
|
|
8 |
|
execute(Ctx, _Obj, <<"listResources">>, Args) -> |
9 |
1 |
list_resources(Ctx, Args); |
10 |
|
execute(Ctx, _Obj, <<"countResources">>, Args) -> |
11 |
1 |
count_resources(Ctx, Args); |
12 |
|
execute(Ctx, _Obj, <<"listSessions">>, Args) -> |
13 |
1 |
list_sessions_info(Ctx, Args). |
14 |
|
|
15 |
|
-spec list_resources(map(), map()) -> {ok, [jid:lresource()]}. |
16 |
|
list_resources(#{user := JID}, _Args) -> |
17 |
1 |
{ok, Resources} = mongoose_session_api:list_user_resources(JID), |
18 |
1 |
{ok, lists:map(fun(R) -> {ok, R} end, Resources)}. |
19 |
|
|
20 |
|
-spec count_resources(map(), map()) -> {ok, non_neg_integer()}. |
21 |
|
count_resources(#{user := JID}, _Args) -> |
22 |
1 |
{ok, Resources} = mongoose_session_api:list_user_resources(JID), |
23 |
1 |
{ok, length(Resources)}. |
24 |
|
|
25 |
|
-spec list_sessions_info(map(), map()) -> {ok, mongoose_graphql_session_helper:session_list()}. |
26 |
|
list_sessions_info(#{user := JID}, _Args) -> |
27 |
1 |
{ok, Sessions} = mongoose_session_api:list_user_sessions(JID), |
28 |
1 |
{ok, mongoose_graphql_session_helper:format_sessions(Sessions)}. |