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.

37 lines
881 B

  1. package mutations
  2. import (
  3. "context"
  4. "git.aiterp.net/rpdata/api/graphql/resolver/types"
  5. "git.aiterp.net/rpdata/api/internal/auth"
  6. "git.aiterp.net/rpdata/api/model/change"
  7. "git.aiterp.net/rpdata/api/model/channel"
  8. )
  9. // RemoveChannelArgs is args for removeChannels mutation
  10. type RemoveChannelArgs struct {
  11. Name string
  12. }
  13. // RemoveChannel resolves the editChannel mutation
  14. func (r *MutationResolver) RemoveChannel(ctx context.Context, args RemoveChannelArgs) (*types.ChannelResolver, error) {
  15. token := auth.TokenFromContext(ctx)
  16. if !token.Permitted("channel.remove") {
  17. return nil, ErrUnauthorized
  18. }
  19. channel, err := channel.FindName(args.Name)
  20. if err != nil {
  21. return nil, err
  22. }
  23. err = channel.Remove()
  24. if err != nil {
  25. return nil, err
  26. }
  27. go change.Submit("Channel", "remove", token.UserID, channel.Name, nil)
  28. return &types.ChannelResolver{C: channel}, nil
  29. }