blob: da1844866641c9aab58ad955bed1c82664a733bf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# frozen_string_literal: true
module Api
# The UserAccounts controller.
class UserAccountsController < AuthenticatedController
skip_before_action :validate_jwt, only: [:create]
def show
render json: serialized_object.serializable_hash
end
def create
@user_account = UserAccount.new(permitted_params.merge(role: 'regular'))
if @user_account.save
render json: generate_token, status: :ok
@user_account.update(cart_id: Cart.create(user_account_id: @user_account.id).id)
return
end
render json: { errors: @user_account.errors.as_json }, status: :unprocessable_entity
end
def update
if current_user_account.update(permitted_params)
render json: serialized_object.serializable_hash, status: :ok
else
render json: { errors: current_user_account.errors.as_json }, status: :unprocessable_entity
end
end
private
def serialized_object
UserAccountSerializer.new(current_user_account)
end
def service_params
{ email: @user_account.email,
role: @user_account.role }
end
def permitted_params
params.permit(:email, :first_name, :last_name, :password)
end
end
end
|