mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-03-06 04:34:06 +08:00
Add position format validation [SCI-11152]
This commit is contained in:
parent
122f389629
commit
009fb04e37
1 changed files with 6 additions and 0 deletions
|
@ -4,6 +4,8 @@ require 'caxlsx'
|
|||
|
||||
module StorageLocations
|
||||
class ImportService
|
||||
class PositionNotValid < StandardError; end
|
||||
|
||||
def initialize(storage_location, file, user)
|
||||
@storage_location = storage_location
|
||||
@assigned_count = 0
|
||||
|
@ -54,6 +56,8 @@ module StorageLocations
|
|||
{ status: :ok, assigned_count: @assigned_count, unassigned_count: @unassigned_count, updated_count: @updated_count }
|
||||
rescue ActiveRecord::RecordNotFound, ActiveRecord::RecordInvalid
|
||||
{ status: :error, message: @error_message }
|
||||
rescue PositionNotValid
|
||||
{ status: :error, message: I18n.t('storage_locations.show.import_modal.errors.invalid_position') }
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -105,6 +109,8 @@ module StorageLocations
|
|||
def convert_position_letter_to_number(position)
|
||||
return unless position
|
||||
|
||||
raise PositionNotValid unless position.to_s.match?(/^[A-Z]\d+$/)
|
||||
|
||||
column_letter = position[0]
|
||||
row_number = position[1..]
|
||||
|
||||
|
|
Loading…
Reference in a new issue