Skip to content

Commit

Permalink
Merge branch '2023061605-fixed-api-for-mobile' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
kirykr committed Aug 2, 2023
2 parents 3fbf027 + 604b6e4 commit ef45de3
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 12 deletions.
14 changes: 9 additions & 5 deletions app/controllers/api/v1/custom_field_properties_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,16 @@ def destroy
name = params[:file_name]
index = params[:file_index].to_i
if name.present? && index.present?
delete_form_builder_attachment(@custom_field_property, name, index)
render json: { error: "Failed deleting attachment" } unless @custom_field_property.save
if delete_form_builder_attachment(@custom_field_property, name, index)
head 204 if @custom_field_property.save
else
render json: { error: "Failed deleting attachment" }
end
elsif @custom_field_property.destroy
head 204
else
33054
render json: { error: "Failed deleting custom field property" }
end
head 204
end

private
Expand All @@ -61,7 +65,7 @@ def custom_field_property_params
end
end
end
properties_params.values.map{ |v| v.delete('') if (v.is_a?Array) && v.size > 1 } if properties_params.present?
properties_params.values.map { |v| v.delete('') if (v.is_a? Array) && v.size > 1 } if properties_params.present?
default_params = params.require(:custom_field_property).permit({}).merge(custom_field_id: params[:custom_field_id])
default_params = default_params.merge(properties: properties_params) if properties_params.present?
default_params = default_params.merge(form_builder_attachments_attributes: attachment_params) if action_name == 'create' && attachment_params.present?
Expand Down
14 changes: 7 additions & 7 deletions app/controllers/concerns/form_builder_attachments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,37 +29,37 @@ def delete_form_builder_attachment(resource, name, index)
end

def attachment_params
if ['client_enrollments','client_enrolled_programs'].include?(controller_name)
if ['client_enrollments', 'client_enrolled_programs'].include?(controller_name)
params[:client_enrollment][:form_builder_attachments_attributes]
elsif ['client_enrollment_trackings', 'client_enrolled_program_trackings', 'client_trackings'].include?(controller_name)
params[:client_enrollment_tracking][:form_builder_attachments_attributes]
elsif ['leave_programs','leave_enrolled_programs'].include?(controller_name)
elsif ['leave_programs', 'leave_enrolled_programs'].include?(controller_name)
params[:leave_program][:form_builder_attachments_attributes]
elsif ['custom_field_properties', 'client_custom_fields'].include?(controller_name)
params[:custom_field_property][:form_builder_attachments_attributes]
elsif ['enrollments','enrolled_programs'].include?(controller_name)
elsif ['enrollments', 'enrolled_programs'].include?(controller_name)
params[:enrollment][:form_builder_attachments_attributes]
elsif ['enrollment_trackings', 'enrolled_program_trackings', 'trackings'].include?(controller_name)
params[:enrollment_tracking][:form_builder_attachments_attributes]
end
end

def properties_params
if ['client_enrollments','client_enrolled_programs'].include?(controller_name)
if ['client_enrollments', 'client_enrolled_programs'].include?(controller_name)
params[:client_enrollment][:properties]
elsif ['client_enrollment_trackings', 'client_enrolled_program_trackings', 'client_trackings'].include?(controller_name)
params[:client_enrollment_tracking][:properties]
elsif ['leave_programs','leave_enrolled_programs'].include?(controller_name)
elsif ['leave_programs', 'leave_enrolled_programs'].include?(controller_name)
params[:leave_program][:properties]
elsif ['custom_field_properties', 'client_custom_fields'].include?(controller_name)
params[:custom_field_property][:properties]
end
end

def entity_properties_params
if ['enrollments','enrolled_programs'].include?(controller_name)
if ['enrollments', 'enrolled_programs'].include?(controller_name)
params[:enrollment][:properties]
elsif ['enrollment_trackings','enrolled_program_trackings', 'trackings'].include?(controller_name)
elsif ['enrollment_trackings', 'enrolled_program_trackings', 'trackings'].include?(controller_name)
params[:enrollment_tracking][:properties]
end
end
Expand Down
8 changes: 8 additions & 0 deletions app/models/attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ class Attachment < ActiveRecord::Base

validate :image_size_validation

protected

def _filename
file_name = File.basename(path).split('.').first.titleize
extention = File.basename(path).split('.').last
"#{file_name}.#{extention}"
end

private

def image_size_validation
Expand Down
12 changes: 12 additions & 0 deletions app/uploaders/custom_field_property_uploader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,23 @@ def extension_white_list
%w(jpg jpeg png doc docx xls xlsx pdf)
end

def serializable_hash
super.merge(
filename: _filename
)
end

protected

def image?(new_file)
if new_file.content_type.present?
new_file.content_type.start_with? 'image'
end
end

def _filename
file_name = File.basename(path).split('.').first.titleize
extention = File.basename(path).split('.').last
"#{file_name}.#{extention}"
end
end
12 changes: 12 additions & 0 deletions app/uploaders/form_builder_attachment_uploader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,23 @@ def extension_white_list
%w(jpg jpeg png doc docx xls xlsx pdf)
end

def serializable_hash
super.merge(
filename: _filename
)
end

protected

def image?(new_file)
if new_file.content_type.present?
new_file.content_type.start_with? 'image'
end
end

def _filename
file_name = File.basename(path).split('.').first.titleize
extention = File.basename(path).split('.').last
"#{file_name}.#{extention}"
end
end

0 comments on commit ef45de3

Please sign in to comment.