cats_core 1.1.20 → 1.1.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a82354115851db50157d1387858c1b10b65c84fcbf4b78b80f7cbc51e308b6c1
4
- data.tar.gz: 9810991a8731b4850e3950f1ba0245c49101b65adbb7f5ffc7ec8e7db6fb7cf4
3
+ metadata.gz: 106712bfb38bd512ae9d06d20301aa81a5a199bb6522728cddcf6c1d688fe444
4
+ data.tar.gz: 80cf7130c7cbbb47bcf4120c021e54aa2e9eb7bf5578260664339a6cbca18e78
5
5
  SHA512:
6
- metadata.gz: 75344722c714a1ab8d5b2c82ba808977f88aa141fe83e03520e92d4ccde316819932110693ac78d0523ce78e2f69417e9cb44e54b12045fc4f66870b6ccfa281
7
- data.tar.gz: 855c87c77fa0c3517e72dc87930c959f86204ef52c46a800d53d67e2adcdd0bdd9a62251355a334707f9e0bd9f26910cde0fe895a75e69d0d7bd910fc345c77a
6
+ metadata.gz: 1741bedb659f842852f836dd020c79f45d4ec901f8e076be97007c06fec9a69cb5793ac7612a46b08e9fd06b92b6892bebb2baa39cb0d49b1a48bffba9c93f48
7
+ data.tar.gz: 7fb859382f5faf676437e39cdb7f64c0201a47bb7b9409dd4d41a8ec5e30d13713415f21a04a2b8e2c7fd40c0315c800d1dd64d5277ea846ff279357486a9a4f
@@ -3,7 +3,7 @@ module Cats
3
3
  class UsersController < ApplicationController
4
4
  include Common
5
5
 
6
- before_action :set_user, only: %i[roles assign_role stores warehouse hub]
6
+ before_action :set_user, only: %i[update roles assign_role stores warehouse hub]
7
7
 
8
8
  def index
9
9
  users = Cats::Core::User.joins(:application_module)
@@ -11,6 +11,36 @@ module Cats
11
11
  render json: { success: true, data: serialize(users) }
12
12
  end
13
13
 
14
+ def create
15
+ prefix = model_params[:application_prefix]
16
+ application_module = Cats::Core::ApplicationModule.find_by(prefix: prefix)
17
+
18
+ obj = Cats::Core::User.new(model_params.except(:application_prefix))
19
+ obj.application_module = application_module
20
+ if obj.save
21
+ render json: { success: true, data: serialize(obj) }, status: :created
22
+ else
23
+ render json: { success: false, error: obj.errors.full_messages[0] }, status: :unprocessable_entity
24
+ end
25
+ end
26
+
27
+ def update
28
+ if model_params[:application_prefix]
29
+ prefix = model_params[:application_prefix]
30
+ application_module = Cats::Core::ApplicationModule.find_by(prefix: prefix)
31
+ @user.assign_attributes(model_params.except(:application_prefix))
32
+ @user.application_module = application_module
33
+ else
34
+ @user.assign_attributes(model_params)
35
+ end
36
+
37
+ if @user.save
38
+ render json: { success: true, data: serialize(@user) }
39
+ else
40
+ render json: { success: false, error: @user.errors.full_messages[0] }, status: :unprocessable_entity
41
+ end
42
+ end
43
+
14
44
  def roles
15
45
  data = ActiveModelSerializers::SerializableResource.new(@user.roles)
16
46
  render json: { success: true, data: data }
@@ -47,7 +77,7 @@ module Cats
47
77
  def model_params
48
78
  params.require(:payload).permit(
49
79
  :first_name, :last_name, :email, :phone_number, :active, :password, :password_confirmation, :details,
50
- :application_module_id
80
+ :application_prefix
51
81
  )
52
82
  end
53
83
  end
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.1.20'.freeze
3
+ VERSION = '1.1.21'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cats_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.20
4
+ version: 1.1.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henock L.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-04 00:00:00.000000000 Z
11
+ date: 2021-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers