From 6e9b55dfac5d61f2dcc35bab516931b8940dd840 Mon Sep 17 00:00:00 2001 From: Aleksandar Date: Tue, 3 Sep 2024 01:44:56 +0300 Subject: [PATCH] chore: Disallow account deletion if there are active recurring payments --- apps/api/src/auth/auth.service.ts | 6 ++++++ apps/api/src/person/person.service.ts | 1 + 2 files changed, 7 insertions(+) diff --git a/apps/api/src/auth/auth.service.ts b/apps/api/src/auth/auth.service.ts index 6d413f50..412f5243 100644 --- a/apps/api/src/auth/auth.service.ts +++ b/apps/api/src/auth/auth.service.ts @@ -502,6 +502,12 @@ export class AuthService { ) } + if (user.recurringDonations.length) { + throw new ForbiddenException( + `Account cannot be deleted due to active recurring payments. Please cancel all recurring payments before deleting this account`, + ) + } + return this.authenticateAdmin() .then(() => this.admin.users.del({ id: keycloakId })) .then(() => this.personService.softDelete(user.id)) diff --git a/apps/api/src/person/person.service.ts b/apps/api/src/person/person.service.ts index 17aee7de..8d8197a2 100644 --- a/apps/api/src/person/person.service.ts +++ b/apps/api/src/person/person.service.ts @@ -125,6 +125,7 @@ export class PersonService { company: true, beneficiaries: { select: { id: true } }, organizer: { select: { id: true } }, + recurringDonations: { select: { id: true } }, }, }) }