Lines 340-345
sub delete {
Link Here
|
340 |
}; |
340 |
}; |
341 |
} |
341 |
} |
342 |
|
342 |
|
|
|
343 |
=head3 delete_bulk |
344 |
|
345 |
Method that handles deleting multiple Koha::Hold objects |
346 |
|
347 |
=cut |
348 |
|
349 |
sub delete_bulk { |
350 |
my $c = shift->openapi->valid_input or return; |
351 |
|
352 |
my $body = $c->req->json; |
353 |
my $hold_ids = ($body) ? $body->{hold_ids} : undef; |
354 |
my $cancellation_reason = ($body) ? $body->{cancellation_reason} : undef; |
355 |
|
356 |
return $c->render_resource_not_found("Hold") |
357 |
unless $hold_ids; |
358 |
|
359 |
foreach my $hold_id (@$hold_ids) { |
360 |
my $hold = Koha::Holds->find($hold_id); |
361 |
return $c->render_resource_not_found( "Hold", "id", $hold_id ) |
362 |
unless $hold; |
363 |
} |
364 |
|
365 |
return try { |
366 |
Koha::Database->new->schema->txn_do( |
367 |
sub { |
368 |
foreach my $hold_id (@$hold_ids) { |
369 |
my $hold = Koha::Holds->find($hold_id); |
370 |
$hold->cancel( { cancellation_reason => $cancellation_reason } ); |
371 |
} |
372 |
$c->res->headers->location( $c->req->url->to_string ); |
373 |
return $c->render( |
374 |
status => 204, |
375 |
openapi => { |
376 |
hold_ids => $hold_ids, |
377 |
cancellation_reason => $cancellation_reason, |
378 |
} |
379 |
); |
380 |
} |
381 |
); |
382 |
} catch { |
383 |
$c->unhandled_exception($_); |
384 |
}; |
385 |
} |
386 |
|
343 |
=head3 suspend |
387 |
=head3 suspend |
344 |
|
388 |
|
345 |
Method that handles suspending a hold |
389 |
Method that handles suspending a hold |