cypriss / mutations

Compose your business logic into commands that sanitize and validate input.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

nils:false not working on optional integer

omarsotillo opened this issue · comments

I want the user to be able to provide nil into a optional field (see product_id and mailjet_template_id)

# frozen_string_literal: true

module Admin
  module Commands
    module EmailConfigurations
      class Update < Mutations::Command
        required do
          integer :id
        end

        optional do
          integer :product_id
          integer :mailjet_template_id
          integer :experiment_id, nils: true
          integer :variant_id, nils: true
        end

        def execute
          Admin::Repositories::EmailConfigurations.update(id, inputs.except(:id))
        end
      end
    end
  end
end

When I pass {:id=>1383, :product_id=>nil, :experiment_id=>1, :variant_id=>1, :mailjet_template_id=>1} the result is succesfull. The nils true part works fine and is not giving errors.

Is this an intended approach? Also moving them to required and allowing nils does not work since we want to support the fields to not be provided in the request.

Closing this as I have noticed that it will automatically remove the input

#<Mutations::Outcome:0x0000557223479fd8 @success=true, @result=#<EmailConfiguration id: 1509, product_id: 100, experiment_id: 1, variant_id: 1, mailjet_template_id: 54, default: false, created_at: "2019-08-22 07:43:22", updated_at: "2019-08-22 07:43:22">, @errors=nil, @inputs={"id"=>1509, "product_id"=>100, "experiment_id"=>1, "variant_id"=>1}>