1 |
|
-module(mongoose_graphql_account_user_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, [format_result/2]). |
11 |
|
|
12 |
|
execute(Ctx, _Obj, <<"unregister">>, _Args) -> |
13 |
1 |
unregister_user(Ctx); |
14 |
|
execute(Ctx, _Obj, <<"changePassword">>, Args) -> |
15 |
2 |
change_user_password(Ctx, Args). |
16 |
|
|
17 |
|
%% Internal |
18 |
|
|
19 |
|
-spec unregister_user(map()) -> {ok, binary()} | {error, resolver_error()}. |
20 |
|
unregister_user(#{user := JID}) -> |
21 |
1 |
Result = mongoose_account_api:unregister_user(JID), |
22 |
1 |
format_result(Result, #{}). |
23 |
|
|
24 |
|
-spec change_user_password(map(), map()) -> {ok, binary()} | {error, resolver_error()}. |
25 |
|
change_user_password(#{user := JID}, #{<<"newPassword">> := Password}) -> |
26 |
2 |
Result = mongoose_account_api:change_password(JID, Password), |
27 |
2 |
format_result(Result, #{}). |