package mutations import ( "context" "git.aiterp.net/rpdata/api/graphql/resolver/types" "git.aiterp.net/rpdata/api/internal/auth" "git.aiterp.net/rpdata/api/model/change" "git.aiterp.net/rpdata/api/model/story" ) // RemoveChapterArgs is args for the addChapter mutation type RemoveChapterArgs struct { ID string } // RemoveChapter resolves the removeChapter mutation func (r *MutationResolver) RemoveChapter(ctx context.Context, args *RemoveChapterArgs) (*types.ChapterResolver, error) { token := auth.TokenFromContext(ctx) if !token.Permitted("member", "chapter.edit") { return nil, ErrUnauthorized } chapter, err := story.FindChapterID(args.ID) if err != nil { return nil, err } err = chapter.Remove() if err != nil { return nil, err } go change.Submit("Chapter", "remove", token.UserID, chapter.ID, nil) return &types.ChapterResolver{C: chapter}, nil }