refactor: metadata entity (#17492)

This commit is contained in:
Jason Rasmussen
2025-04-09 11:45:30 -04:00
committed by GitHub
parent 3e372500b0
commit 206545356d
14 changed files with 120 additions and 148 deletions

View File

@@ -1,10 +1,10 @@
import { BadRequestException, ForbiddenException, UnauthorizedException } from '@nestjs/common';
import { DateTime } from 'luxon';
import { AuthDto, SignUpDto } from 'src/dtos/auth.dto';
import { UserMetadataEntity } from 'src/entities/user-metadata.entity';
import { UserEntity } from 'src/entities/user.entity';
import { AuthType, Permission } from 'src/enum';
import { AuthService } from 'src/services/auth.service';
import { UserMetadataItem } from 'src/types';
import { sharedLinkStub } from 'test/fixtures/shared-link.stub';
import { systemConfigStub } from 'test/fixtures/system-config.stub';
import { userStub } from 'test/fixtures/user.stub';
@@ -230,7 +230,7 @@ describe('AuthService', () => {
...dto,
id: 'admin',
createdAt: new Date('2021-01-01'),
metadata: [] as UserMetadataEntity[],
metadata: [] as UserMetadataItem[],
} as UserEntity);
await expect(sut.adminSignUp(dto)).resolves.toMatchObject({

View File

@@ -357,8 +357,6 @@ describe(NotificationService.name, () => {
{
key: UserMetadataKey.PREFERENCES,
value: { emailNotifications: { enabled: false, albumInvite: true } },
userId: userStub.user1.id,
user: userStub.user1,
},
],
});
@@ -374,8 +372,6 @@ describe(NotificationService.name, () => {
{
key: UserMetadataKey.PREFERENCES,
value: { emailNotifications: { enabled: true, albumInvite: false } },
userId: userStub.user1.id,
user: userStub.user1,
},
],
});
@@ -391,8 +387,6 @@ describe(NotificationService.name, () => {
{
key: UserMetadataKey.PREFERENCES,
value: { emailNotifications: { enabled: true, albumInvite: true } },
userId: userStub.user1.id,
user: userStub.user1,
},
],
});
@@ -414,8 +408,6 @@ describe(NotificationService.name, () => {
{
key: UserMetadataKey.PREFERENCES,
value: { emailNotifications: { enabled: true, albumInvite: true } },
userId: userStub.user1.id,
user: userStub.user1,
},
],
});
@@ -443,8 +435,6 @@ describe(NotificationService.name, () => {
{
key: UserMetadataKey.PREFERENCES,
value: { emailNotifications: { enabled: true, albumInvite: true } },
userId: userStub.user1.id,
user: userStub.user1,
},
],
});
@@ -476,8 +466,6 @@ describe(NotificationService.name, () => {
{
key: UserMetadataKey.PREFERENCES,
value: { emailNotifications: { enabled: true, albumInvite: true } },
userId: userStub.user1.id,
user: userStub.user1,
},
],
});
@@ -536,8 +524,6 @@ describe(NotificationService.name, () => {
{
key: UserMetadataKey.PREFERENCES,
value: { emailNotifications: { enabled: false, albumUpdate: true } },
user: userStub.user1,
userId: userStub.user1.id,
},
],
});
@@ -559,8 +545,6 @@ describe(NotificationService.name, () => {
{
key: UserMetadataKey.PREFERENCES,
value: { emailNotifications: { enabled: true, albumUpdate: false } },
user: userStub.user1,
userId: userStub.user1.id,
},
],
});

View File

@@ -8,12 +8,11 @@ import { LicenseKeyDto, LicenseResponseDto } from 'src/dtos/license.dto';
import { UserPreferencesResponseDto, UserPreferencesUpdateDto, mapPreferences } from 'src/dtos/user-preferences.dto';
import { CreateProfileImageResponseDto } from 'src/dtos/user-profile.dto';
import { UserAdminResponseDto, UserResponseDto, UserUpdateMeDto, mapUser, mapUserAdmin } from 'src/dtos/user.dto';
import { UserMetadataEntity } from 'src/entities/user-metadata.entity';
import { UserEntity } from 'src/entities/user.entity';
import { CacheControl, JobName, JobStatus, QueueName, StorageFolder, UserMetadataKey } from 'src/enum';
import { UserFindOptions } from 'src/repositories/user.repository';
import { BaseService } from 'src/services/base.service';
import { JobOf } from 'src/types';
import { JobOf, UserMetadataItem } from 'src/types';
import { ImmichFileResponse } from 'src/utils/file';
import { getPreferences, getPreferencesPartial, mergePreferences } from 'src/utils/preferences';
@@ -135,7 +134,7 @@ export class UserService extends BaseService {
const metadata = await this.userRepository.getMetadata(auth.user.id);
const license = metadata.find(
(item): item is UserMetadataEntity<UserMetadataKey.LICENSE> => item.key === UserMetadataKey.LICENSE,
(item): item is UserMetadataItem<UserMetadataKey.LICENSE> => item.key === UserMetadataKey.LICENSE,
);
if (!license) {
throw new NotFoundException();