From 9b7d8530b6d78e5acf47d10c4102c479f74b3dcd Mon Sep 17 00:00:00 2001 From: Felix Date: Wed, 14 Aug 2019 14:02:01 +0100 Subject: [PATCH] Revert "custom graph duration and dateRange added" This reverts commit bbb7edd269c3597aff926ba462322b576734b115. --- .DS_Store | Bin 6148 -> 0 bytes .../Controller/Api/V1/Customer/Graphs.pm | 65 +++--------------- 2 files changed, 8 insertions(+), 57 deletions(-) delete mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 191c7db4be52e2ec91f1153c266a44a0839652eb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKUvJYe5I=8WxIu_MOk$6D;cc*1493f(s0=0~gpk6Y2S8h*gf3Eut0Y~4Qk1VT zz7d~*ufy+bx7z3?@qiFwzRLGIpM7WhCpqpBkr<5AK2ev5BpRdVL!Bc$&TUCntY-}< zI7c$6M@gX)^uI67b`HmYW8hz7fbXtHcW6jCHK*@yGAi=A>Gghyl~wP`+Epoi>0kHX zMMr89HE}bp2XXa=d(Y$MD6#enrHX|eC$I8sa?o9WsLCeJ%dFDDd75F$+t+!Ss>wi& z%e2;cA~PUmM|KXn8`J5%2ffW;d%Hi|45m9fY~Q^CXwrN<%7*NuPQn%+!mccAg(CFo$RFtGBtnBuI|dvBXBk*E-7dfXk1nqN&jz`kW56-+ zUojxOy=ZTMBiXlg>2Unk255(9EIh9@s6(LabF2-1iZ{@-U@Tw*7+P!%!UJ)C1T+m! KIR^eJ13v+1Vuniq diff --git a/lib/Pear/LocalLoop/Controller/Api/V1/Customer/Graphs.pm b/lib/Pear/LocalLoop/Controller/Api/V1/Customer/Graphs.pm index 42a55f2..f48e52b 100644 --- a/lib/Pear/LocalLoop/Controller/Api/V1/Customer/Graphs.pm +++ b/lib/Pear/LocalLoop/Controller/Api/V1/Customer/Graphs.pm @@ -20,20 +20,9 @@ sub index { avg_spend_last_week total_last_month avg_spend_last_month - total_duration - total_range - avg_spend_duration - avg_spend_range / ); return $c->api_validation_error if $validation->has_error; - if ($validation->param('graph') == 'total_range' || $validation->param('graph') == 'avg_spend_range') { - $validation->required('start_date', 'end_date'); - } - - if ($validation->param('graph') == 'total_duration' || $validation->param('graph') == 'avg_spend_duration') { - $validation->required('duration'); - } my $graph_sub = "graph_" . $validation->param('graph'); @@ -55,26 +44,15 @@ sub index { sub graph_total_last_week { return shift->_purchases_total_duration( 7 ) } sub graph_total_last_month { return shift->_purchases_total_duration( 30 ) } -sub graph_total_duration { - my ( $c, $duration ) = @_; - return shift->__purchases_total_duration( $duration ); -} - -sub graph_total_range { - my ( $c, $start_date, $end_date ) = @_; - return shift->__purchases_total_duration( $duration, $start_date, $end_date ); -} - sub _purchases_total_duration { - my ( $c, $day_duration, $start_date, $end_date ) = @_; + my ( $c, $day_duration ) = @_; my $duration = DateTime::Duration->new( days => $day_duration ); my $entity = $c->stash->{api_user}->entity; my $data = { labels => [], data => [] }; -# if $start_date and $end_date are not present it will use $duration - my ( $start, $end ) = $c->_get_start_end_duration( $duration, $start_date, $end_date ); + my ( $start, $end ) = $c->_get_start_end_duration( $duration ); $data->{bounds} = { min => $c->format_iso_datetime( $start ), @@ -103,27 +81,16 @@ sub _purchases_total_duration { sub graph_avg_spend_last_week { return shift->_purchases_avg_spend_duration( 7 ) } sub graph_avg_spend_last_month { return shift->_purchases_avg_spend_duration( 30 ) } -sub graph_avg_spend_duration { - my ( $c, $duration ) = @_; - return shift->_purchases_avg_spend_duration( $duration ); -} - -sub graph_avg_spend_range { - my ( $c, $start_date, $end_date ) = @_; - return shift->_purchases_avg_spend_duration( $duration, $start_date, $end_date ); -} - sub _purchases_avg_spend_duration { - my ( $c, $day_duration, $start_date, $end_date ) = @_; + my ( $c, $day_duration ) = @_; my $duration = DateTime::Duration->new( days => $day_duration ); my $entity = $c->stash->{api_user}->entity; my $data = { labels => [], data => [] }; -# if $start_date and $end_date are not present it will use $duration - my ( $start, $end ) = $c->_get_start_end_duration( $duration, $start_date, $end_date ); - + my ( $start, $end ) = $c->_get_start_end_duration( $duration ); + $data->{bounds} = { min => $c->format_iso_datetime( $start ), max => $c->format_iso_datetime( $end ), @@ -176,25 +143,9 @@ sub _purchases_avg_spend_duration { } sub _get_start_end_duration { - my ( $c, $duration, $start_date, $end_date ) = @_; - my $start; - my $end; - - if ($end_date && $start_date) { - $start = DateTime->new( - year => substr $start_date, 0, 4, - month => substr $start_date, 4, 2, - days => substr $start_date, 7, 2, - ); - $end = DateTime->new( - year => substr $end_date, 0, 4, - month => substr $end_date, 4, 2, - days => substr $end_date, 7, 2, - ); - } else { - $end = $end->clone->subtract_duration( $duration ); - } - + my ( $c, $duration ) = @_; + my $end = DateTime->today; + my $start = $end->clone->subtract_duration( $duration ); return ( $start, $end ); }