generated from matoszz/mitbgo-template
-
Notifications
You must be signed in to change notification settings - Fork 7
/
groupextended.resolvers.go
88 lines (68 loc) · 2.37 KB
/
groupextended.resolvers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package graphapi
// This file will be automatically regenerated based on the schema, any resolver implementations
// will be copied through when generating and any unknown code will be moved to the end.
// Code generated by github.com/99designs/gqlgen
import (
"context"
"github.com/99designs/gqlgen/graphql"
"github.com/datumforge/datum/internal/ent/generated"
)
// CreateGroupSettings is the resolver for the createGroupSettings field.
func (r *createGroupInputResolver) CreateGroupSettings(ctx context.Context, obj *generated.CreateGroupInput, data *generated.CreateGroupSettingInput) error {
c := withTransactionalMutation(ctx)
groupSettings, err := c.GroupSetting.Create().SetInput(*data).Save(ctx)
if err != nil {
return err
}
obj.SettingID = groupSettings.ID
return nil
}
// AddGroupMembers is the resolver for the addGroupMembers field.
func (r *updateGroupInputResolver) AddGroupMembers(ctx context.Context, obj *generated.UpdateGroupInput, data []*generated.CreateGroupMembershipInput) error {
opCtx := graphql.GetOperationContext(ctx)
groupID, ok := opCtx.Variables["updateGroupId"]
if !ok {
r.logger.Errorw("unable to get group from context")
return ErrInternalServerError
}
c := withTransactionalMutation(ctx)
builders := make([]*generated.GroupMembershipCreate, len(data))
for i := range data {
input := *data[i]
input.GroupID = groupID.(string)
builders[i] = c.GroupMembership.Create().SetInput(input)
}
_, err := c.GroupMembership.CreateBulk(builders...).Save(ctx)
if err != nil {
return err
}
return nil
}
// UpdateGroupSettings is the resolver for the updateGroupSettings field.
func (r *updateGroupInputResolver) UpdateGroupSettings(ctx context.Context, obj *generated.UpdateGroupInput, data *generated.UpdateGroupSettingInput) error {
opCtx := graphql.GetOperationContext(ctx)
groupID, ok := opCtx.Variables["updateGroupId"]
if !ok {
r.logger.Errorw("unable to get group from context")
return ErrInternalServerError
}
c := withTransactionalMutation(ctx)
// get setting ID to update
settingID := obj.SettingID
if settingID == nil {
group, err := c.Group.Get(ctx, groupID.(string))
if err != nil {
return err
}
setting, err := group.Setting(ctx)
if err != nil {
return err
}
settingID = &setting.ID
}
_, err := c.GroupSetting.UpdateOneID(*settingID).SetInput(*data).Save(ctx)
if err != nil {
return err
}
return nil
}