diff --git a/modules/costs/app/components/time_entries/time_entry_form_component.rb b/modules/costs/app/components/time_entries/time_entry_form_component.rb index 887e712496cc..648b155980cc 100644 --- a/modules/costs/app/components/time_entries/time_entry_form_component.rb +++ b/modules/costs/app/components/time_entries/time_entry_form_component.rb @@ -54,7 +54,7 @@ def form_options if time_entry.persisted? base.merge({ url: project_time_entry_path(project, time_entry), - method: :post + method: :patch }) else diff --git a/modules/costs/app/contracts/time_entries/base_contract.rb b/modules/costs/app/contracts/time_entries/base_contract.rb index 52aad1fda5db..1d9fdcf5aa63 100644 --- a/modules/costs/app/contracts/time_entries/base_contract.rb +++ b/modules/costs/app/contracts/time_entries/base_contract.rb @@ -69,6 +69,8 @@ def self.model attribute :user_id, permission: :log_time + attribute :start_time # TODO: Add validation with global setting + def assignable_activities if model.project TimeEntryActivity.active_in_project(model.project) diff --git a/modules/costs/app/controllers/projects/time_entries_controller.rb b/modules/costs/app/controllers/projects/time_entries_controller.rb index 3a5edf3e536c..7cd85daa8694 100644 --- a/modules/costs/app/controllers/projects/time_entries_controller.rb +++ b/modules/costs/app/controllers/projects/time_entries_controller.rb @@ -63,9 +63,22 @@ def create end def update - puts "*" * 100 - pp(permitted_params.time_entries) - puts "*" * 100 + time_entry = TimeEntry.find_by(id: params[:id]) + + call = TimeEntries::UpdateService + .new(user: current_user, model: time_entry) + .call(time_entry_params) + + @time_entry = call.result + + if call.success? + # TODO: just close here? + else + form_component = TimeEntries::TimeEntryFormComponent.new(time_entry: @time_entry) + update_via_turbo_stream(component: form_component, status: :bad_request) + + respond_with_turbo_streams + end end private