|
|
|
@ -8,6 +8,8 @@ class Recipient < ApplicationRecord
|
|
|
|
|
|
|
|
|
|
|
|
validates :name, presence: true
|
|
|
|
validates :name, presence: true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
before_destroy :sync_lists
|
|
|
|
|
|
|
|
|
|
|
|
def self.import(school, file)
|
|
|
|
def self.import(school, file)
|
|
|
|
CSV.foreach(file.path, headers: true) do |row|
|
|
|
|
CSV.foreach(file.path, headers: true) do |row|
|
|
|
|
school.recipients.create!(row.to_hash)
|
|
|
|
school.recipients.create!(row.to_hash)
|
|
|
|
@ -22,4 +24,14 @@ class Recipient < ApplicationRecord
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def sync_lists
|
|
|
|
|
|
|
|
school.recipient_lists.each do |recipient_list|
|
|
|
|
|
|
|
|
next if recipient_list.recipient_id_array.index(id).nil?
|
|
|
|
|
|
|
|
updated_ids = recipient_list.recipient_id_array - [id]
|
|
|
|
|
|
|
|
recipient_list.update_attributes(recipient_id_array: updated_ids)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|