Bug 32997: (QA follow-up) values => authorised_values
[srvgit] / Koha / REST / V1 / ReturnClaims.pm
index ce6b58e..850b0f7 100644 (file)
@@ -2,28 +2,27 @@ package Koha::REST::V1::ReturnClaims;
 
 # This file is part of Koha.
 #
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 3 of the License, or (at your option) any later
-# version.
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
 #
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
 #
-# You should have received a copy of the GNU General Public License along
-# with Koha; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 use Modern::Perl;
 
 use Mojo::Base 'Mojolicious::Controller';
 
-use Try::Tiny;
+use Try::Tiny qw( catch try );
 
 use Koha::Checkouts::ReturnClaims;
 use Koha::Checkouts;
-use Koha::DateUtils qw( dt_from_string output_pref );
 
 =head1 NAME
 
@@ -86,12 +85,8 @@ sub claim_returned {
                 openapi => { error => "Mandatory attribute created_by missing" }
             );
         }
-        else {
-            return $c->render(
-                status  => 500,
-                openapi => { error => "Something went wrong, check the logs." }
-            );
-        }
+
+        $c->unhandled_exception($_);
     };
 }
 
@@ -137,18 +132,7 @@ sub update_notes {
         );
     }
     catch {
-        if ( $_->isa('Koha::Exceptions::Exception') ) {
-            return $c->render(
-                status  => 500,
-                openapi => { error => "$_" }
-            );
-        }
-        else {
-            return $c->render(
-                status  => 500,
-                openapi => { error => "Something went wrong, check the logs." }
-            );
-        }
+        $c->unhandled_exception($_);
     };
 }
 
@@ -167,28 +151,26 @@ sub resolve_claim {
     my $claim = Koha::Checkouts::ReturnClaims->find($claim_id);
 
     return $c->render(
-            status => 404,
-            openapi => {
-                error => "Claim not found"
-            }
+        status  => 404,
+        openapi => { error => "Claim not found" }
     ) unless $claim;
 
     return try {
 
-        my $resolved_by = $body->{resolved_by};
-        my $resolution  = $body->{resolution};
+        my $resolved_by     = $body->{resolved_by};
+        my $resolution      = $body->{resolution};
+        my $new_lost_status = $body->{new_lost_status};
 
         my $user = $c->stash('koha.user');
         $resolved_by //= $user->borrowernumber;
 
-        $claim->set(
+        $claim->resolve(
             {
-                resolution  => $resolution,
-                resolved_by => $resolved_by,
-                resolved_on => \'NOW()',
+                resolution      => $resolution,
+                resolved_by     => $resolved_by,
+                new_lost_status => $new_lost_status,
             }
-        )->store;
-        $claim->discard_changes;
+        )->discard_changes;
 
         return $c->render(
             status  => 200,
@@ -196,18 +178,7 @@ sub resolve_claim {
         );
     }
     catch {
-        if ( $_->isa('Koha::Exceptions::Exception') ) {
-            return $c->render(
-                status  => 500,
-                openapi => { error => "$_" }
-            );
-        }
-        else {
-            return $c->render(
-                status  => 500,
-                openapi => { error => "Something went wrong, check the logs." }
-            );
-        }
+        $c->unhandled_exception($_);
     };
 }
 
@@ -237,18 +208,7 @@ sub delete_claim {
         );
     }
     catch {
-        if ( $_->isa('Koha::Exceptions::Exception') ) {
-            return $c->render(
-                status  => 500,
-                openapi => { error => "$_" }
-            );
-        }
-        else {
-            return $c->render(
-                status  => 500,
-                openapi => { error => "Something went wrong, check the logs." }
-            );
-        }
+        $c->unhandled_exception($_);
     };
 }