mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-01 13:13:22 +08:00
Merge pull request #1026 from okriuchykhin/ok_SCI_2148
Add uniqueness validation for SamplesTable [SCI-2148][SCI-2149]
This commit is contained in:
commit
7cbfa5936a
2 changed files with 14 additions and 8 deletions
|
@ -1,9 +1,9 @@
|
|||
class UserSamplesController < ApplicationController
|
||||
def save_samples_table_status
|
||||
samples_table = SamplesTable.where(user: @current_user,
|
||||
team: params[:team])
|
||||
team: params[:team]).first
|
||||
if samples_table
|
||||
samples_table.first.update(status: params[:state])
|
||||
samples_table.update(status: params[:state])
|
||||
else
|
||||
SamplesTable.create(user: @current_user,
|
||||
team: params[:team],
|
||||
|
@ -19,14 +19,19 @@ class UserSamplesController < ApplicationController
|
|||
end
|
||||
|
||||
def load_samples_table_status
|
||||
@samples_table_state = SamplesTable.find_status(current_user,
|
||||
current_team).first
|
||||
samples_table_state = SamplesTable.find_status(current_user,
|
||||
current_team).first
|
||||
if samples_table_state.blank?
|
||||
st = SamplesTable.new(user: current_user, team: current_team)
|
||||
st.save
|
||||
samples_table_state = st.status
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
if @samples_table_state
|
||||
if samples_table_state
|
||||
format.json do
|
||||
render json: {
|
||||
state: @samples_table_state
|
||||
state: samples_table_state
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
class SamplesTable < ApplicationRecord
|
||||
validates :user, :team, presence: true
|
||||
|
||||
belongs_to :user, inverse_of: :samples_tables, optional: true
|
||||
belongs_to :team, inverse_of: :samples_tables, optional: true
|
||||
|
||||
validates :user, :team, presence: true
|
||||
validates :user, uniqueness: { scope: :team }
|
||||
|
||||
scope :find_status,
|
||||
->(user, team) { where(user: user, team: team).pluck(:status) }
|
||||
|
||||
|
|
Loading…
Reference in a new issue