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

(-)a/Koha/REST/V1/Holds.pm (+32 lines)
Lines 508-511 sub pickup_locations { Link Here
508
    };
508
    };
509
}
509
}
510
510
511
=head3 update_pickup_location
512
513
Method that handles modifying the pickup location of a Koha::Hold object
514
515
=cut
516
517
sub update_pickup_location {
518
    my $c = shift->openapi->valid_input or return;
519
520
    my $hold_id = $c->validation->param('hold_id');
521
    my $hold = Koha::Holds->find($hold_id);
522
523
    unless ($hold) {
524
        return $c->render(
525
            status  => 404,
526
            openapi => { error => "Hold not found" }
527
        );
528
    }
529
530
    return try {
531
        my $pickup_location = $c->req->json;
532
533
        $hold->branchcode($pickup_location)->store;
534
535
        return $c->render( status => 200, openapi => $pickup_location );
536
    }
537
    catch {
538
        $c->unhandled_exception($_);
539
    };
540
}
541
542
511
1;
543
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 1054-1056 subtest 'add() tests' => sub { Link Here
1054
1054
1055
    $schema->storage->txn_rollback;
1055
    $schema->storage->txn_rollback;
1056
};
1056
};
1057
- 
1057
1058
1059
subtest 'PUT /holds/{hold_id}/pickup_location tests' => sub {
1060
1061
    plan tests => 4;
1062
1063
    $schema->storage->txn_begin;
1064
1065
    my $password = 'AbcdEFG123';
1066
1067
    my $library_1   =  $builder->build_object({ class => 'Koha::Libraries' });
1068
    my $library_2 = $builder->build_object({ class => 'Koha::Libraries' });
1069
1070
    my $patron = $builder->build_object(
1071
        { class => 'Koha::Patrons', value => { flags => 0 } } );
1072
    $patron->set_password( { password => $password, skip_validation => 1 } );
1073
    my $userid = $patron->userid;
1074
    $builder->build(
1075
        {
1076
            source => 'UserPermission',
1077
            value  => {
1078
                borrowernumber => $patron->borrowernumber,
1079
                module_bit     => 6,
1080
                code           => 'place_holds',
1081
            },
1082
        }
1083
    );
1084
1085
    # Disable logging
1086
    t::lib::Mocks::mock_preference( 'HoldsLog',      0 );
1087
    t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
1088
1089
    my $biblio = $builder->build_sample_biblio;
1090
    my $hold = Koha::Holds->find(
1091
        AddReserve(
1092
            {
1093
                branchcode     => $library_1->branchcode,
1094
                borrowernumber => $patron->borrowernumber,
1095
                biblionumber   => $biblio->biblionumber,
1096
                priority       => 1,
1097
            }
1098
        )
1099
    );
1100
1101
    $t->put_ok( "//$userid:$password@/api/v1/holds/"
1102
          . $hold->id
1103
          . "/pickup_location" => json => $library_2->branchcode )->status_is(200)->json_is($library_2->branchcode);
1104
1105
    is( $hold->discard_changes->branchcode->branchcode, $library_2->branchcode, 'pickup library adjusted correctly' );
1106
1107
    $schema->storage->txn_rollback;
1108
};

Return to bug 18729