|
Lines 29-35
use Koha::DateUtils qw( dt_from_string output_pref );
Link Here
|
| 29 |
|
29 |
|
| 30 |
Koha::REST::V1::ReturnClaims |
30 |
Koha::REST::V1::ReturnClaims |
| 31 |
|
31 |
|
| 32 |
=head2 Operations |
32 |
=head1 API |
|
|
33 |
|
| 34 |
=head2 Methods |
| 33 |
|
35 |
|
| 34 |
=head3 claim_returned |
36 |
=head3 claim_returned |
| 35 |
|
37 |
|
|
Lines 53-59
sub claim_returned {
Link Here
|
| 53 |
my $checkout = Koha::Checkouts->find( { itemnumber => $itemnumber } ); |
55 |
my $checkout = Koha::Checkouts->find( { itemnumber => $itemnumber } ); |
| 54 |
|
56 |
|
| 55 |
return $c->render( |
57 |
return $c->render( |
| 56 |
openapi => { error => "Not found - Checkout not found" }, |
58 |
openapi => { error => "Checkout not found" }, |
| 57 |
status => 404 |
59 |
status => 404 |
| 58 |
) unless $checkout; |
60 |
) unless $checkout; |
| 59 |
|
61 |
|
|
Lines 100-151
Update the notes of an existing claim
Link Here
|
| 100 |
=cut |
102 |
=cut |
| 101 |
|
103 |
|
| 102 |
sub update_notes { |
104 |
sub update_notes { |
| 103 |
my $c = shift->openapi->valid_input or return; |
105 |
my $c = shift->openapi->valid_input or return; |
| 104 |
my $input = $c->validation->output; |
106 |
|
| 105 |
my $body = $c->validation->param('body'); |
107 |
my $claim_id = $c->validation->param('claim_id'); |
|
|
108 |
my $body = $c->validation->param('body'); |
| 109 |
|
| 110 |
my $claim = Koha::Checkouts::ReturnClaims->find( $claim_id ); |
| 111 |
|
| 112 |
return $c->render( |
| 113 |
status => 404, |
| 114 |
openapi => { |
| 115 |
error => "Claim not found" |
| 116 |
} |
| 117 |
) unless $claim; |
| 106 |
|
118 |
|
| 107 |
return try { |
119 |
return try { |
| 108 |
my $id = $input->{claim_id}; |
|
|
| 109 |
my $updated_by = $body->{updated_by}; |
120 |
my $updated_by = $body->{updated_by}; |
| 110 |
my $notes = $body->{notes}; |
121 |
my $notes = $body->{notes}; |
| 111 |
|
122 |
|
| 112 |
$updated_by ||= |
123 |
my $user = $c->stash('koha.user'); |
| 113 |
C4::Context->userenv ? C4::Context->userenv->{number} : undef; |
124 |
$updated_by //= $user->borrowernumber; |
| 114 |
|
|
|
| 115 |
my $claim = Koha::Checkouts::ReturnClaims->find($id); |
| 116 |
|
| 117 |
return $c->render( |
| 118 |
openapi => { error => "Not found - Claim not found" }, |
| 119 |
status => 404 |
| 120 |
) unless $claim; |
| 121 |
|
125 |
|
| 122 |
$claim->set( |
126 |
$claim->set( |
| 123 |
{ |
127 |
{ |
| 124 |
notes => $notes, |
128 |
notes => $notes, |
| 125 |
updated_by => $updated_by, |
129 |
updated_by => $updated_by |
| 126 |
updated_on => dt_from_string(), |
|
|
| 127 |
} |
130 |
} |
| 128 |
); |
131 |
)->store; |
| 129 |
$claim->store(); |
132 |
$claim->discard_changes; |
| 130 |
|
|
|
| 131 |
my $data = $claim->unblessed; |
| 132 |
|
| 133 |
my $c_dt = dt_from_string( $data->{created_on} ); |
| 134 |
my $u_dt = dt_from_string( $data->{updated_on} ); |
| 135 |
|
| 136 |
$data->{created_on_formatted} = output_pref( { dt => $c_dt } ); |
| 137 |
$data->{updated_on_formatted} = output_pref( { dt => $u_dt } ); |
| 138 |
|
133 |
|
| 139 |
$data->{created_on} = $c_dt->iso8601; |
134 |
return $c->render( |
| 140 |
$data->{updated_on} = $u_dt->iso8601; |
135 |
status => 200, |
| 141 |
|
136 |
openapi => $claim->to_api |
| 142 |
return $c->render( openapi => $data, status => 200 ); |
137 |
); |
| 143 |
} |
138 |
} |
| 144 |
catch { |
139 |
catch { |
| 145 |
if ( $_->isa('DBIx::Class::Exception') ) { |
140 |
if ( $_->isa('Koha::Exceptions::Exception') ) { |
| 146 |
return $c->render( |
141 |
return $c->render( |
| 147 |
status => 500, |
142 |
status => 500, |
| 148 |
openapi => { error => $_->{msg} } |
143 |
openapi => { error => "$_" } |
| 149 |
); |
144 |
); |
| 150 |
} |
145 |
} |
| 151 |
else { |
146 |
else { |
|
Lines 165-204
Marks a claim as resolved
Link Here
|
| 165 |
|
160 |
|
| 166 |
sub resolve_claim { |
161 |
sub resolve_claim { |
| 167 |
my $c = shift->openapi->valid_input or return; |
162 |
my $c = shift->openapi->valid_input or return; |
| 168 |
my $input = $c->validation->output; |
163 |
|
| 169 |
my $body = $c->validation->param('body'); |
164 |
my $claim_id = $c->validation->param('claim_id'); |
|
|
165 |
my $body = $c->validation->param('body'); |
| 166 |
|
| 167 |
my $claim = Koha::Checkouts::ReturnClaims->find($claim_id); |
| 168 |
|
| 169 |
return $c->render( |
| 170 |
status => 404, |
| 171 |
openapi => { |
| 172 |
error => "Claim not found" |
| 173 |
} |
| 174 |
) unless $claim; |
| 170 |
|
175 |
|
| 171 |
return try { |
176 |
return try { |
| 172 |
my $id = $input->{claim_id}; |
177 |
|
| 173 |
my $resolved_by = $body->{updated_by}; |
178 |
my $resolved_by = $body->{updated_by}; |
| 174 |
my $resolution = $body->{resolution}; |
179 |
my $resolution = $body->{resolution}; |
| 175 |
|
180 |
|
| 176 |
$resolved_by ||= |
181 |
my $user = $c->stash('koha.user'); |
| 177 |
C4::Context->userenv ? C4::Context->userenv->{number} : undef; |
182 |
$resolved_by //= $user->borrowernumber; |
| 178 |
|
|
|
| 179 |
my $claim = Koha::Checkouts::ReturnClaims->find($id); |
| 180 |
|
| 181 |
return $c->render( |
| 182 |
openapi => { error => "Not found - Claim not found" }, |
| 183 |
status => 404 |
| 184 |
) unless $claim; |
| 185 |
|
183 |
|
| 186 |
$claim->set( |
184 |
$claim->set( |
| 187 |
{ |
185 |
{ |
| 188 |
resolution => $resolution, |
186 |
resolution => $resolution, |
| 189 |
resolved_by => $resolved_by, |
187 |
resolved_by => $resolved_by, |
| 190 |
resolved_on => dt_from_string(), |
188 |
resolved_on => \'NOW()', |
| 191 |
} |
189 |
} |
| 192 |
); |
190 |
)->store; |
| 193 |
$claim->store(); |
191 |
$claim->discard_changes; |
| 194 |
|
192 |
|
| 195 |
return $c->render( openapi => $claim, status => 200 ); |
193 |
return $c->render( |
|
|
194 |
status => 200, |
| 195 |
openapi => $claim->to_api |
| 196 |
); |
| 196 |
} |
197 |
} |
| 197 |
catch { |
198 |
catch { |
| 198 |
if ( $_->isa('DBIx::Class::Exception') ) { |
199 |
if ( $_->isa('Koha::Exceptions::Exception') ) { |
| 199 |
return $c->render( |
200 |
return $c->render( |
| 200 |
status => 500, |
201 |
status => 500, |
| 201 |
openapi => { error => $_->{msg} } |
202 |
openapi => { error => "$_" } |
| 202 |
); |
203 |
); |
| 203 |
} |
204 |
} |
| 204 |
else { |
205 |
else { |
|
Lines 217-244
Deletes the claim from the database
Link Here
|
| 217 |
=cut |
218 |
=cut |
| 218 |
|
219 |
|
| 219 |
sub delete_claim { |
220 |
sub delete_claim { |
| 220 |
my $c = shift->openapi->valid_input or return; |
221 |
my $c = shift->openapi->valid_input or return; |
| 221 |
my $input = $c->validation->output; |
|
|
| 222 |
|
222 |
|
| 223 |
return try { |
223 |
return try { |
| 224 |
my $id = $input->{claim_id}; |
|
|
| 225 |
|
224 |
|
| 226 |
my $claim = Koha::Checkouts::ReturnClaims->find($id); |
225 |
my $claim = Koha::Checkouts::ReturnClaims->find( $c->validation->param('claim_id') ); |
| 227 |
|
226 |
|
| 228 |
return $c->render( |
227 |
return $c->render( |
| 229 |
openapi => { error => "Not found - Claim not found" }, |
228 |
status => 404, |
| 230 |
status => 404 |
229 |
openapi => { error => "Claim not found" } |
| 231 |
) unless $claim; |
230 |
) unless $claim; |
| 232 |
|
231 |
|
| 233 |
$claim->delete(); |
232 |
$claim->delete(); |
| 234 |
|
233 |
|
| 235 |
return $c->render( openapi => $claim, status => 200 ); |
234 |
return $c->render( |
|
|
235 |
status => 204, |
| 236 |
openapi => {} |
| 237 |
); |
| 236 |
} |
238 |
} |
| 237 |
catch { |
239 |
catch { |
| 238 |
if ( $_->isa('DBIx::Class::Exception') ) { |
240 |
if ( $_->isa('Koha::Exceptions::Exception') ) { |
| 239 |
return $c->render( |
241 |
return $c->render( |
| 240 |
status => 500, |
242 |
status => 500, |
| 241 |
openapi => { error => $_->{msg} } |
243 |
openapi => { error => "$_" } |
| 242 |
); |
244 |
); |
| 243 |
} |
245 |
} |
| 244 |
else { |
246 |
else { |