GraphQL API and utilities for the rpdata project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.2 KiB

  1. package mutations
  2. import (
  3. "context"
  4. "git.aiterp.net/rpdata/api/graphql/resolver/types"
  5. "git.aiterp.net/rpdata/api/internal/session"
  6. "git.aiterp.net/rpdata/api/model/change"
  7. "git.aiterp.net/rpdata/api/model/channel"
  8. )
  9. // ChannelEditArgs is input for the editChannel mutation
  10. type ChannelEditArgs struct {
  11. Input *struct {
  12. Name string
  13. Logged *bool
  14. Hub *bool
  15. EventName *string
  16. LocationName *string
  17. }
  18. }
  19. // EditChannel resolves the editChannel mutation
  20. func (r *MutationResolver) EditChannel(ctx context.Context, args *ChannelEditArgs) (*types.ChannelResolver, error) {
  21. input := args.Input
  22. user := session.FromContext(ctx).User()
  23. if user == nil || !user.Permitted("channel.edit") {
  24. return nil, ErrUnauthorized
  25. }
  26. channel, err := channel.FindName(input.Name)
  27. if err != nil {
  28. return nil, err
  29. }
  30. err = channel.Edit(input.Logged, input.Hub, input.EventName, input.LocationName)
  31. if err != nil {
  32. return nil, err
  33. }
  34. go change.Submit("Channel", "edit", user.ID, channel.Name, map[string]interface{}{
  35. "logged": input.Logged,
  36. "hub": input.Hub,
  37. "location": input.LocationName,
  38. "event": input.EventName,
  39. })
  40. return &types.ChannelResolver{C: channel}, nil
  41. }