Browse Source

Bugfix/resolve exception in user service for non-existent user (#7435)

* Resolve exception for non-existent user

* Update changelog
pull/7442/head^2
Thomas Kaul 3 days ago
committed by GitHub
parent
commit
13788f5060
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 4
      CHANGELOG.md
  2. 44
      apps/api/src/app/user/user.service.ts

4
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

44
apps/api/src/app/user/user.service.ts

@ -231,22 +231,7 @@ export class UserService {
public async user(
userWhereUniqueInput: Prisma.UserWhereUniqueInput
): Promise<UserWithSettings | null> {
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
};
}

Loading…
Cancel
Save