Lines 21-26
use Mojo::Base 'Mojolicious::Controller';
Link Here
|
21 |
|
21 |
|
22 |
use Koha::Illrequests; |
22 |
use Koha::Illrequests; |
23 |
use Koha::Libraries; |
23 |
use Koha::Libraries; |
|
|
24 |
use Koha::DateUtils qw( format_sqldatetime ); |
24 |
|
25 |
|
25 |
=head1 NAME |
26 |
=head1 NAME |
26 |
|
27 |
|
Lines 40-45
sub list {
Link Here
|
40 |
my $args = $c->req->params->to_hash // {}; |
41 |
my $args = $c->req->params->to_hash // {}; |
41 |
my $filter; |
42 |
my $filter; |
42 |
my $output = []; |
43 |
my $output = []; |
|
|
44 |
my @format_dates = ( 'placed', 'updated' ); |
43 |
|
45 |
|
44 |
# Create a hash where all keys are embedded values |
46 |
# Create a hash where all keys are embedded values |
45 |
# Enables easy checking |
47 |
# Enables easy checking |
Lines 54-71
sub list {
Link Here
|
54 |
$filter->{$filter_param} = \@values; |
56 |
$filter->{$filter_param} = \@values; |
55 |
} |
57 |
} |
56 |
|
58 |
|
57 |
my $requests = Koha::Illrequests->search($filter); |
59 |
my @req_list = Koha::Illrequests->search($filter)->as_list; |
58 |
|
60 |
|
59 |
if ( scalar (keys %embed) ) |
61 |
if ( scalar (keys %embed) ) |
60 |
{ |
62 |
{ |
61 |
# Need to embed stuff |
63 |
# Need to embed stuff |
62 |
my @results = map { $_->TO_JSON(\%embed) } $requests->as_list; |
64 |
@req_list = map { $_->TO_JSON(\%embed) } @req_list; |
63 |
return $c->render( status => 200, openapi => \@results ); |
|
|
64 |
} |
65 |
} |
65 |
else |
66 |
|
66 |
{ |
67 |
# Format dates as required |
67 |
return $c->render( status => 200, openapi => $requests ); |
68 |
foreach(@req_list) { |
|
|
69 |
foreach my $field(@format_dates) { |
70 |
if (defined $_->{$field}) { |
71 |
$_->{$field} = format_sqldatetime($_->{$field}, undef, undef, 1); |
72 |
} |
73 |
} |
74 |
|
68 |
} |
75 |
} |
|
|
76 |
|
77 |
return $c->render( status => 200, openapi => \@req_list ); |
69 |
} |
78 |
} |
70 |
|
79 |
|
71 |
1; |
80 |
1; |
72 |
- |
|
|