From 4fdff21f504b06c6728e8ba0933bb9c6a2570add Mon Sep 17 00:00:00 2001 From: Tom Bloor Date: Mon, 15 Jul 2019 03:45:42 +0100 Subject: [PATCH] Change to using a name map temporarily --- lib/Pear/LocalLoop/Controller/Api/External.pm | 21 ++++++- .../Result/ViewQuantisedTransactionPg.pm | 56 ------------------- 2 files changed, 20 insertions(+), 57 deletions(-) diff --git a/lib/Pear/LocalLoop/Controller/Api/External.pm b/lib/Pear/LocalLoop/Controller/Api/External.pm index 8183b18..d4dee8a 100644 --- a/lib/Pear/LocalLoop/Controller/Api/External.pm +++ b/lib/Pear/LocalLoop/Controller/Api/External.pm @@ -198,12 +198,31 @@ sub post_supplier_count { } ); + my $name_rs = $c->schema->resultset('Transaction')->search( + { + 'me.buyer_id' => $user->entity->id, + }, + { + prefetch => { entity => 'organisation' }, + columns => [ + 'organisation.name', + 'entity.id' + ] + } + ); + + my %name_map = ( + map { + $_->entity->id => $_->entity->organisation->name, + } $name_rs->all + ); + my @graph_data = ( map { { count => $_->get_column('count'), value => $_->get_column('total_spend'), date => $_->get_column('quantised'), - seller => $_->seller->name, + seller => %name_map{ $_->get_column('seller_id') }, } } $spend_rs->all, ); diff --git a/lib/Pear/LocalLoop/Schema/Result/ViewQuantisedTransactionPg.pm b/lib/Pear/LocalLoop/Schema/Result/ViewQuantisedTransactionPg.pm index 8f865e7..a524424 100644 --- a/lib/Pear/LocalLoop/Schema/Result/ViewQuantisedTransactionPg.pm +++ b/lib/Pear/LocalLoop/Schema/Result/ViewQuantisedTransactionPg.pm @@ -22,60 +22,4 @@ SELECT "value", FROM "transactions" /); -__PACKAGE__->add_columns( - "buyer_id" => { - data_type => "integer", - is_foreign_key => 1, - is_nullable => 0, - }, - "seller_id" => { - data_type => "integer", - is_foreign_key => 1, - is_nullable => 0, - }, - "value" => { - data_type => "numeric", - size => [ 100, 0 ], - is_nullable => 0, - }, - "quantised_hours" => { - data_type => "datetime", - timezone => "UTC", - is_nullable => 0, - set_on_create => 1, - }, - "quantised_days" => { - data_type => "datetime", - timezone => "UTC", - is_nullable => 0, - set_on_create => 1, - }, - "quantised_weeks" => { - data_type => "datetime", - timezone => "UTC", - is_nullable => 0, - set_on_create => 1, - }, - "quantised_months" => { - data_type => "datetime", - timezone => "UTC", - is_nullable => 0, - set_on_create => 1, - }, -); - -__PACKAGE__->belongs_to( - "buyer", - "Pear::LocalLoop::Schema::Result::Entity", - { id => "buyer_id" }, - { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" }, -); - -__PACKAGE__->belongs_to( - "seller", - "Pear::LocalLoop::Schema::Result::Entity", - { id => "seller_id" }, - { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" }, -); - 1;