diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index a62da0c4a..d6c3a8d5e 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -33,7 +33,9 @@ def show def new @person = Ptime::UpdatePersonData.new.create_person(params[:ptime_employee_id]) %w[DE EN FR].each do |language| - @person.language_skills.push(LanguageSkill.new({ language: language, level: 'A1' })) + unless @person.language_skills.pluck(:language).include?(language.to_s) + @person.language_skills.push(LanguageSkill.new({ language: language, level: 'A1' })) + end end redirect_to(@person) #super diff --git a/app/domain/ptime/update_person_data.rb b/app/domain/ptime/update_person_data.rb index 7383de95f..b0436d81c 100644 --- a/app/domain/ptime/update_person_data.rb +++ b/app/domain/ptime/update_person_data.rb @@ -6,9 +6,7 @@ def create_person(ptime_employee_id) person = Person.find_by(ptime_employee_id: ptime_employee_id) return person unless person.nil? - Person.create!(name: 'Default name', company: Company.first, birthdate: '1.1.1970', - nationality: 'CH', location: 'Bern', title: 'Default title', - email: 'default@example.com', ptime_employee_id: ptime_employee_id) + update_person_data(person) end # rubocop:disable Metrics @@ -18,14 +16,11 @@ def update_person_data(person) location: :location }.freeze begin - return unless person.ptime_employee_id + raise 'Person has no ptime_employee_id' unless person.ptime_employee_id ptime_employee = Ptime::Client.new.get("employees/#{person.ptime_employee_id}")['data'] rescue RestClient::NotFound - person.destroy! if person.created_at == person.updated_at - raise "Ptime_employee with id #{person.ptime_employee_id} not found" - rescue StandardError - nil + raise "Ptime_employee with ptime_employee_id #{person.ptime_employee_id} not found" else ptime_employee['attributes'].each do |key, value| if key.to_sym.in?(attribute_mapping.keys) @@ -37,8 +32,8 @@ def update_person_data(person) ptime_employee_nationalities = ptime_employee['attributes']['nationalities'] person.nationality = ptime_employee_nationalities[0] person.nationality2 = ptime_employee_nationalities[1] - person.destroy! if !person.valid? && person.created_at == person.updated_at person.save! + person end end # rubocop:enable Metrics