From a3595fa142f43611f72909c05cc0879c5f4bda36 Mon Sep 17 00:00:00 2001 From: Matt Blenkinsop Date: Thu, 5 Jun 2025 13:39:49 +0100 Subject: [PATCH] Bug 40082: Use the new duplicate checking method in the API --- Koha/REST/V1/Patrons.pm | 12 ++++++++++++ api/v1/swagger/paths/patrons.yaml | 1 + 2 files changed, 13 insertions(+) diff --git a/Koha/REST/V1/Patrons.pm b/Koha/REST/V1/Patrons.pm index 9d25ef7cba5..6e86c4634a8 100644 --- a/Koha/REST/V1/Patrons.pm +++ b/Koha/REST/V1/Patrons.pm @@ -108,6 +108,18 @@ sub add { my $extended_attributes = delete $body->{extended_attributes} // []; + my $confirm_not_duplicate = $c->req->headers->header('x-confirm-not-duplicate'); + if ( !$confirm_not_duplicate ) { + my $match_result = + Koha::Patrons->check_for_existing_matches( Koha::Patron->new_from_api($body)->unblessed ); + if ( $match_result->{duplicate_found} ) { + return $c->render( + status => 409, + openapi => { error => 'A patron record matching these details already exists' } + ); + } + } + my $patron = Koha::Patron->new_from_api($body)->store; my $overrides = $c->stash('koha.overrides'); diff --git a/api/v1/swagger/paths/patrons.yaml b/api/v1/swagger/paths/patrons.yaml index a7df190ba3e..6dcd8e71979 100644 --- a/api/v1/swagger/paths/patrons.yaml +++ b/api/v1/swagger/paths/patrons.yaml @@ -413,6 +413,7 @@ - patrons summary: Add patron parameters: + - $ref: "../swagger.yaml#/parameters/confirm_not_duplicate_header" - name: body in: body description: A JSON object containing information about the new patron -- 2.48.1