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
811 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/log"
  8. )
  9. // RemoveLogArgs is args for the removeLog mutation
  10. type RemoveLogArgs struct {
  11. ID string
  12. }
  13. // RemoveLog resolves the removeLog mutation
  14. func (r *MutationResolver) RemoveLog(ctx context.Context, args *RemoveLogArgs) (*types.LogResolver, error) {
  15. token := auth.TokenFromContext(ctx)
  16. if !token.Permitted("log.remove") {
  17. return nil, ErrUnauthorized
  18. }
  19. log, err := log.FindID(args.ID)
  20. if err != nil {
  21. return nil, err
  22. }
  23. err = log.Remove()
  24. if err != nil {
  25. return nil, err
  26. }
  27. go change.Submit("Log", "remove", token.UserID, log.ID, nil)
  28. return &types.LogResolver{L: log}, nil
  29. }