package mutations import ( "context" "git.aiterp.net/rpdata/api/graphql/resolver/types" "git.aiterp.net/rpdata/api/internal/session" "git.aiterp.net/rpdata/api/model/change" "git.aiterp.net/rpdata/api/model/log" ) // LogEditArgs is args for the editLog mutation type LogEditArgs struct { Input *struct { ID string Title *string Event *string Description *string Open *bool } } // EditLog resolves the editLog mutation func (r *MutationResolver) EditLog(ctx context.Context, args *LogEditArgs) (*types.LogResolver, error) { input := args.Input user := session.FromContext(ctx).User() if user == nil || !user.Permitted("log.edit") { return nil, ErrUnauthorized } log, err := log.FindID(input.ID) if err != nil { return nil, err } err = log.Edit(input.Title, input.Event, input.Description, input.Open) if err != nil { return nil, err } go change.Submit("Log", "edit", user.ID, log.ID, map[string]interface{}{ "channel": log.Channel, "title": input.Title, "event": input.Event, "description": input.Description, "open": input.Open, }) return &types.LogResolver{L: log}, nil }