From 1f393e78f68d2f3675605341860daf4ef56fca8e Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Thu, 25 May 2023 17:27:33 +0200 Subject: [PATCH] Feature/improve error handling in delete user endpoint (#2000) * Improve error handling * Update changelog --- CHANGELOG.md | 1 + apps/api/src/app/user/user.service.ts | 32 +++++++++++++++++---------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 662e1f3cf..8f465d45b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Decreased the density of the `@angular/material` tables - Improved the breadcrumb navigation style in the blog post pages for mobile +- Improved the error handling in the delete user endpoint - Improved the style of the _Changelog & License_ button on the about page - Upgraded `ionicons` from version `6.1.2` to `7.1.0` diff --git a/apps/api/src/app/user/user.service.ts b/apps/api/src/app/user/user.service.ts index 56807e10a..26736e88d 100644 --- a/apps/api/src/app/user/user.service.ts +++ b/apps/api/src/app/user/user.service.ts @@ -304,21 +304,29 @@ export class UserService { } public async deleteUser(where: Prisma.UserWhereUniqueInput): Promise { - await this.prismaService.access.deleteMany({ - where: { OR: [{ granteeUserId: where.id }, { userId: where.id }] } - }); + try { + await this.prismaService.access.deleteMany({ + where: { OR: [{ granteeUserId: where.id }, { userId: where.id }] } + }); + } catch {} - await this.prismaService.account.deleteMany({ - where: { userId: where.id } - }); + try { + await this.prismaService.account.deleteMany({ + where: { userId: where.id } + }); + } catch {} - await this.prismaService.analytics.delete({ - where: { userId: where.id } - }); + try { + await this.prismaService.analytics.delete({ + where: { userId: where.id } + }); + } catch {} - await this.prismaService.order.deleteMany({ - where: { userId: where.id } - }); + try { + await this.prismaService.order.deleteMany({ + where: { userId: where.id } + }); + } catch {} try { await this.prismaService.settings.delete({