From cdbf8e4950f2394b60ae91ec1dc4039ad82495ce Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 18 Feb 2022 15:22:36 -0300 Subject: [PATCH] Bug 30133: Simplify code This patch simplifies the code, and also fixes a problem with branchcode comparisson failing, highlighted when running the tests To test: 1. Apply the regression tests 2. Run: $ kshell k$ prove t/db_dependent/api/v1/items.t => FAIL: Tests fail. Notably: - Link header pagination is wrong - X-*Total-Count headers have two values (dupicated) 3. Apply this patch 4. Repeat 2 => SUCCESS: Tests pass! 5. Sign off :-D --- Koha/REST/V1/Items.pm | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/Koha/REST/V1/Items.pm b/Koha/REST/V1/Items.pm index df0103700c..d3c5d7e177 100644 --- a/Koha/REST/V1/Items.pm +++ b/Koha/REST/V1/Items.pm @@ -113,7 +113,7 @@ sub pickup_locations { return try { - my $ps_set = $item->pickup_locations( { patron => $patron } ); + my $pl_set = $item->pickup_locations( { patron => $patron } ); my @response = (); if ( C4::Context->preference('AllowHoldPolicyOverride') ) { @@ -124,23 +124,19 @@ sub pickup_locations { @response = map { my $library = $_; $library->{needs_override} = ( - any { $_->{library_id} eq $library->{library_id} } - @{$ps_set->as_list} + any { $_->branchcode eq $library->{library_id} } + @{ $pl_set->as_list } ) ? Mojo::JSON->false : Mojo::JSON->true; $library; } @{$libraries}; - - return $c->render( - status => 200, - openapi => \@response - ); } + else { - my $pickup_locations = $c->objects->search( $ps_set ); - - @response = map { $_->{needs_override} = Mojo::JSON->false; $_; } @{$pickup_locations}; + my $pickup_locations = $c->objects->search($pl_set); + @response = map { $_->{needs_override} = Mojo::JSON->false; $_; } @{$pickup_locations}; + } return $c->render( status => 200, -- 2.35.1