Browse Source

Bug 28424: Fix patron credits route (POST)

This patch makes the route follow the coding guidelines and thus:
- Return the generated object
- Use the status code 201 for the response

To test:
1. Apply the tests patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/api/v1/patrons_accounts.t
=> FAIL: Tests fail. The reponse body and status is incorrect
3. Apply this patch
4. Repeat 2
=> SUCCESS: Tests pass!
5. Sign off :-D

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
21.05.x
Tomas Cohen Arazi 8 months ago
committed by Jonathan Druart
parent
commit
cfcc34fde7
  1. 7
      Koha/REST/V1/Patrons/Account.pm
  2. 2
      api/v1/swagger/paths/patrons_account.json

7
Koha/REST/V1/Patrons/Account.pm

@ -142,7 +142,12 @@ sub add_credit {
$credit->apply({ debits => [ $outstanding_debits->as_list ], offset_type => 'payment' });
}
return $c->render( status => 200, openapi => { account_line_id => $credit->id } );
$credit->discard_changes;
return $c->render(
status => 201,
openapi => $credit->to_api
);
}
catch {
$c->unhandled_exception($_);

2
api/v1/swagger/paths/patrons_account.json

@ -85,7 +85,7 @@
"application/json"
],
"responses": {
"200": {
"201": {
"description": "Credit added",
"schema": {
"type": "object"

Loading…
Cancel
Save