Update blueprint for availability endpoints

This commit is contained in:
Justin Edmund 2022-12-22 18:12:34 -08:00
parent 153d36be5a
commit e91e1664a6
2 changed files with 8 additions and 8 deletions

View file

@ -3,12 +3,12 @@
module Api module Api
module V1 module V1
class EmptyBlueprint < Blueprinter::Base class EmptyBlueprint < Blueprinter::Base
field :email_available, if: ->(_field_name, _empty, options) { options.key?(:email) } do |_, options| field :available, if: ->(_field_name, _empty, options) { options.key?(:availability) } do |_, options|
User.where('email = ?', options[:email]).count.zero? if options.key?(:email)
end User.where('email = ?', options[:email]).count.zero?
elsif options.key?(:username)
field :username_available, if: ->(_field_name, _empty, options) { options.key?(:username) } do |_, options| User.where('username = ?', options[:username]).count.zero?
User.where('username = ?', options[:username]).count.zero? end
end end
end end
end end

View file

@ -69,11 +69,11 @@ module Api
end end
def check_email def check_email
render json: EmptyBlueprint.render_as_json(nil, email: params[:email]) render json: EmptyBlueprint.render_as_json(nil, email: params[:email], availability: true)
end end
def check_username def check_username
render json: EmptyBlueprint.render_as_json(nil, username: params[:username]) render json: EmptyBlueprint.render_as_json(nil, username: params[:username], availability: true)
end end
def destroy; end def destroy; end