Bug 21063: Add "Columns settings" for ILL
[koha.git] / Koha / REST / V1 / Illrequests.pm
index 324a1ca..f8385a7 100644 (file)
@@ -15,6 +15,8 @@ package Koha::REST::V1::Illrequests;
 # with Koha; if not, write to the Free Software Foundation, Inc.,
 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
+use Modern::Perl;
+
 use Mojo::Base 'Mojolicious::Controller';
 
 use Koha::Illrequests;
@@ -22,6 +24,7 @@ use Koha::Illrequestattributes;
 use Koha::Libraries;
 use Koha::Patrons;
 use Koha::Libraries;
+use Koha::DateUtils qw( format_sqldatetime );
 
 =head1 NAME
 
@@ -39,6 +42,8 @@ sub list {
     my $c = shift->openapi->valid_input or return;
 
     my $args = $c->req->params->to_hash // {};
+    my $output = [];
+    my @format_dates = ( 'placed', 'updated', 'completed' );
 
     # Create a hash where all keys are embedded values
     # Enables easy checking
@@ -106,12 +111,26 @@ sub list {
     foreach my $req(@requests) {
         my $to_push = $req->unblessed;
         $to_push->{id_prefix} = $req->id_prefix;
+        # Create new "formatted" columns for each date column
+        # that needs formatting
+        foreach my $field(@format_dates) {
+            if (defined $to_push->{$field}) {
+                $to_push->{$field . "_formatted"} = format_sqldatetime(
+                    $to_push->{$field},
+                    undef,
+                    undef,
+                    1
+                );
+            }
+        }
+
         foreach my $p(@{$patron_arr}) {
             if ($p->{borrowernumber} == $req->borrowernumber) {
                 $to_push->{patron} = {
-                    firstname  => $p->{firstname},
-                    surname    => $p->{surname},
-                    cardnumber => $p->{cardnumber}
+                    patron_id => $p->{borrowernumber},
+                    firstname      => $p->{firstname},
+                    surname        => $p->{surname},
+                    cardnumber     => $p->{cardnumber}
                 };
                 last;
             }
@@ -139,6 +158,9 @@ sub list {
         if ($embed{comments}) {
             $to_push->{comments} = $req->illcomments->count;
         }
+        if ($embed{status_alias}) {
+            $to_push->{status_alias} = $req->statusalias;
+        }
         push @output, $to_push;
     }