diff --git a/app/controllers/time_entries_controller.rb b/app/controllers/time_entries_controller.rb deleted file mode 100644 index 56595e2..0000000 --- a/app/controllers/time_entries_controller.rb +++ /dev/null @@ -1,55 +0,0 @@ -# frozen_string_literal: true - -class TimeEntriesController < ApplicationController - before_action :set_time_entry, only: %i[show update destroy] - - # GET /time_entries - # GET /time_entries.json - def index - @time_entries = TimeEntry.all - end - - # GET /time_entries/1 - # GET /time_entries/1.json - def show; end - - # POST /time_entries - # POST /time_entries.json - def create - @time_entry = TimeEntry.new(time_entry_params) - - if @time_entry.save - render :show, status: :created, location: @time_entry - else - render json: @time_entry.errors, status: :unprocessable_entity - end - end - - # PATCH/PUT /time_entries/1 - # PATCH/PUT /time_entries/1.json - def update - if @time_entry.update(time_entry_params) - render :show, status: :ok, location: @time_entry - else - render json: @time_entry.errors, status: :unprocessable_entity - end - end - - # DELETE /time_entries/1 - # DELETE /time_entries/1.json - def destroy - @time_entry.destroy - end - - private - - # Use callbacks to share common setup or constraints between actions. - def set_time_entry - @time_entry = TimeEntry.find(params[:id]) - end - - # Only allow a list of trusted parameters through. - def time_entry_params - params.require(:time_entry).permit(:date, :hours, :user_id, :statement_of_work_id) - end -end diff --git a/app/services/team_maker_project_creator.rb b/app/services/team_maker_project_creator.rb index 343b10c..0ba4421 100644 --- a/app/services/team_maker_project_creator.rb +++ b/app/services/team_maker_project_creator.rb @@ -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:, @@ -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:, @@ -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