Skip to content

Commit

Permalink
Fixes query to run ordering/filtering in the db, adds return if distr…
Browse files Browse the repository at this point in the history
…ibutions is blank, TODO about error-handling
  • Loading branch information
katelovescode committed Jan 31, 2024
1 parent f48bd71 commit f6ea450
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
7 changes: 5 additions & 2 deletions app/services/exports/export_distributions_csv_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ def initialize(distributions:, filters: [])
# service object.
@distributions = distributions
@filters = filters
@organization = @distributions.first.organization
@organization = @distributions.&first.&organization
end

def generate_csv
# TODO: we may want some error handling here in case there are none, but I'm not sure what the process is;
# should we do a flash[:error]?
return unless distributions
csv_data = generate_csv_data

CSV.generate(headers: true) do |csv|
Expand Down Expand Up @@ -115,7 +118,7 @@ def base_headers
def item_headers
return @item_headers if @item_headers

@item_headers = @organization.items.uniq.sort_by(&:created_at).pluck(:name)
@item_headers = @organization.items.order(:created_at).distinct.select([:created_at, :name]).map(&:name)
end

def build_row_data(distribution)
Expand Down
1 change: 0 additions & 1 deletion spec/requests/partners_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@

context "csv" do
let(:response_format) { 'csv' }
before { create(:distribution, partner: partner) }

it { is_expected.to be_successful }
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
let(:all_org_items) { Item.where(organization:).uniq.sort_by(&:created_at) }

let(:total_item_quantities) do
# binding.pry
template = all_org_items.pluck(:name).index_with(0)

items_lists.map do |items_list|
Expand Down

0 comments on commit f6ea450

Please sign in to comment.