Created
April 26, 2019 15:17
-
-
Save farhanrahmadi/a65b0d7a01cc6a4336f56b6a0f7799aa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create | |
begin | |
@merchant = Merchant.find_by!(:username => params[:username]) | |
if @merchant | |
render json: {error: 'duplicate', message: "Username anda sudah terdaftar"}, status: :unprocessable_entity | |
end | |
rescue Mongoid::Errors::DocumentNotFound | |
@merchant = Merchant.new() | |
@merchant.name = params[:name] | |
@merchant.username = params[:username] | |
@merchant.password = params[:password] | |
@merchant.password_confirmation = params[:password_confirmation] | |
@merchant.phone_number = params[:phone_number] | |
@merchant.max_waiting_time = params[:max_waiting_time] | |
@merchant.open_hour = Time.parse(params[:open_hour]) | |
@merchant.close_hour = Time.parse(params[:close_hour]) | |
@merchant.address = params[:address] | |
@merchant.location = {:lng => params[:lng].to_f, :lat => params[:lat].to_f} | |
@merchant.banner_image = params[:banner_image] | |
@merchant.profile_image = params[:profile_image] | |
@merchant.menu_type = params[:menu_type].to_a | |
@merchant.user = @user | |
puts @merchant.location | |
if @merchant.save | |
render json: @merchant | |
else | |
render json: {errors: @merchant.errors.full_messages}, | |
status: :unprocessable_entity | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment