View | Details | Raw Unified | Return to bug 18729
Collapse All | Expand All

(-)a/Koha/REST/V1/Holds.pm (+32 lines)
Lines 483-486 sub pickup_locations { Link Here
483
    };
483
    };
484
}
484
}
485
485
486
=head3 update_pickup_location
487
488
Method that handles modifying the pickup location of a Koha::Hold object
489
490
=cut
491
492
sub update_pickup_location {
493
    my $c = shift->openapi->valid_input or return;
494
495
    my $hold_id = $c->validation->param('hold_id');
496
    my $hold = Koha::Holds->find($hold_id);
497
498
    unless ($hold) {
499
        return $c->render(
500
            status  => 404,
501
            openapi => { error => "Hold not found" }
502
        );
503
    }
504
505
    return try {
506
        my $pickup_location = $c->req->json;
507
508
        $hold->branchcode($pickup_location)->store;
509
510
        return $c->render( status => 200, openapi => $pickup_location );
511
    }
512
    catch {
513
        $c->unhandled_exception($_);
514
    };
515
}
516
517
486
1;
518
1;
(-)a/api/v1/swagger/paths.json (+3 lines)
Lines 71-76 Link Here
71
  "/holds/{hold_id}/pickup_locations": {
71
  "/holds/{hold_id}/pickup_locations": {
72
    "$ref": "paths/holds.json#/~1holds~1{hold_id}~1pickup_locations"
72
    "$ref": "paths/holds.json#/~1holds~1{hold_id}~1pickup_locations"
73
  },
73
  },
74
  "/holds/{hold_id}/pickup_location": {
75
    "$ref": "paths/holds.json#/~1holds~1{hold_id}~1pickup_location"
76
  },
74
  "/items": {
77
  "/items": {
75
    "$ref": "paths/items.json#/~1items"
78
    "$ref": "paths/items.json#/~1items"
76
  },
79
  },
(-)a/api/v1/swagger/paths/holds.json (+73 lines)
Lines 702-706 Link Here
702
        }
702
        }
703
      }
703
      }
704
    }
704
    }
705
  },
706
  "/holds/{hold_id}/pickup_location": {
707
    "put": {
708
      "x-mojo-to": "Holds#update_pickup_location",
709
      "operationId": "updateHoldPickupLocation",
710
      "tags": ["holds"],
711
      "parameters": [
712
        {
713
          "$ref": "../parameters.json#/hold_id_pp"
714
        },
715
        {
716
          "name": "body",
717
          "in": "body",
718
          "description": "Pickup location",
719
          "required": true,
720
          "schema": {
721
            "type": "string"
722
          }
723
        }
724
      ],
725
      "produces": [
726
        "application/json"
727
      ],
728
      "responses": {
729
        "200": {
730
          "description": "The new pickup location value for the hold",
731
          "schema": {
732
            "type": "string"
733
          }
734
        },
735
        "401": {
736
          "description": "Authentication required",
737
          "schema": {
738
            "$ref": "../definitions.json#/error"
739
          }
740
        },
741
        "403": {
742
          "description": "Access forbidden",
743
          "schema": {
744
            "$ref": "../definitions.json#/error"
745
          }
746
        },
747
        "404": {
748
          "description": "Hold not found",
749
          "schema": {
750
            "$ref": "../definitions.json#/error"
751
          }
752
        },
753
        "409": {
754
          "description": "Unable to perform action on hold",
755
          "schema": {
756
            "$ref": "../definitions.json#/error"
757
          }
758
        },
759
        "500": {
760
          "description": "Internal error",
761
          "schema": {
762
            "$ref": "../definitions.json#/error"
763
          }
764
        },
765
        "503": {
766
          "description": "Under maintenance",
767
          "schema": {
768
            "$ref": "../definitions.json#/error"
769
          }
770
        }
771
      },
772
      "x-koha-authorization": {
773
        "permissions": {
774
          "reserveforothers": "place_holds"
775
        }
776
      }
777
    }
705
  }
