From 86beecce8139d5a8cb7c44a90517bd61660729bf 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 Signed-off-by: Andrew Fuerste-Henry Signed-off-by: Jonathan Druart Signed-off-by: Fridolin Somers Signed-off-by: Kyle M Hall (cherry picked from commit eb5dbb4010c6f95f6ddaf594d8aee22509acec42) Signed-off-by: Andrew Fuerste-Henry --- 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 380a88ef16..1d85f74780 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.39.5