Lines 366-397
sub update_item {
Link Here
|
366 |
|
366 |
|
367 |
$item->set_from_api($body); |
367 |
$item->set_from_api($body); |
368 |
|
368 |
|
369 |
my $barcodeSearch; |
369 |
$item->store->discard_changes; |
370 |
$barcodeSearch = Koha::Items->search( { barcode => $body->{external_id} } ) if defined $body->{external_id}; |
|
|
371 |
|
372 |
if ( $barcodeSearch |
373 |
&& ($barcodeSearch->count > 1 |
374 |
|| ($barcodeSearch->count == 1 |
375 |
&& $barcodeSearch->next->itemnumber != $item->itemnumber |
376 |
) |
377 |
) |
378 |
) |
379 |
{ |
380 |
return $c->render( |
381 |
status => 400, |
382 |
openapi => { error => "Barcode not unique" } |
383 |
); |
384 |
} |
385 |
|
386 |
my $storedItem = $item->store; |
387 |
$storedItem->discard_changes; |
388 |
|
370 |
|
389 |
$c->render( |
371 |
$c->render( |
390 |
status => 200, |
372 |
status => 200, |
391 |
openapi => $storedItem->to_api |
373 |
openapi => $item->to_api |
392 |
); |
374 |
); |
393 |
} |
375 |
} |
394 |
catch { |
376 |
catch { |
|
|
377 |
if ( blessed $_ and $_->isa('Koha::Exceptions::Object::DuplicateID') ) { |
378 |
return $c->render( |
379 |
status => 409, |
380 |
openapi => { error => 'Duplicate barcode.' } |
381 |
); |
382 |
} |
395 |
$c->unhandled_exception($_); |
383 |
$c->unhandled_exception($_); |
396 |
} |
384 |
} |
397 |
} |
385 |
} |