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

(-)a/Koha/REST/V1/Holds.pm (-34 / +36 lines)
Lines 143-185 sub add { Link Here
143
            );
143
            );
144
        }
144
        }
145
145
146
        # Validate pickup location
146
        # If the hold is being forced, no need to validate
147
        my $valid_pickup_location;
147
        unless( $can_override ){
148
        if ($item) {    # item-level hold
148
            # Validate pickup location
149
            $valid_pickup_location =
149
            my $valid_pickup_location;
150
              any { $_->branchcode eq $pickup_library_id }
150
            if ($item) {    # item-level hold
151
            $item->pickup_locations(
151
                $valid_pickup_location =
152
                { patron => $patron } )->as_list;
152
                  any { $_->branchcode eq $pickup_library_id }
153
        }
153
                $item->pickup_locations(
154
        else {
154
                    { patron => $patron } )->as_list;
155
            $valid_pickup_location =
155
            }
156
              any { $_->branchcode eq $pickup_library_id }
156
            else {
157
            $biblio->pickup_locations(
157
                $valid_pickup_location =
158
                { patron => $patron } )->as_list;
158
                  any { $_->branchcode eq $pickup_library_id }
159
        }
159
                $biblio->pickup_locations(
160
160
                    { patron => $patron } )->as_list;
161
        return $c->render(
162
            status  => 400,
163
            openapi => {
164
                error => 'The supplied pickup location is not valid'
165
            }
161
            }
166
        ) unless $valid_pickup_location || $can_override;
167
162
168
        my $can_place_hold
163
            return $c->render(
169
            = $item
164
                status  => 400,
170
            ? C4::Reserves::CanItemBeReserved( $patron, $item )
165
                openapi => {
171
            : C4::Reserves::CanBookBeReserved( $patron_id, $biblio_id );
166
                    error => 'The supplied pickup location is not valid'
167
                }
168
            ) unless $valid_pickup_location;
172
169
173
        if ( C4::Context->preference('maxreserves') && $patron->holds->count + 1 > C4::Context->preference('maxreserves') ) {
170
            my $can_place_hold
174
            $can_place_hold->{status} = 'tooManyReserves';
171
                = $item
175
        }
172
                ? C4::Reserves::CanItemBeReserved( $patron, $item )
173
                : C4::Reserves::CanBookBeReserved( $patron_id, $biblio_id );
176
174
177
        unless ( $can_override || $can_place_hold->{status} eq 'OK' ) {
175
            if ( C4::Context->preference('maxreserves') && $patron->holds->count + 1 > C4::Context->preference('maxreserves') ) {
178
            return $c->render(
176
                $can_place_hold->{status} = 'tooManyReserves';
179
                status => 403,
177
            }
180
                openapi =>
178
181
                    { error => "Hold cannot be placed. Reason: " . $can_place_hold->{status} }
179
            unless ( $can_place_hold->{status} eq 'OK' ) {
182
            );
180
                return $c->render(
181
                    status => 403,
182
                    openapi =>
183
                        { error => "Hold cannot be placed. Reason: " . $can_place_hold->{status} }
184
                );
185
            }
183
        }
186
        }
184
187
185
        my $priority = C4::Reserves::CalculatePriority($biblio_id);
188
        my $priority = C4::Reserves::CalculatePriority($biblio_id);
186
- 

Return to bug 33470