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

(-)a/Koha/REST/V1/Patrons.pm (-4 / +33 lines)
Lines 330-339 sub delete { Link Here
330
330
331
    return try {
331
    return try {
332
332
333
        $patron->delete;
333
        if ( $patron->checkouts->count > 0 ) {
334
        return $c->render(
334
            return $c->render(
335
            status  => 204,
335
                status  => 409,
336
            openapi => q{}
336
                openapi => { error => 'Pending checkouts prevent deletion' }
337
            );
338
        }
339
340
        my $account = $patron->account;
341
342
        if ( $account->outstanding_debits->total_outstanding > 0 ) {
343
            return $c->render(
344
                status  => 409,
345
                openapi => { error => 'Pending debts prevent deletion' }
346
            );
347
        }
348
349
        if ( $patron->guarantee_relationships->count > 0 ) {
350
            return $c->render(
351
                status  => 409,
352
                openapi => { error => 'Patron is a guarantor and it prevents deletion' }
353
            );
354
        }
355
356
        $patron->_result->result_source->schema->txn_do(
357
            sub {
358
                $patron->move_to_deleted;
359
                $patron->delete;
360
361
                return $c->render(
362
                    status  => 204,
363
                    openapi => q{}
364
                );
365
            }
337
        );
366
        );
338
    } catch {
367
    } catch {
339
        if ( blessed $_ && $_->isa('Koha::Exceptions::Patron::FailedDeleteAnonymousPatron') ) {
368
        if ( blessed $_ && $_->isa('Koha::Exceptions::Patron::FailedDeleteAnonymousPatron') ) {
(-)a/api/v1/swagger/paths/patrons.yaml (-1 / +8 lines)
Lines 546-551 Link Here
546
        description: Patron not found
546
        description: Patron not found
547
        schema:
547
        schema:
548
          $ref: ../definitions.yaml#/error
548
          $ref: ../definitions.yaml#/error
549
      "409":
550
        description: Conflict
551
        schema:
552
          $ref: ../definitions.yaml#/error
553
      "500":
554
        description: Internal server error
555
        schema:
556
          $ref: ../definitions.yaml#/error
549
    x-koha-authorization:
557
    x-koha-authorization:
550
      permissions:
558
      permissions:
551
        borrowers: delete_borrowers
559
        borrowers: delete_borrowers
552
- 

Return to bug 29018