mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-23 16:27:06 +08:00
Add external_id field to repository list and checklist items [SCI-9454] (#6702)
This commit is contained in:
parent
39f4637351
commit
9e9f8ab402
6 changed files with 62 additions and 6 deletions
|
@ -111,7 +111,7 @@ class RepositoryStockValue < ApplicationRecord
|
||||||
self.repository_stock_unit_item = repository_cell
|
self.repository_stock_unit_item = repository_cell
|
||||||
.repository_column
|
.repository_column
|
||||||
.repository_stock_unit_items
|
.repository_stock_unit_items
|
||||||
.find(new_data[:unit_item_id])
|
.find_by(id: new_data[:unit_item_id])
|
||||||
self.last_modified_by = user
|
self.last_modified_by = user
|
||||||
new_amount = new_data[:amount].to_d
|
new_amount = new_data[:amount].to_d
|
||||||
delta = new_amount - amount.to_d
|
delta = new_amount - amount.to_d
|
||||||
|
@ -157,7 +157,7 @@ class RepositoryStockValue < ApplicationRecord
|
||||||
value.repository_stock_unit_item = value.repository_cell
|
value.repository_stock_unit_item = value.repository_cell
|
||||||
.repository_column
|
.repository_column
|
||||||
.repository_stock_unit_items
|
.repository_stock_unit_items
|
||||||
.find(payload['unit_item_id'])
|
.find_by(id: payload['unit_item_id'])
|
||||||
value
|
value
|
||||||
else
|
else
|
||||||
raise ActiveRecord::RecordInvalid, 'Missing amount value'
|
raise ActiveRecord::RecordInvalid, 'Missing amount value'
|
||||||
|
|
|
@ -144,6 +144,8 @@ class Extends
|
||||||
RepositoryStockValue
|
RepositoryStockValue
|
||||||
)
|
)
|
||||||
|
|
||||||
|
STI_PRELOAD_CLASSES = %w(LinkedRepository)
|
||||||
|
|
||||||
# Array of preload relations used in search query for repository rows
|
# Array of preload relations used in search query for repository rows
|
||||||
REPOSITORY_ROWS_PRELOAD_RELATIONS = []
|
REPOSITORY_ROWS_PRELOAD_RELATIONS = []
|
||||||
|
|
||||||
|
|
7
config/initializers/preload_stis.rb
Normal file
7
config/initializers/preload_stis.rb
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
unless Rails.application.config.eager_load
|
||||||
|
Rails.application.config.to_prepare do
|
||||||
|
Extends::STI_PRELOAD_CLASSES.each(&:constantize)
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,35 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require File.expand_path('app/helpers/database_helper')
|
||||||
|
|
||||||
|
class AddExternalIdToRepositoryColumnItems < ActiveRecord::Migration[6.1]
|
||||||
|
include DatabaseHelper
|
||||||
|
|
||||||
|
def up
|
||||||
|
add_column :repository_list_items, :external_id, :string, null: true
|
||||||
|
add_column :repository_checklist_items, :external_id, :string, null: true
|
||||||
|
add_index :repository_list_items,
|
||||||
|
:external_id,
|
||||||
|
unique: true,
|
||||||
|
name: 'unique_index_repository_list_items_on_external_id'
|
||||||
|
add_index :repository_checklist_items,
|
||||||
|
:external_id,
|
||||||
|
unique: true,
|
||||||
|
name: 'unique_index_repository_checklist_items_on_external_id'
|
||||||
|
add_gin_index_without_tags(:repository_list_items, :external_id)
|
||||||
|
add_gin_index_without_tags(:repository_checklist_items, :external_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
remove_index :repository_rows, name: 'index_repository_checklist_items_on_external_id'
|
||||||
|
remove_index :repository_rows, name: 'index_repository_list_items_on_external_id'
|
||||||
|
remove_index :repository_checklist_items,
|
||||||
|
:external_id,
|
||||||
|
name: 'unique_index_repository_checklist_items_on_external_id'
|
||||||
|
remove_index :repository_list_items,
|
||||||
|
:external_id,
|
||||||
|
name: 'unique_index_repository_list_items_on_external_id'
|
||||||
|
remove_column :repository_checklist_items, :external_id, :string, null: true
|
||||||
|
remove_column :repository_list_items, :external_id, :string, null: true
|
||||||
|
end
|
||||||
|
end
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema[7.0].define(version: 2023_10_23_091358) do
|
ActiveRecord::Schema[7.0].define(version: 2023_11_07_163821) do
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "btree_gist"
|
enable_extension "btree_gist"
|
||||||
enable_extension "pg_trgm"
|
enable_extension "pg_trgm"
|
||||||
|
@ -657,8 +657,11 @@ ActiveRecord::Schema[7.0].define(version: 2023_10_23_091358) do
|
||||||
t.bigint "last_modified_by_id"
|
t.bigint "last_modified_by_id"
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
|
t.string "external_id"
|
||||||
t.index "trim_html_tags((data)::text) gin_trgm_ops", name: "index_repository_checklist_items_on_data", using: :gin
|
t.index "trim_html_tags((data)::text) gin_trgm_ops", name: "index_repository_checklist_items_on_data", using: :gin
|
||||||
|
t.index "trim_html_tags((external_id)::text) gin_trgm_ops", name: "index_repository_checklist_items_on_external_id", using: :gin
|
||||||
t.index ["created_by_id"], name: "index_repository_checklist_items_on_created_by_id"
|
t.index ["created_by_id"], name: "index_repository_checklist_items_on_created_by_id"
|
||||||
|
t.index ["external_id"], name: "unique_index_repository_checklist_items_on_external_id", unique: true
|
||||||
t.index ["last_modified_by_id"], name: "index_repository_checklist_items_on_last_modified_by_id"
|
t.index ["last_modified_by_id"], name: "index_repository_checklist_items_on_last_modified_by_id"
|
||||||
t.index ["repository_column_id"], name: "index_repository_checklist_items_on_repository_column_id"
|
t.index ["repository_column_id"], name: "index_repository_checklist_items_on_repository_column_id"
|
||||||
end
|
end
|
||||||
|
@ -750,8 +753,11 @@ ActiveRecord::Schema[7.0].define(version: 2023_10_23_091358) do
|
||||||
t.bigint "last_modified_by_id"
|
t.bigint "last_modified_by_id"
|
||||||
t.datetime "created_at", precision: nil, null: false
|
t.datetime "created_at", precision: nil, null: false
|
||||||
t.datetime "updated_at", precision: nil, null: false
|
t.datetime "updated_at", precision: nil, null: false
|
||||||
|
t.string "external_id"
|
||||||
|
t.index "trim_html_tags((external_id)::text) gin_trgm_ops", name: "index_repository_list_items_on_external_id", using: :gin
|
||||||
t.index "trim_html_tags(data) gin_trgm_ops", name: "index_repository_list_items_on_data", using: :gin
|
t.index "trim_html_tags(data) gin_trgm_ops", name: "index_repository_list_items_on_data", using: :gin
|
||||||
t.index ["created_by_id"], name: "index_repository_list_items_on_created_by_id"
|
t.index ["created_by_id"], name: "index_repository_list_items_on_created_by_id"
|
||||||
|
t.index ["external_id"], name: "unique_index_repository_list_items_on_external_id", unique: true
|
||||||
t.index ["last_modified_by_id"], name: "index_repository_list_items_on_last_modified_by_id"
|
t.index ["last_modified_by_id"], name: "index_repository_list_items_on_last_modified_by_id"
|
||||||
t.index ["repository_column_id"], name: "index_repository_list_items_on_repository_column_id"
|
t.index ["repository_column_id"], name: "index_repository_list_items_on_repository_column_id"
|
||||||
end
|
end
|
||||||
|
|
|
@ -749,7 +749,7 @@ RSpec.describe 'Api::V1::InventoryCellsController', type: :request do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'Response with inventory cell, stock cell, missing stock unit' do
|
it 'Response with inventory cell, stock cell, empty stock unit' do
|
||||||
hash_body = nil
|
hash_body = nil
|
||||||
empty_item = create(:repository_row, repository: @valid_inventory)
|
empty_item = create(:repository_row, repository: @valid_inventory)
|
||||||
invalid_file_body = @valid_stock_body.deep_dup
|
invalid_file_body = @valid_stock_body.deep_dup
|
||||||
|
@ -759,9 +759,15 @@ RSpec.describe 'Api::V1::InventoryCellsController', type: :request do
|
||||||
inventory_id: @valid_inventory.id,
|
inventory_id: @valid_inventory.id,
|
||||||
item_id: empty_item.id
|
item_id: empty_item.id
|
||||||
), params: invalid_file_body.to_json, headers: @valid_headers
|
), params: invalid_file_body.to_json, headers: @valid_headers
|
||||||
expect(response).to have_http_status 404
|
expect(response).to have_http_status 201
|
||||||
expect { hash_body = json }.not_to raise_exception
|
expect { hash_body = json }.not_to raise_exception
|
||||||
expect(hash_body['errors'][0]).to include('status': 404)
|
expect(hash_body[:data]).to match(
|
||||||
|
JSON.parse(
|
||||||
|
ActiveModelSerializers::SerializableResource
|
||||||
|
.new(RepositoryCell.last, serializer: Api::V1::InventoryCellSerializer)
|
||||||
|
.to_json
|
||||||
|
)['data']
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'Response with inventory cell, stock cell, missing amount' do
|
it 'Response with inventory cell, stock cell, missing amount' do
|
||||||
|
|
Loading…
Reference in a new issue