From aa6cc63506cd80a2ac0ff5478d955c68c680a8e5 Mon Sep 17 00:00:00 2001 From: Tom Bloor Date: Thu, 31 Aug 2017 18:25:27 +0100 Subject: [PATCH] Refactor leaderboard creation functions for entity upgrade --- .../LocalLoop/Schema/Result/Leaderboard.pm | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/Pear/LocalLoop/Schema/Result/Leaderboard.pm b/lib/Pear/LocalLoop/Schema/Result/Leaderboard.pm index 480aaa4..7c122d7 100644 --- a/lib/Pear/LocalLoop/Schema/Result/Leaderboard.pm +++ b/lib/Pear/LocalLoop/Schema/Result/Leaderboard.pm @@ -67,8 +67,8 @@ sub create_new { sub _get_customer_rs { my $self = shift; - return $self->result_source->schema->resultset('User')->search({ - organisation_id => undef, + return $self->result_source->schema->resultset('Entity')->search({ + type => 'customer', }); } @@ -93,7 +93,7 @@ sub _set_position_and_trend { my $previous_value; if ( defined $previous_board ) { - $previous_value = $previous_board->find({ user_id => $lb_val->{user_id} }); + $previous_value = $previous_board->find({ entity_id => $lb_val->{entity_id} }); } my $trend; @@ -122,12 +122,12 @@ sub _create_total_set { my @leaderboard; while ( my $user_result = $user_rs->next ) { - my $transaction_rs = $user_result->transactions->search_between( $start, $end ); + my $transaction_rs = $user_result->purchases->search_between( $start, $end ); my $transaction_sum = $transaction_rs->get_column('value')->sum; push @leaderboard, { - user_id => $user_result->id, + entity_id => $user_result->id, value => $transaction_sum || 0, }; } @@ -153,12 +153,12 @@ sub _create_count_set { my @leaderboard; while ( my $user_result = $user_rs->next ) { - my $transaction_rs = $user_result->transactions->search_between( $start, $end ); + my $transaction_rs = $user_result->purchases->search_between( $start, $end ); my $transaction_count = $transaction_rs->count; push @leaderboard, { - user_id => $user_result->id, + entity_id => $user_result->id, value => $transaction_count || 0, }; } @@ -184,12 +184,12 @@ sub _create_total_all_time { my @leaderboard; while ( my $user_result = $user_rs->next ) { - my $transaction_rs = $user_result->transactions->search_before( $end ); + my $transaction_rs = $user_result->purchases->search_before( $end ); my $transaction_sum = $transaction_rs->get_column('value')->sum; push @leaderboard, { - user_id => $user_result->id, + entity_id => $user_result->id, value => $transaction_sum || 0, }; } @@ -215,12 +215,12 @@ sub _create_count_all_time { my @leaderboard; while ( my $user_result = $user_rs->next ) { - my $transaction_rs = $user_result->transactions->search_before( $end ); + my $transaction_rs = $user_result->purchases->search_before( $end ); my $transaction_count = $transaction_rs->count; push @leaderboard, { - user_id => $user_result->id, + entity_id => $user_result->id, value => $transaction_count || 0, }; }