./ct_report/coverage/mongoose_graphql_token_admin_mutation.COVER.html

1 -module(mongoose_graphql_token_admin_mutation).
2 -behaviour(mongoose_graphql).
3
4 -export([execute/4]).
5
6 -ignore_xref([execute/4]).
7
8 -include("../mongoose_graphql_types.hrl").
9
10 -import(mongoose_graphql_helper, [make_error/2]).
11
12 -type token_info() :: map().
13
14 execute(_Ctx, token, <<"requestToken">>, #{<<"user">> := JID}) ->
15 14 request_token(JID);
16 execute(_Ctx, token, <<"revokeToken">>, #{<<"user">> := JID}) ->
17 11 revoke_token(JID).
18
19 -spec request_token(jid:jid()) -> {ok, token_info()} | {error, resolver_error()}.
20 request_token(JID) ->
21 14 case mod_auth_token_api:create_token(JID) of
22 12 {ok, _} = Result -> Result;
23 2 Error -> make_error(Error, #{user => JID})
24 end.
25
26 -spec revoke_token(jid:jid()) -> {ok, string()} | {error, resolver_error()}.
27 revoke_token(JID) ->
28 11 case mod_auth_token_api:revoke_token_command(JID) of
29 6 {ok, _} = Result -> Result;
30 5 Error -> make_error(Error, #{user => JID})
31 end.
Line Hits Source