Skip to content

Commit

Permalink
throw a specific error if user isnt found when syncing time entries
Browse files Browse the repository at this point in the history
  • Loading branch information
kaiomagalhaes committed Nov 6, 2023
1 parent a41a4a2 commit f6d65d4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 58 deletions.
55 changes: 0 additions & 55 deletions app/controllers/time_entries_controller.rb

This file was deleted.

12 changes: 9 additions & 3 deletions app/services/team_maker_project_creator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ def call

def create_time_entires!(team_maker_project_time_entries)
team_maker_project_time_entries.each do |time_entry|
user = User.find_by(email: time_entry.resource)
next if user.nil?
user = find_user(time_entry.resource)

TimeEntry.create!(
statement_of_work:,
Expand All @@ -41,7 +40,7 @@ def create_requirements!(team_maker_project_requirements)

def create_assignments!(team_maker_project_assignments, requirement)
team_maker_project_assignments.each do |assignment|
user = User.find_by(email: assignment.resource)
user = find_user(assignment.resource)

Assignment.create!(
requirement:,
Expand Down Expand Up @@ -85,4 +84,11 @@ def statement_of_work
@statement_of_work.requirements.destroy_all
@statement_of_work
end

def find_user(email)
user = User.find_by(email:)
raise StandardError, "User with email #{email} does not exist" if user.nil?

user
end
end

0 comments on commit f6d65d4

Please sign in to comment.