mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-04-13 07:40:36 +08:00
Implement inventory column data type name mappings [SCI-2772]
This commit is contained in:
parent
5190ac7a08
commit
ed46115b3f
6 changed files with 31 additions and 21 deletions
app
controllers/api/v1
serializers/api/v1
config/initializers
spec/requests/api/v1
|
@ -84,9 +84,15 @@ module Api
|
||||||
'Wrong object type within parameters'
|
'Wrong object type within parameters'
|
||||||
end
|
end
|
||||||
params.require(:data).require(:attributes)
|
params.require(:data).require(:attributes)
|
||||||
params
|
new_params = params
|
||||||
.permit(data: { attributes: %i(name data_type) })[:data]
|
.permit(data: { attributes: %i(name data_type) })[:data]
|
||||||
.merge(created_by: @current_user)
|
.merge(created_by: @current_user)
|
||||||
|
if new_params[:attributes][:data_type].present?
|
||||||
|
new_params[:attributes][:data_type] =
|
||||||
|
Extends::API_REPOSITORY_DATA_TYPE_MAPPINGS
|
||||||
|
.key(new_params.dig(:attributes, :data_type))
|
||||||
|
end
|
||||||
|
new_params
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_inventory_column_params
|
def update_inventory_column_params
|
||||||
|
@ -94,7 +100,7 @@ module Api
|
||||||
raise ActionController::BadRequest,
|
raise ActionController::BadRequest,
|
||||||
'Object ID mismatch in URL and request body'
|
'Object ID mismatch in URL and request body'
|
||||||
end
|
end
|
||||||
if params.require(:data).require(:attributes).include?(:data_type)
|
if inventory_column_params[:attributes].include?(:data_type)
|
||||||
raise ActionController::BadRequest,
|
raise ActionController::BadRequest,
|
||||||
'Update of data_type attribute is not allowed'
|
'Update of data_type attribute is not allowed'
|
||||||
end
|
end
|
||||||
|
|
|
@ -119,7 +119,7 @@ module Api
|
||||||
'Wrong object type within parameters'
|
'Wrong object type within parameters'
|
||||||
end
|
end
|
||||||
params.require(:data).require(:attributes)
|
params.require(:data).require(:attributes)
|
||||||
params.permit(data: { attributes: %i(name uid) })[:data]
|
params.permit(data: { attributes: :name })[:data]
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_inventory_item_params
|
def update_inventory_item_params
|
||||||
|
|
|
@ -8,23 +8,17 @@ module Api
|
||||||
attribute :repository_column_id, key: :column_id
|
attribute :repository_column_id, key: :column_id
|
||||||
|
|
||||||
def value
|
def value
|
||||||
value =
|
|
||||||
case object.value_type
|
|
||||||
when 'RepositoryTextValue'
|
|
||||||
object.repository_text_value
|
|
||||||
when 'RepositoryDateValue'
|
|
||||||
object.repository_date_value
|
|
||||||
when 'RepositoryListValue'
|
|
||||||
object.repository_list_value
|
|
||||||
when 'RepositoryAssetValue'
|
|
||||||
object.repository_asset_value
|
|
||||||
end
|
|
||||||
ActiveModelSerializers::SerializableResource.new(
|
ActiveModelSerializers::SerializableResource.new(
|
||||||
value,
|
object.value,
|
||||||
|
class_name: object.value_type,
|
||||||
namespace: Api::V1,
|
namespace: Api::V1,
|
||||||
adapter: :attribute
|
adapter: :attribute
|
||||||
).as_json
|
).as_json
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def value_type
|
||||||
|
Extends::API_REPOSITORY_DATA_TYPE_MAPPINGS[object.value_type]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,8 +9,14 @@ module Api
|
||||||
key: :inventory_list_items,
|
key: :inventory_list_items,
|
||||||
serializer: InventoryListItemSerializer,
|
serializer: InventoryListItemSerializer,
|
||||||
class_name: 'RepositoryListItem',
|
class_name: 'RepositoryListItem',
|
||||||
if: -> { object.data_type == 'RepositoryListValue' &&
|
if: (lambda do
|
||||||
!instance_options[:hide_list_items] }
|
object.data_type == 'RepositoryListValue' &&
|
||||||
|
!instance_options[:hide_list_items]
|
||||||
|
end)
|
||||||
|
|
||||||
|
def data_type
|
||||||
|
Extends::API_REPOSITORY_DATA_TYPE_MAPPINGS[object.data_type]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -66,6 +66,11 @@ class Extends
|
||||||
# Array used for injecting names of additional authentication methods for API
|
# Array used for injecting names of additional authentication methods for API
|
||||||
API_PLUGABLE_AUTH_METHODS = [:azure_jwt_auth]
|
API_PLUGABLE_AUTH_METHODS = [:azure_jwt_auth]
|
||||||
|
|
||||||
|
API_REPOSITORY_DATA_TYPE_MAPPINGS = { 'RepositoryTextValue' => 'text',
|
||||||
|
'RepositoryDateValue' => 'date',
|
||||||
|
'RepositoryListValue' => 'list',
|
||||||
|
'RepositoryAssetValue' => 'file' }
|
||||||
|
|
||||||
OMNIAUTH_PROVIDERS = [:linkedin]
|
OMNIAUTH_PROVIDERS = [:linkedin]
|
||||||
|
|
||||||
INITIAL_USER_OPTIONS = {}
|
INITIAL_USER_OPTIONS = {}
|
||||||
|
|
|
@ -181,8 +181,7 @@ RSpec.describe 'Api::V1::InventoryColumnsController', type: :request do
|
||||||
{ type: 'inventory_columns',
|
{ type: 'inventory_columns',
|
||||||
attributes: {
|
attributes: {
|
||||||
name: Faker::Name.unique.name,
|
name: Faker::Name.unique.name,
|
||||||
data_type:
|
data_type: 'text'
|
||||||
RepositoryColumn.data_types.values.first
|
|
||||||
} } }
|
} } }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue