From 7d1d26df09c2f2b00b3633619bc64fbefd6e57e8 Mon Sep 17 00:00:00 2001 From: kirykr Date: Fri, 18 Aug 2023 11:13:34 +0700 Subject: [PATCH] Added tasks to case note serializer --- app/controllers/api/v1/case_notes_controller.rb | 5 +++++ app/serializers/case_note_serializer.rb | 11 ++++++++++- config/routes.rb | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/v1/case_notes_controller.rb b/app/controllers/api/v1/case_notes_controller.rb index fbe23e5678..5a12eb72f6 100644 --- a/app/controllers/api/v1/case_notes_controller.rb +++ b/app/controllers/api/v1/case_notes_controller.rb @@ -7,6 +7,11 @@ class CaseNotesController < Api::V1::BaseApiController before_action :find_client + def show + case_note = CaseNote.find(params[:id]) + render json: case_note + end + def create case_note = @client.case_notes.new(case_note_params) case_note.assessment = @client.assessments.custom_latest_record diff --git a/app/serializers/case_note_serializer.rb b/app/serializers/case_note_serializer.rb index 39337b456d..3b1590fa35 100644 --- a/app/serializers/case_note_serializer.rb +++ b/app/serializers/case_note_serializer.rb @@ -1,7 +1,16 @@ class CaseNoteSerializer < ActiveModel::Serializer - attributes :id, :attendee, :meeting_date, :interaction_type, :note, :client_id, :assessment_id, :case_note_domain_groups, :selected_domain_group_ids, :attachments, :draft, :created_at, :updated_at + attributes :id, :attendee, :meeting_date, :interaction_type, :note, :client_id, :assessment_id, :case_note_domain_groups, + :selected_domain_group_ids, :attachments, :draft, :tasks, :created_at, :updated_at + + + private def case_note_domain_groups ActiveModel::ArraySerializer.new(object.case_note_domain_groups, each_serializer: CaseNoteDomainGroupSerializer) end + + def tasks + tasks = Task.completed.where(case_note_id: object.id) + [*object.tasks, *tasks] + end end diff --git a/config/routes.rb b/config/routes.rb index e7f8dd00ec..44a3286052 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -396,7 +396,7 @@ resources :clients, except: [:edit, :new] do get :listing, on: :collection resources :assessments, only: [:create, :update, :destroy, :delete] - resources :case_notes, only: [:create, :update, :destroy, :delete_attachment] do + resources :case_notes, only: [:show, :create, :update, :destroy, :delete_attachment] do delete 'attachments/:file_index', action: :delete_attachment, on: :member end resources :custom_field_properties, only: [:create, :update, :destroy]