|
Lines 432-463
sub update_item {
Link Here
|
| 432 |
|
432 |
|
| 433 |
$item->set_from_api($body); |
433 |
$item->set_from_api($body); |
| 434 |
|
434 |
|
| 435 |
my $barcodeSearch; |
435 |
$item->store->discard_changes; |
| 436 |
$barcodeSearch = Koha::Items->search( { barcode => $body->{external_id} } ) if defined $body->{external_id}; |
|
|
| 437 |
|
| 438 |
if ( $barcodeSearch |
| 439 |
&& ($barcodeSearch->count > 1 |
| 440 |
|| ($barcodeSearch->count == 1 |
| 441 |
&& $barcodeSearch->next->itemnumber != $item->itemnumber |
| 442 |
) |
| 443 |
) |
| 444 |
) |
| 445 |
{ |
| 446 |
return $c->render( |
| 447 |
status => 400, |
| 448 |
openapi => { error => "Barcode not unique" } |
| 449 |
); |
| 450 |
} |
| 451 |
|
| 452 |
my $storedItem = $item->store; |
| 453 |
$storedItem->discard_changes; |
| 454 |
|
436 |
|
| 455 |
$c->render( |
437 |
$c->render( |
| 456 |
status => 200, |
438 |
status => 200, |
| 457 |
openapi => $storedItem->to_api |
439 |
openapi => $item->to_api |
| 458 |
); |
440 |
); |
| 459 |
} |
441 |
} |
| 460 |
catch { |
442 |
catch { |
|
|
443 |
if ( blessed $_ and $_->isa('Koha::Exceptions::Object::DuplicateID') ) { |
| 444 |
return $c->render( |
| 445 |
status => 409, |
| 446 |
openapi => { error => 'Duplicate barcode.' } |
| 447 |
); |
| 448 |
} |
| 461 |
$c->unhandled_exception($_); |
449 |
$c->unhandled_exception($_); |
| 462 |
} |
450 |
} |
| 463 |
} |
451 |
} |