778
  }
706
}
779
}
(-)a/koha-tmpl/intranet-tmpl/prog/js/holds.js (-3 / +2 lines)
Lines 224-235 $(document).ready(function() { Link Here
224
                    var cur_select = $(this);
224
                    var cur_select = $(this);
225
                    var res_id = $(this).attr('reserve_id');
225
                    var res_id = $(this).attr('reserve_id');
226
                    $(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>');
226
                    $(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>');
227
                    var api_url = '/api/v1/holds/'+res_id;
227
                    var api_url = '/api/v1/holds/' + encodeURIComponent(res_id) + '/pickup_location';
228
                    var update_info = JSON.stringify({ pickup_library_id: $(this).val(), priority: parseInt($(this).attr("priority"),10) });
229
                    $.ajax({
228
                    $.ajax({
230
                        method: "PUT",
229
                        method: "PUT",
231
                        url: api_url,
230
                        url: api_url,
232
                        data: update_info ,
231
                        data: $(this).val(),
233
                        success: function( data ){ holdsTable.api().ajax.reload(); },
232
                        success: function( data ){ holdsTable.api().ajax.reload(); },
234
                        error: function( jqXHR, textStatus, errorThrown) {
233
                        error: function( jqXHR, textStatus, errorThrown) {
235
                            alert('There was an error:'+textStatus+" "+errorThrown);
234
                            alert('There was an error:'+textStatus+" "+errorThrown);
(-)a/t/db_dependent/api/v1/holds.t (-2 / +53 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 12;
20
use Test::More tests => 13;
21
use Test::MockModule;
21
use Test::MockModule;
22
use Test::Mojo;
22
use Test::Mojo;
23
use t::lib::TestBuilder;
23
use t::lib::TestBuilder;
Lines 1026-1028 subtest 'add() tests' => sub { Link Here
1026
1026
1027
    $schema->storage->txn_rollback;
1027
    $schema->storage->txn_rollback;
1028
};
1028
};
1029
- 
1029
1030
1031
subtest 'PUT /holds/{hold_id}/pickup_location tests' => sub {
1032
1033
    plan tests => 4;
1034
1035
    $schema->storage->txn_begin;
1036
1037
    my $password = 'AbcdEFG123';
1038
1039
    my $library_1   =  $builder->build_object({ class => 'Koha::Libraries' });
1040
    my $library_2 = $builder->build_object({ class => 'Koha::Libraries' });
1041
1042
    my $patron = $builder->build_object(
1043
        { class => 'Koha::Patrons', value => { flags => 0 } } );
1044
    $patron->set_password( { password => $password, skip_validation => 1 } );
1045
    my $userid = $patron->userid;
1046
    $builder->build(
1047
        {
1048
            source => 'UserPermission',
1049
            value  => {
1050
                borrowernumber => $patron->borrowernumber,
1051
                module_bit     => 6,
1052
                code           => 'place_holds',
1053
            },
1054
        }
1055
    );
1056
1057
    # Disable logging
1058
    t::lib::Mocks::mock_preference( 'HoldsLog',      0 );
1059
    t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
1060
1061
    my $biblio = $builder->build_sample_biblio;
1062
    my $hold = Koha::Holds->find(
1063
        AddReserve(
1064
            {
1065
                branchcode     => $library_1->branchcode,
1066
                borrowernumber => $patron->borrowernumber,
1067
                biblionumber   => $biblio->biblionumber,
1068
                priority       => 1,
1069
            }
1070
        )
1071
    );
1072
1073
    $t->put_ok( "//$userid:$password@/api/v1/holds/"
1074
          . $hold->id
1075
          . "/pickup_location" => json => $library_2->branchcode )->status_is(200)->json_is($library_2->branchcode);
1076
1077
    is( $hold->discard_changes->branchcode->branchcode, $library_2->branchcode, 'pickup library adjusted correctly' );
1078
1079
    $schema->storage->txn_rollback;
1080
};

Return to bug 18729