+=head3 update_pickup_location
+
+Method that handles modifying the pickup location of a Koha::Hold object
+
+=cut
+
+sub update_pickup_location {
+ my $c = shift->openapi->valid_input or return;
+
+ my $hold_id = $c->validation->param('hold_id');
+ my $body = $c->validation->param('body');
+ my $pickup_library_id = $body->{pickup_library_id};
+
+ my $hold = Koha::Holds->find($hold_id);
+
+ unless ($hold) {
+ return $c->render(
+ status => 404,
+ openapi => { error => "Hold not found" }
+ );
+ }
+
+ return try {
+
+ my $overrides = $c->stash('koha.overrides');
+ my $can_override = $overrides->{any} && C4::Context->preference('AllowHoldPolicyOverride');
+
+ $hold->set_pickup_location(
+ {
+ library_id => $pickup_library_id,
+ force => $can_override
+ }
+ );
+
+ return $c->render(
+ status => 200,
+ openapi => {
+ pickup_library_id => $pickup_library_id
+ }
+ );
+ }
+ catch {
+
+ if ( blessed $_ and $_->isa('Koha::Exceptions::Hold::InvalidPickupLocation') ) {
+ return $c->render(
+ status => 400,
+ openapi => {
+ error => "$_"
+ }
+ );
+ }
+
+ $c->unhandled_exception($_);
+ };
+}
+
+