./ct_report/coverage/mongoose_graphql_roster_user_mutation.COVER.html

1 -module(mongoose_graphql_roster_user_mutation).
2 -behaviour(mongoose_graphql).
3
4 -export([execute/4]).
5
6 -ignore_xref([execute/4]).
7
8 -import(mongoose_graphql_helper, [make_error/2, format_result/2, null_to_default/2]).
9
10 execute(Ctx, _Obj, <<"addContact">>, Args) ->
11 9 add_contact(Ctx, Args);
12 execute(Ctx, _Obj, <<"addContacts">>, Args) ->
13 1 add_contacts(Ctx, Args);
14 execute(Ctx, _Obj, <<"subscription">>, Args) ->
15 5 subscription(Ctx, Args);
16 execute(Ctx, _Obj, <<"deleteContact">>, Args) ->
17 2 delete_contact(Ctx, Args);
18 execute(Ctx, _Obj, <<"deleteContacts">>, Args) ->
19 1 delete_contacts(Ctx, Args).
20
21 -spec add_contact(mongoose_graphql:context(), mongoose_graphql:args()) ->
22 mongoose_graphql_roster:binary_result().
23 add_contact(#{user := UserJID}, #{<<"contact">> := ContactJID,
24 <<"name">> := Name,
25 <<"groups">> := Groups}) ->
26 9 mongoose_graphql_roster:add_contact(UserJID, ContactJID, Name, Groups).
27
28 -spec add_contacts(mongoose_graphql:context(), mongoose_graphql:args()) ->
29 mongoose_graphql_roster:list_binary_result().
30 add_contacts(#{user := UserJID}, #{<<"contacts">> := Contacts}) ->
31 1 {ok, [mongoose_graphql_roster:add_contact(UserJID, ContactJID, Name, Groups)
32 1 || #{<<"jid">> := ContactJID, <<"name">> := Name, <<"groups">> := Groups} <- Contacts]}.
33
34 -spec subscription(mongoose_graphql:context(), mongoose_graphql:args()) ->
35 mongoose_graphql_roster:binary_result().
36 subscription(#{user := UserJID}, #{<<"contact">> := ContactJID, <<"action">> := Action}) ->
37 5 Type = mongoose_graphql_roster:translate_sub_action(Action),
38 5 Res = mod_roster_api:subscription(UserJID, ContactJID, Type),
39 5 format_result(Res, #{contact => jid:to_binary(ContactJID)}).
40
41 -spec delete_contact(mongoose_graphql:context(), mongoose_graphql:args()) ->
42 mongoose_graphql_roster:binary_result().
43 delete_contact(#{user := UserJID}, #{<<"contact">> := ContactJID}) ->
44 2 mongoose_graphql_roster:delete_contact(UserJID, ContactJID).
45
46 -spec delete_contacts(mongoose_graphql:context(), mongoose_graphql:args()) ->
47 mongoose_graphql_roster:list_binary_result().
48 delete_contacts(#{user := UserJID}, #{<<"contacts">> := ContactJIDs}) ->
49 1 {ok, [mongoose_graphql_roster:delete_contact(UserJID, ContactJID)
50 1 || ContactJID <- ContactJIDs]}.
Line Hits Source