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.

51 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/log"
  8. )
  9. // LogEditArgs is args for the editLog mutation
  10. type LogEditArgs struct {
  11. Input *struct {
  12. ID string
  13. Title *string
  14. Event *string
  15. Description *string
  16. Open *bool
  17. }
  18. }
  19. // EditLog resolves the editLog mutation
  20. func (r *MutationResolver) EditLog(ctx context.Context, args *LogEditArgs) (*types.LogResolver, error) {
  21. input := args.Input
  22. user := session.FromContext(ctx).User()
  23. if user == nil || !user.Permitted("log.edit") {
  24. return nil, ErrUnauthorized
  25. }
  26. log, err := log.FindID(input.ID)
  27. if err != nil {
  28. return nil, err
  29. }
  30. err = log.Edit(input.Title, input.Event, input.Description, input.Open)
  31. if err != nil {
  32. return nil, err
  33. }
  34. go change.Submit("Log", "edit", user.ID, log.ID, map[string]interface{}{
  35. "channel": log.Channel,
  36. "title": input.Title,
  37. "event": input.Event,
  38. "description": input.Description,
  39. "open": input.Open,
  40. })
  41. return &types.LogResolver{L: log}, nil
  42. }