Bug 40550: Add cancellation_bulk API endpoint
Signed-off-by: Phillip Berg <phillip.berg@mainlib.org> Signed-off-by: Andrew Fuerste Henry <andrew@bywatersolutions.com> Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
parent
353e3b6da8
commit
09673df356
|
|
@ -347,6 +347,50 @@ sub delete {
|
|||
};
|
||||
}
|
||||
|
||||
=head3 delete_bulk
|
||||
|
||||
Method that handles deleting multiple Koha::Hold objects
|
||||
|
||||
=cut
|
||||
|
||||
sub delete_bulk {
|
||||
my $c = shift->openapi->valid_input or return;
|
||||
|
||||
my $body = $c->req->json;
|
||||
my $hold_ids = ($body) ? $body->{hold_ids} : undef;
|
||||
my $cancellation_reason = ($body) ? $body->{cancellation_reason} : undef;
|
||||
|
||||
return $c->render_resource_not_found("Hold")
|
||||
unless $hold_ids;
|
||||
|
||||
foreach my $hold_id (@$hold_ids) {
|
||||
my $hold = Koha::Holds->find($hold_id);
|
||||
return $c->render_resource_not_found( "Hold", "id", $hold_id )
|
||||
unless $hold;
|
||||
}
|
||||
|
||||
return try {
|
||||
Koha::Database->new->schema->txn_do(
|
||||
sub {
|
||||
foreach my $hold_id (@$hold_ids) {
|
||||
my $hold = Koha::Holds->find($hold_id);
|
||||
$hold->cancel( { cancellation_reason => $cancellation_reason } );
|
||||
}
|
||||
$c->res->headers->location( $c->req->url->to_string );
|
||||
return $c->render(
|
||||
status => 204,
|
||||
openapi => {
|
||||
hold_ids => $hold_ids,
|
||||
cancellation_reason => $cancellation_reason,
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
} catch {
|
||||
$c->unhandled_exception($_);
|
||||
};
|
||||
}
|
||||
|
||||
=head3 suspend
|
||||
|
||||
Method that handles suspending a hold
|
||||
|
|
|
|||
|
|
@ -343,6 +343,64 @@
|
|||
x-koha-authorization:
|
||||
permissions:
|
||||
reserveforothers: place_holds
|
||||
"/holds/cancellation_bulk":
|
||||
delete:
|
||||
x-mojo-to: Holds#delete_bulk
|
||||
operationId: deleteHolds
|
||||
tags:
|
||||
- holds
|
||||
summary: Cancel holds
|
||||
parameters:
|
||||
- name: body
|
||||
in: body
|
||||
description: Hold ids
|
||||
required: true
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
cancellation_reason:
|
||||
description: Cancellation reason
|
||||
type: string
|
||||
hold_ids:
|
||||
type: array
|
||||
items:
|
||||
type: integer
|
||||
additionalProperties: false
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"204":
|
||||
description: Holds deleted
|
||||
"400":
|
||||
description: Bad request
|
||||
schema:
|
||||
$ref: "../swagger.yaml#/definitions/error"
|
||||
"401":
|
||||
description: Authentication required
|
||||
schema:
|
||||
$ref: "../swagger.yaml#/definitions/error"
|
||||
"403":
|
||||
description: Hold not allowed
|
||||
schema:
|
||||
$ref: "../swagger.yaml#/definitions/error"
|
||||
"404":
|
||||
description: Hold not found
|
||||
schema:
|
||||
$ref: "../swagger.yaml#/definitions/error"
|
||||
"500":
|
||||
description: |
|
||||
Internal server error. Possible `error_code` attribute values:
|
||||
|
||||
* `internal_server_error`
|
||||
schema:
|
||||
$ref: "../swagger.yaml#/definitions/error"
|
||||
"503":
|
||||
description: Under maintenance
|
||||
schema:
|
||||
$ref: "../swagger.yaml#/definitions/error"
|
||||
x-koha-authorization:
|
||||
permissions:
|
||||
reserveforothers: place_holds
|
||||
"/holds/{hold_id}":
|
||||
patch:
|
||||
x-mojo-to: Holds#edit
|
||||
|
|
|
|||
|
|
@ -415,6 +415,8 @@ paths:
|
|||
$ref: ./paths/holds.yaml#/~1holds
|
||||
"/holds/suspension_bulk":
|
||||
$ref: "./paths/holds.yaml#/~1holds~1suspension_bulk"
|
||||
"/holds/cancellation_bulk":
|
||||
$ref: "./paths/holds.yaml#/~1holds~1cancellation_bulk"
|
||||
"/holds/{hold_id}":
|
||||
$ref: "./paths/holds.yaml#/~1holds~1{hold_id}"
|
||||
"/holds/{hold_id}/pickup_location":
|
||||
|
|
|
|||
Loading…
Reference in New Issue