Fix serializing local storage on update and create [SCI-10465]

This commit is contained in:
Andrej 2024-07-11 07:54:44 +02:00
parent b1e5199c59
commit 88f6a12bdf
5 changed files with 13 additions and 11 deletions

View file

@ -20,7 +20,9 @@ class StorageLocationRepositoryRowsController < ApplicationController
@storage_location_repository_row.update(storage_location_repository_row_params)
if @storage_location_repository_row.save
render json: {}
render json: @storage_location_repository_row,
serializer: Lists::StorageLocationRepositoryRowSerializer,
include: :repository_row
else
render json: @storage_location_repository_row.errors, status: :unprocessable_entity
end
@ -30,12 +32,14 @@ class StorageLocationRepositoryRowsController < ApplicationController
@storage_location_repository_row = StorageLocationRepositoryRow.new(
repository_row: @repository_row,
storage_location: @storage_location,
metadata: storage_location_repository_row_params[:metadata],
metadata: storage_location_repository_row_params[:metadata] || {},
created_by: current_user
)
if @storage_location_repository_row.save
render json: {}
render json: @storage_location_repository_row,
serializer: Lists::StorageLocationRepositoryRowSerializer,
include: :repository_row
else
render json: @storage_location_repository_row.errors, status: :unprocessable_entity
end
@ -53,7 +57,7 @@ class StorageLocationRepositoryRowsController < ApplicationController
def load_storage_location_repository_row
@storage_location_repository_row = StorageLocationRepositoryRow.find(
storage_location_repository_row_params[:storage_location_id]
storage_location_repository_row_params[:id]
)
render_404 unless @storage_location_repository_row
end

View file

@ -15,7 +15,7 @@ class StorageLocationsController < ApplicationController
@storage_location.update(storage_location_params)
if @storage_location.save
render json: {}
render json: @storage_location, serializer: Lists::StorageLocationSerializer
else
render json: @storage_location.errors, status: :unprocessable_entity
end
@ -29,7 +29,7 @@ class StorageLocationsController < ApplicationController
@storage_location.image.attach(storage_location_params[:signed_blob_id]) if storage_location_params[:signed_blob_id]
if @storage_location.save
render json: {}
render json: @storage_location, serializer: Lists::StorageLocationSerializer
else
render json: @storage_location.errors, status: :unprocessable_entity
end

View file

@ -19,7 +19,7 @@ class StorageLocation < ApplicationRecord
validates :name, length: { maximum: Constants::NAME_MAX_LENGTH }
after_discard do
StorageLocation.where(parent_id: id).each(&:discard)
StorageLocation.where(parent_id: id).find_each(&:discard)
storage_location_repository_rows.each(&:discard)
end
end

View file

@ -12,7 +12,6 @@ module Lists
@records = StorageLocationRepositoryRow.includes(:repository_row).where(storage_location_id: @storage_location_id)
end
def filter_records
end
def filter_records; end
end
end

View file

@ -12,7 +12,6 @@ module Lists
@records = StorageLocation.where(team: @team, parent_id: @parent_id)
end
def filter_records
end
def filter_records; end
end
end