1 |
|
-module(mongoose_graphql_account_user_mutation). |
2 |
|
|
3 |
|
-export([execute/4]). |
4 |
|
|
5 |
|
-ignore_xref([execute/4]). |
6 |
|
|
7 |
|
-include("../mongoose_graphql_types.hrl"). |
8 |
|
|
9 |
|
-import(mongoose_graphql_account_helper, [format_result/2]). |
10 |
|
|
11 |
|
execute(Ctx, _Obj, <<"unregister">>, _Args) -> |
12 |
1 |
unregister_user(Ctx); |
13 |
|
execute(Ctx, _Obj, <<"changePassword">>, Args) -> |
14 |
2 |
change_user_password(Ctx, Args). |
15 |
|
|
16 |
|
%% Internal |
17 |
|
|
18 |
|
-spec unregister_user(map()) -> {ok, binary()} | {error, resolver_error()}. |
19 |
|
unregister_user(#{user := JID}) -> |
20 |
1 |
Result = mongoose_account_api:unregister_user(JID), |
21 |
1 |
format_result(Result, #{}). |
22 |
|
|
23 |
|
-spec change_user_password(map(), map()) -> {ok, binary()} | {error, resolver_error()}. |
24 |
|
change_user_password(#{user := JID}, #{<<"newPassword">> := Password}) -> |
25 |
2 |
Result = mongoose_account_api:change_password(JID, Password), |
26 |
2 |
format_result(Result, #{}). |