blob: ad276b5b044a7a2ed7d5bd4db1b5ebbbb504f62f (
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
|
# 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'))
render json: generate_token, status: :ok and return if @user_account.save
render json: @user_account.errors.full_messages, status: :unprocessable_entity
end
def update
if current_user_account.update(permitted_params)
render json: serialized_object.serializable_hash, status: :ok
else
render json: current_user_account.errors.full_messages, 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
|