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,13 +3,13 @@
module Api
module V1
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|
if options.key?(:email)
User.where('email = ?', options[:email]).count.zero?
end
field :username_available, if: ->(_field_name, _empty, options) { options.key?(:username) } do |_, options|
elsif options.key?(:username)
User.where('username = ?', options[:username]).count.zero?
end
end
end
end
end

View file

@ -69,11 +69,11 @@ module Api
end
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
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
def destroy; end