From 7168707395e45487e9f735bfc9c18016e09d7d5f Mon Sep 17 00:00:00 2001 From: Jason Rasmussen Date: Fri, 24 May 2024 16:37:29 -0400 Subject: [PATCH] refactor(server): remove unused code (#9737) --- server/src/cores/user.core.ts | 10 ++-------- server/src/services/auth.service.spec.ts | 19 +------------------ server/src/services/auth.service.ts | 9 +-------- server/src/services/cli.service.spec.ts | 6 +----- server/src/services/cli.service.ts | 4 +--- server/src/services/user.service.spec.ts | 15 +-------------- server/src/services/user.service.ts | 6 ++---- 7 files changed, 9 insertions(+), 60 deletions(-) diff --git a/server/src/cores/user.core.ts b/server/src/cores/user.core.ts index fa6ee7cdea..504687fb18 100644 --- a/server/src/cores/user.core.ts +++ b/server/src/cores/user.core.ts @@ -4,7 +4,6 @@ import { SALT_ROUNDS } from 'src/constants'; import { UserResponseDto } from 'src/dtos/user.dto'; import { UserEntity } from 'src/entities/user.entity'; import { ICryptoRepository } from 'src/interfaces/crypto.interface'; -import { ILibraryRepository } from 'src/interfaces/library.interface'; import { IUserRepository } from 'src/interfaces/user.interface'; let instance: UserCore | null; @@ -12,17 +11,12 @@ let instance: UserCore | null; export class UserCore { private constructor( private cryptoRepository: ICryptoRepository, - private libraryRepository: ILibraryRepository, private userRepository: IUserRepository, ) {} - static create( - cryptoRepository: ICryptoRepository, - libraryRepository: ILibraryRepository, - userRepository: IUserRepository, - ) { + static create(cryptoRepository: ICryptoRepository, userRepository: IUserRepository) { if (!instance) { - instance = new UserCore(cryptoRepository, libraryRepository, userRepository); + instance = new UserCore(cryptoRepository, userRepository); } return instance; diff --git a/server/src/services/auth.service.spec.ts b/server/src/services/auth.service.spec.ts index 34b8d9a550..aef0f04668 100644 --- a/server/src/services/auth.service.spec.ts +++ b/server/src/services/auth.service.spec.ts @@ -8,7 +8,6 @@ import { UserMetadataEntity } from 'src/entities/user-metadata.entity'; import { UserEntity } from 'src/entities/user.entity'; import { IKeyRepository } from 'src/interfaces/api-key.interface'; import { ICryptoRepository } from 'src/interfaces/crypto.interface'; -import { ILibraryRepository } from 'src/interfaces/library.interface'; import { ILoggerRepository } from 'src/interfaces/logger.interface'; import { ISessionRepository } from 'src/interfaces/session.interface'; import { ISharedLinkRepository } from 'src/interfaces/shared-link.interface'; @@ -21,10 +20,8 @@ import { sessionStub } from 'test/fixtures/session.stub'; import { sharedLinkStub } from 'test/fixtures/shared-link.stub'; import { systemConfigStub } from 'test/fixtures/system-config.stub'; import { userStub } from 'test/fixtures/user.stub'; -import { IAccessRepositoryMock, newAccessRepositoryMock } from 'test/repositories/access.repository.mock'; import { newKeyRepositoryMock } from 'test/repositories/api-key.repository.mock'; import { newCryptoRepositoryMock } from 'test/repositories/crypto.repository.mock'; -import { newLibraryRepositoryMock } from 'test/repositories/library.repository.mock'; import { newLoggerRepositoryMock } from 'test/repositories/logger.repository.mock'; import { newSessionRepositoryMock } from 'test/repositories/session.repository.mock'; import { newSharedLinkRepositoryMock } from 'test/repositories/shared-link.repository.mock'; @@ -60,10 +57,8 @@ const oauthUserWithDefaultQuota = { describe('AuthService', () => { let sut: AuthService; - let accessMock: Mocked; let cryptoMock: Mocked; let userMock: Mocked; - let libraryMock: Mocked; let loggerMock: Mocked; let systemMock: Mocked; let sessionMock: Mocked; @@ -93,27 +88,15 @@ describe('AuthService', () => { }), } as any); - accessMock = newAccessRepositoryMock(); cryptoMock = newCryptoRepositoryMock(); userMock = newUserRepositoryMock(); - libraryMock = newLibraryRepositoryMock(); loggerMock = newLoggerRepositoryMock(); systemMock = newSystemMetadataRepositoryMock(); sessionMock = newSessionRepositoryMock(); shareMock = newSharedLinkRepositoryMock(); keyMock = newKeyRepositoryMock(); - sut = new AuthService( - accessMock, - cryptoMock, - systemMock, - libraryMock, - loggerMock, - userMock, - sessionMock, - shareMock, - keyMock, - ); + sut = new AuthService(cryptoMock, systemMock, loggerMock, userMock, sessionMock, shareMock, keyMock); }); it('should be defined', () => { diff --git a/server/src/services/auth.service.ts b/server/src/services/auth.service.ts index 115a630b78..5e61cad187 100644 --- a/server/src/services/auth.service.ts +++ b/server/src/services/auth.service.ts @@ -12,7 +12,6 @@ import { IncomingHttpHeaders } from 'node:http'; import { ClientMetadata, Issuer, UserinfoResponse, custom, generators } from 'openid-client'; import { SystemConfig } from 'src/config'; import { AuthType, LOGIN_URL, MOBILE_REDIRECT } from 'src/constants'; -import { AccessCore } from 'src/cores/access.core'; import { SystemConfigCore } from 'src/cores/system-config.core'; import { UserCore } from 'src/cores/user.core'; import { @@ -30,10 +29,8 @@ import { } from 'src/dtos/auth.dto'; import { UserResponseDto, mapUser } from 'src/dtos/user.dto'; import { UserEntity } from 'src/entities/user.entity'; -import { IAccessRepository } from 'src/interfaces/access.interface'; import { IKeyRepository } from 'src/interfaces/api-key.interface'; import { ICryptoRepository } from 'src/interfaces/crypto.interface'; -import { ILibraryRepository } from 'src/interfaces/library.interface'; import { ILoggerRepository } from 'src/interfaces/logger.interface'; import { ISessionRepository } from 'src/interfaces/session.interface'; import { ISharedLinkRepository } from 'src/interfaces/shared-link.interface'; @@ -60,15 +57,12 @@ interface ClaimOptions { @Injectable() export class AuthService { - private access: AccessCore; private configCore: SystemConfigCore; private userCore: UserCore; constructor( - @Inject(IAccessRepository) accessRepository: IAccessRepository, @Inject(ICryptoRepository) private cryptoRepository: ICryptoRepository, @Inject(ISystemMetadataRepository) systemMetadataRepository: ISystemMetadataRepository, - @Inject(ILibraryRepository) libraryRepository: ILibraryRepository, @Inject(ILoggerRepository) private logger: ILoggerRepository, @Inject(IUserRepository) private userRepository: IUserRepository, @Inject(ISessionRepository) private sessionRepository: ISessionRepository, @@ -76,9 +70,8 @@ export class AuthService { @Inject(IKeyRepository) private keyRepository: IKeyRepository, ) { this.logger.setContext(AuthService.name); - this.access = AccessCore.create(accessRepository); this.configCore = SystemConfigCore.create(systemMetadataRepository, logger); - this.userCore = UserCore.create(cryptoRepository, libraryRepository, userRepository); + this.userCore = UserCore.create(cryptoRepository, userRepository); custom.setHttpOptionsDefaults({ timeout: 30_000 }); } diff --git a/server/src/services/cli.service.spec.ts b/server/src/services/cli.service.spec.ts index 016045fc17..e52c648664 100644 --- a/server/src/services/cli.service.spec.ts +++ b/server/src/services/cli.service.spec.ts @@ -1,12 +1,10 @@ import { ICryptoRepository } from 'src/interfaces/crypto.interface'; -import { ILibraryRepository } from 'src/interfaces/library.interface'; import { ILoggerRepository } from 'src/interfaces/logger.interface'; import { ISystemMetadataRepository } from 'src/interfaces/system-metadata.interface'; import { IUserRepository } from 'src/interfaces/user.interface'; import { CliService } from 'src/services/cli.service'; import { userStub } from 'test/fixtures/user.stub'; import { newCryptoRepositoryMock } from 'test/repositories/crypto.repository.mock'; -import { newLibraryRepositoryMock } from 'test/repositories/library.repository.mock'; import { newLoggerRepositoryMock } from 'test/repositories/logger.repository.mock'; import { newSystemMetadataRepositoryMock } from 'test/repositories/system-metadata.repository.mock'; import { newUserRepositoryMock } from 'test/repositories/user.repository.mock'; @@ -17,18 +15,16 @@ describe(CliService.name, () => { let userMock: Mocked; let cryptoMock: Mocked; - let libraryMock: Mocked; let systemMock: Mocked; let loggerMock: Mocked; beforeEach(() => { cryptoMock = newCryptoRepositoryMock(); - libraryMock = newLibraryRepositoryMock(); systemMock = newSystemMetadataRepositoryMock(); userMock = newUserRepositoryMock(); loggerMock = newLoggerRepositoryMock(); - sut = new CliService(cryptoMock, libraryMock, systemMock, userMock, loggerMock); + sut = new CliService(cryptoMock, systemMock, userMock, loggerMock); }); describe('resetAdminPassword', () => { diff --git a/server/src/services/cli.service.ts b/server/src/services/cli.service.ts index d4d838d0c4..459dde1888 100644 --- a/server/src/services/cli.service.ts +++ b/server/src/services/cli.service.ts @@ -3,7 +3,6 @@ import { SystemConfigCore } from 'src/cores/system-config.core'; import { UserCore } from 'src/cores/user.core'; import { UserResponseDto, mapUser } from 'src/dtos/user.dto'; import { ICryptoRepository } from 'src/interfaces/crypto.interface'; -import { ILibraryRepository } from 'src/interfaces/library.interface'; import { ILoggerRepository } from 'src/interfaces/logger.interface'; import { ISystemMetadataRepository } from 'src/interfaces/system-metadata.interface'; import { IUserRepository } from 'src/interfaces/user.interface'; @@ -15,12 +14,11 @@ export class CliService { constructor( @Inject(ICryptoRepository) private cryptoRepository: ICryptoRepository, - @Inject(ILibraryRepository) libraryRepository: ILibraryRepository, @Inject(ISystemMetadataRepository) systemMetadataRepository: ISystemMetadataRepository, @Inject(IUserRepository) private userRepository: IUserRepository, @Inject(ILoggerRepository) private logger: ILoggerRepository, ) { - this.userCore = UserCore.create(cryptoRepository, libraryRepository, userRepository); + this.userCore = UserCore.create(cryptoRepository, userRepository); this.logger.setContext(CliService.name); this.configCore = SystemConfigCore.create(systemMetadataRepository, this.logger); } diff --git a/server/src/services/user.service.spec.ts b/server/src/services/user.service.spec.ts index b46984ce7e..0b0cdb5699 100644 --- a/server/src/services/user.service.spec.ts +++ b/server/src/services/user.service.spec.ts @@ -9,7 +9,6 @@ import { UserEntity, UserStatus } from 'src/entities/user.entity'; import { IAlbumRepository } from 'src/interfaces/album.interface'; import { ICryptoRepository } from 'src/interfaces/crypto.interface'; import { IJobRepository, JobName } from 'src/interfaces/job.interface'; -import { ILibraryRepository } from 'src/interfaces/library.interface'; import { ILoggerRepository } from 'src/interfaces/logger.interface'; import { IStorageRepository } from 'src/interfaces/storage.interface'; import { ISystemMetadataRepository } from 'src/interfaces/system-metadata.interface'; @@ -22,7 +21,6 @@ import { userStub } from 'test/fixtures/user.stub'; import { newAlbumRepositoryMock } from 'test/repositories/album.repository.mock'; import { newCryptoRepositoryMock } from 'test/repositories/crypto.repository.mock'; import { newJobRepositoryMock } from 'test/repositories/job.repository.mock'; -import { newLibraryRepositoryMock } from 'test/repositories/library.repository.mock'; import { newLoggerRepositoryMock } from 'test/repositories/logger.repository.mock'; import { newStorageRepositoryMock } from 'test/repositories/storage.repository.mock'; import { newSystemMetadataRepositoryMock } from 'test/repositories/system-metadata.repository.mock'; @@ -42,7 +40,6 @@ describe(UserService.name, () => { let albumMock: Mocked; let jobMock: Mocked; - let libraryMock: Mocked; let storageMock: Mocked; let systemMock: Mocked; let loggerMock: Mocked; @@ -52,21 +49,11 @@ describe(UserService.name, () => { systemMock = newSystemMetadataRepositoryMock(); cryptoRepositoryMock = newCryptoRepositoryMock(); jobMock = newJobRepositoryMock(); - libraryMock = newLibraryRepositoryMock(); storageMock = newStorageRepositoryMock(); userMock = newUserRepositoryMock(); loggerMock = newLoggerRepositoryMock(); - sut = new UserService( - albumMock, - cryptoRepositoryMock, - jobMock, - libraryMock, - storageMock, - systemMock, - userMock, - loggerMock, - ); + sut = new UserService(albumMock, cryptoRepositoryMock, jobMock, storageMock, systemMock, userMock, loggerMock); userMock.get.mockImplementation((userId) => Promise.resolve([userStub.admin, userStub.user1].find((user) => user.id === userId) ?? null), diff --git a/server/src/services/user.service.ts b/server/src/services/user.service.ts index e62df2225f..bb3313e4a9 100644 --- a/server/src/services/user.service.ts +++ b/server/src/services/user.service.ts @@ -11,7 +11,6 @@ import { UserEntity, UserStatus } from 'src/entities/user.entity'; import { IAlbumRepository } from 'src/interfaces/album.interface'; import { ICryptoRepository } from 'src/interfaces/crypto.interface'; import { IEntityJob, IJobRepository, JobName, JobStatus } from 'src/interfaces/job.interface'; -import { ILibraryRepository } from 'src/interfaces/library.interface'; import { ILoggerRepository } from 'src/interfaces/logger.interface'; import { IStorageRepository } from 'src/interfaces/storage.interface'; import { ISystemMetadataRepository } from 'src/interfaces/system-metadata.interface'; @@ -26,15 +25,14 @@ export class UserService { constructor( @Inject(IAlbumRepository) private albumRepository: IAlbumRepository, - @Inject(ICryptoRepository) private cryptoRepository: ICryptoRepository, + @Inject(ICryptoRepository) cryptoRepository: ICryptoRepository, @Inject(IJobRepository) private jobRepository: IJobRepository, - @Inject(ILibraryRepository) libraryRepository: ILibraryRepository, @Inject(IStorageRepository) private storageRepository: IStorageRepository, @Inject(ISystemMetadataRepository) systemMetadataRepository: ISystemMetadataRepository, @Inject(IUserRepository) private userRepository: IUserRepository, @Inject(ILoggerRepository) private logger: ILoggerRepository, ) { - this.userCore = UserCore.create(cryptoRepository, libraryRepository, userRepository); + this.userCore = UserCore.create(cryptoRepository, userRepository); this.logger.setContext(UserService.name); this.configCore = SystemConfigCore.create(systemMetadataRepository, this.logger); }