This patch adds a route to overwrite the current pickup location.
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
};
}
+=head3 update_pickup_location
+
+Method that handles modifying the pickup location of a Koha::Hold object
+
+=cut
+
+sub update_pickup_location {
+ my $c = shift->openapi->valid_input or return;
+
+ my $hold_id = $c->validation->param('hold_id');
+ my $hold = Koha::Holds->find($hold_id);
+
+ unless ($hold) {
+ return $c->render(
+ status => 404,
+ openapi => { error => "Hold not found" }
+ );
+ }
+
+ return try {
+ my $pickup_location = $c->req->json;
+
+ $hold->branchcode($pickup_location)->store;
+
+ return $c->render( status => 200, openapi => $pickup_location );
+ }
+ catch {
+ $c->unhandled_exception($_);
+ };
+}
+
+
1;
"/holds/{hold_id}/pickup_locations": {
"$ref": "paths/holds.json#/~1holds~1{hold_id}~1pickup_locations"
},
+ "/holds/{hold_id}/pickup_location": {
+ "$ref": "paths/holds.json#/~1holds~1{hold_id}~1pickup_location"
+ },
"/items": {
"$ref": "paths/items.json#/~1items"
},
}
}
}
+ },
+ "/holds/{hold_id}/pickup_location": {
+ "put": {
+ "x-mojo-to": "Holds#update_pickup_location",
+ "operationId": "updateHoldPickupLocation",
+ "tags": ["holds"],
+ "parameters": [
+ {
+ "$ref": "../parameters.json#/hold_id_pp"
+ },
+ {
+ "name": "body",
+ "in": "body",
+ "description": "Pickup location",
+ "required": true,
+ "schema": {
+ "type": "string"
+ }
+ }
+ ],
+ "produces": [
+ "application/json"
+ ],
+ "responses": {
+ "200": {
+ "description": "The new pickup location value for the hold",
+ "schema": {
+ "type": "string"
+ }
+ },
+ "401": {
+ "description": "Authentication required",
+ "schema": {
+ "$ref": "../definitions.json#/error"
+ }
+ },
+ "403": {
+ "description": "Access forbidden",
+ "schema": {
+ "$ref": "../definitions.json#/error"
+ }
+ },
+ "404": {
+ "description": "Hold not found",
+ "schema": {
+ "$ref": "../definitions.json#/error"
+ }
+ },
+ "409": {
+ "description": "Unable to perform action on hold",
+ "schema": {
+ "$ref": "../definitions.json#/error"
+ }
+ },
+ "500": {
+ "description": "Internal error",
+ "schema": {
+ "$ref": "../definitions.json#/error"
+ }
+ },
+ "503": {
+ "description": "Under maintenance",
+ "schema": {
+ "$ref": "../definitions.json#/error"
+ }
+ }
+ },
+ "x-koha-authorization": {
+ "permissions": {
+ "reserveforothers": "place_holds"
+ }
+ }
+ }
}
}
var cur_select = $(this);
var res_id = $(this).attr('reserve_id');
$(this).after('<div id="updating_reserveno'+res_id+'" class="waiting"><img src="/intranet-tmpl/prog/img/spinner-small.gif" alt="" /><span class="waiting_msg"></span></div>');
- var api_url = '/api/v1/holds/'+res_id;
- var update_info = JSON.stringify({ pickup_library_id: $(this).val(), priority: parseInt($(this).attr("priority"),10) });
+ var api_url = '/api/v1/holds/' + encodeURIComponent(res_id) + '/pickup_location';
$.ajax({
method: "PUT",
url: api_url,
- data: update_info ,
+ data: $(this).val(),
success: function( data ){ holdsTable.api().ajax.reload(); },
error: function( jqXHR, textStatus, errorThrown) {
alert('There was an error:'+textStatus+" "+errorThrown);
use Modern::Perl;
-use Test::More tests => 12;
+use Test::More tests => 13;
use Test::MockModule;
use Test::Mojo;
use t::lib::TestBuilder;
$schema->storage->txn_rollback;
};
+
+
+subtest 'PUT /holds/{hold_id}/pickup_location tests' => sub {
+
+ plan tests => 4;
+
+ $schema->storage->txn_begin;
+
+ my $password = 'AbcdEFG123';
+
+ my $library_1 = $builder->build_object({ class => 'Koha::Libraries' });
+ my $library_2 = $builder->build_object({ class => 'Koha::Libraries' });
+
+ my $patron = $builder->build_object(
+ { class => 'Koha::Patrons', value => { flags => 0 } } );
+ $patron->set_password( { password => $password, skip_validation => 1 } );
+ my $userid = $patron->userid;
+ $builder->build(
+ {
+ source => 'UserPermission',
+ value => {
+ borrowernumber => $patron->borrowernumber,
+ module_bit => 6,
+ code => 'place_holds',
+ },
+ }
+ );
+
+ # Disable logging
+ t::lib::Mocks::mock_preference( 'HoldsLog', 0 );
+ t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
+
+ my $biblio = $builder->build_sample_biblio;
+ my $hold = Koha::Holds->find(
+ AddReserve(
+ {
+ branchcode => $library_1->branchcode,
+ borrowernumber => $patron->borrowernumber,
+ biblionumber => $biblio->biblionumber,
+ priority => 1,
+ }
+ )
+ );
+
+ $t->put_ok( "//$userid:$password@/api/v1/holds/"
+ . $hold->id
+ . "/pickup_location" => json => $library_2->branchcode )->status_is(200)->json_is($library_2->branchcode);
+
+ is( $hold->discard_changes->branchcode->branchcode, $library_2->branchcode, 'pickup library adjusted correctly' );
+
+ $schema->storage->txn_rollback;
+};