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/character" ) // RemoveCharacterArgs is args for the removeCharacter mutation type RemoveCharacterArgs struct { ID string } // RemoveCharacter resolves the removeCharacter mutation func (r *MutationResolver) RemoveCharacter(ctx context.Context, args RemoveCharacterArgs) (*types.CharacterResolver, error) { token := auth.TokenFromContext(ctx) if !token.Permitted("member") { return nil, ErrUnauthorized } character, err := character.FindID(args.ID) if err != nil { return nil, err } if character.Author != token.UserID && !token.Permitted("character.remove") { return nil, ErrPermissionDenied } err = character.Remove() if err != nil { return nil, err } go change.Submit("Character", "remove", token.UserID, character.ID, map[string]interface{}{ "name": character.Name, "author": character.Author, "nicks": character.Nicks, }) return &types.CharacterResolver{C: character}, nil }