From 13788f5060d544b3601b8e26a9d719a45cf2731a Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Mon, 27 Jul 2026 18:52:00 +0200 Subject: [PATCH] Bugfix/resolve exception in user service for non-existent user (#7435) * Resolve exception for non-existent user * Update changelog --- CHANGELOG.md | 4 +++ apps/api/src/app/user/user.service.ts | 44 +++++++++++++++------------ 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e93211b3..286b2a27c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Refreshed the cryptocurrencies list - Upgraded `prettier` from version `3.8.4` to `3.9.6` +### Fixed + +- Resolved an exception in the user service when getting a non-existent user + ## 3.34.0 - 2026-07-25 ### Changed diff --git a/apps/api/src/app/user/user.service.ts b/apps/api/src/app/user/user.service.ts index 6304c81ea..648f36cbf 100644 --- a/apps/api/src/app/user/user.service.ts +++ b/apps/api/src/app/user/user.service.ts @@ -231,22 +231,7 @@ export class UserService { public async user( userWhereUniqueInput: Prisma.UserWhereUniqueInput ): Promise { - const { - _count, - accessesGet, - accessToken, - accounts, - analytics, - authChallenge, - createdAt, - id, - provider, - role, - settings, - subscriptions, - thirdPartyId, - updatedAt - } = await this.prismaService.user.findUnique({ + const userFromDatabase = await this.prismaService.user.findUnique({ include: { _count: { select: { @@ -264,6 +249,27 @@ export class UserService { where: userWhereUniqueInput }); + if (!userFromDatabase) { + return null; + } + + const { + _count, + accessesGet, + accessToken, + accounts, + analytics, + authChallenge, + createdAt, + id, + provider, + role, + settings, + subscriptions, + thirdPartyId, + updatedAt + } = userFromDatabase; + const activitiesCount = _count?.activities ?? 0; const user: UserWithSettings = { @@ -283,16 +289,16 @@ export class UserService { analytics?.dataProviderGhostfolioDailyRequests }; - if (user?.settings) { + if (user.settings) { if (!user.settings.settings) { user.settings.settings = {}; } - } else if (user) { + } else { // Set default settings if needed user.settings = { settings: {}, updatedAt: new Date(), - userId: user?.id + userId: user.id }; }