From eb1ba11d60edc69ae1d83b74e2445bbb99dcd130 Mon Sep 17 00:00:00 2001 From: Jason Rasmussen Date: Fri, 5 Jul 2024 09:08:36 -0400 Subject: [PATCH] refactor(server): rename asset stack to stack (#10828) --- server/src/entities/asset.entity.ts | 6 ++-- server/src/entities/index.ts | 4 +-- ...{asset-stack.entity.ts => stack.entity.ts} | 2 +- .../src/interfaces/asset-stack.interface.ts | 11 ------ server/src/interfaces/stack.interface.ts | 11 ++++++ server/src/repositories/index.ts | 6 ++-- ...tack.repository.ts => stack.repository.ts} | 16 ++++----- server/src/services/asset.service.spec.ts | 36 +++++++++---------- server/src/services/asset.service.ts | 20 +++++------ server/src/services/user.service.spec.ts | 8 ++--- server/src/services/user.service.ts | 8 ++--- server/test/fixtures/asset.stub.ts | 6 ++-- ...itory.mock.ts => stack.repository.mock.ts} | 4 +-- 13 files changed, 68 insertions(+), 70 deletions(-) rename server/src/entities/{asset-stack.entity.ts => stack.entity.ts} (94%) delete mode 100644 server/src/interfaces/asset-stack.interface.ts create mode 100644 server/src/interfaces/stack.interface.ts rename server/src/repositories/{asset-stack.repository.ts => stack.repository.ts} (67%) rename server/test/repositories/{asset-stack.repository.mock.ts => stack.repository.mock.ts} (54%) diff --git a/server/src/entities/asset.entity.ts b/server/src/entities/asset.entity.ts index 52dba6befe..ca486fb471 100644 --- a/server/src/entities/asset.entity.ts +++ b/server/src/entities/asset.entity.ts @@ -1,12 +1,12 @@ import { AlbumEntity } from 'src/entities/album.entity'; import { AssetFaceEntity } from 'src/entities/asset-face.entity'; import { AssetJobStatusEntity } from 'src/entities/asset-job-status.entity'; -import { AssetStackEntity } from 'src/entities/asset-stack.entity'; import { ExifEntity } from 'src/entities/exif.entity'; import { LibraryEntity } from 'src/entities/library.entity'; import { SharedLinkEntity } from 'src/entities/shared-link.entity'; import { SmartInfoEntity } from 'src/entities/smart-info.entity'; import { SmartSearchEntity } from 'src/entities/smart-search.entity'; +import { StackEntity } from 'src/entities/stack.entity'; import { TagEntity } from 'src/entities/tag.entity'; import { UserEntity } from 'src/entities/user.entity'; import { @@ -164,9 +164,9 @@ export class AssetEntity { @Column({ nullable: true }) stackId?: string | null; - @ManyToOne(() => AssetStackEntity, { nullable: true, onDelete: 'SET NULL', onUpdate: 'CASCADE' }) + @ManyToOne(() => StackEntity, { nullable: true, onDelete: 'SET NULL', onUpdate: 'CASCADE' }) @JoinColumn() - stack?: AssetStackEntity | null; + stack?: StackEntity | null; @OneToOne(() => AssetJobStatusEntity, (jobStatus) => jobStatus.asset, { nullable: true }) jobStatus?: AssetJobStatusEntity; diff --git a/server/src/entities/index.ts b/server/src/entities/index.ts index cd3d74724b..6090b8f918 100644 --- a/server/src/entities/index.ts +++ b/server/src/entities/index.ts @@ -4,7 +4,6 @@ import { AlbumEntity } from 'src/entities/album.entity'; import { APIKeyEntity } from 'src/entities/api-key.entity'; import { AssetFaceEntity } from 'src/entities/asset-face.entity'; import { AssetJobStatusEntity } from 'src/entities/asset-job-status.entity'; -import { AssetStackEntity } from 'src/entities/asset-stack.entity'; import { AssetEntity } from 'src/entities/asset.entity'; import { AuditEntity } from 'src/entities/audit.entity'; import { ExifEntity } from 'src/entities/exif.entity'; @@ -19,6 +18,7 @@ import { SessionEntity } from 'src/entities/session.entity'; import { SharedLinkEntity } from 'src/entities/shared-link.entity'; import { SmartInfoEntity } from 'src/entities/smart-info.entity'; import { SmartSearchEntity } from 'src/entities/smart-search.entity'; +import { StackEntity } from 'src/entities/stack.entity'; import { SystemMetadataEntity } from 'src/entities/system-metadata.entity'; import { TagEntity } from 'src/entities/tag.entity'; import { UserMetadataEntity } from 'src/entities/user-metadata.entity'; @@ -30,7 +30,6 @@ export const entities = [ AlbumUserEntity, APIKeyEntity, AssetEntity, - AssetStackEntity, AssetFaceEntity, AssetJobStatusEntity, AuditEntity, @@ -44,6 +43,7 @@ export const entities = [ SharedLinkEntity, SmartInfoEntity, SmartSearchEntity, + StackEntity, SystemMetadataEntity, TagEntity, UserEntity, diff --git a/server/src/entities/asset-stack.entity.ts b/server/src/entities/stack.entity.ts similarity index 94% rename from server/src/entities/asset-stack.entity.ts rename to server/src/entities/stack.entity.ts index 6397bded3a..dac75b6362 100644 --- a/server/src/entities/asset-stack.entity.ts +++ b/server/src/entities/stack.entity.ts @@ -2,7 +2,7 @@ import { AssetEntity } from 'src/entities/asset.entity'; import { Column, Entity, JoinColumn, OneToMany, OneToOne, PrimaryGeneratedColumn } from 'typeorm'; @Entity('asset_stack') -export class AssetStackEntity { +export class StackEntity { @PrimaryGeneratedColumn('uuid') id!: string; diff --git a/server/src/interfaces/asset-stack.interface.ts b/server/src/interfaces/asset-stack.interface.ts deleted file mode 100644 index 2286f5fd72..0000000000 --- a/server/src/interfaces/asset-stack.interface.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { AssetStackEntity } from 'src/entities/asset-stack.entity'; - -export const IAssetStackRepository = 'IAssetStackRepository'; - -export interface IAssetStackRepository { - create(assetStack: Partial): Promise; - update(asset: Pick & Partial): Promise; - delete(id: string): Promise; - getById(id: string): Promise; - deleteAll(userId: string): Promise; -} diff --git a/server/src/interfaces/stack.interface.ts b/server/src/interfaces/stack.interface.ts new file mode 100644 index 0000000000..c06d7cd5ec --- /dev/null +++ b/server/src/interfaces/stack.interface.ts @@ -0,0 +1,11 @@ +import { StackEntity } from 'src/entities/stack.entity'; + +export const IStackRepository = 'IStackRepository'; + +export interface IStackRepository { + create(stack: Partial): Promise; + update(stack: Pick & Partial): Promise; + delete(id: string): Promise; + getById(id: string): Promise; + deleteAll(userId: string): Promise; +} diff --git a/server/src/repositories/index.ts b/server/src/repositories/index.ts index 758e82d9e7..3be6b375a0 100644 --- a/server/src/repositories/index.ts +++ b/server/src/repositories/index.ts @@ -3,7 +3,6 @@ import { IActivityRepository } from 'src/interfaces/activity.interface'; import { IAlbumUserRepository } from 'src/interfaces/album-user.interface'; import { IAlbumRepository } from 'src/interfaces/album.interface'; import { IKeyRepository } from 'src/interfaces/api-key.interface'; -import { IAssetStackRepository } from 'src/interfaces/asset-stack.interface'; import { IAssetRepository } from 'src/interfaces/asset.interface'; import { IAuditRepository } from 'src/interfaces/audit.interface'; import { ICryptoRepository } from 'src/interfaces/crypto.interface'; @@ -26,6 +25,7 @@ import { ISearchRepository } from 'src/interfaces/search.interface'; import { IServerInfoRepository } from 'src/interfaces/server-info.interface'; import { ISessionRepository } from 'src/interfaces/session.interface'; import { ISharedLinkRepository } from 'src/interfaces/shared-link.interface'; +import { IStackRepository } from 'src/interfaces/stack.interface'; import { IStorageRepository } from 'src/interfaces/storage.interface'; import { ISystemMetadataRepository } from 'src/interfaces/system-metadata.interface'; import { ITagRepository } from 'src/interfaces/tag.interface'; @@ -35,7 +35,6 @@ import { ActivityRepository } from 'src/repositories/activity.repository'; import { AlbumUserRepository } from 'src/repositories/album-user.repository'; import { AlbumRepository } from 'src/repositories/album.repository'; import { ApiKeyRepository } from 'src/repositories/api-key.repository'; -import { AssetStackRepository } from 'src/repositories/asset-stack.repository'; import { AssetRepository } from 'src/repositories/asset.repository'; import { AuditRepository } from 'src/repositories/audit.repository'; import { CryptoRepository } from 'src/repositories/crypto.repository'; @@ -58,6 +57,7 @@ import { SearchRepository } from 'src/repositories/search.repository'; import { ServerInfoRepository } from 'src/repositories/server-info.repository'; import { SessionRepository } from 'src/repositories/session.repository'; import { SharedLinkRepository } from 'src/repositories/shared-link.repository'; +import { StackRepository } from 'src/repositories/stack.repository'; import { StorageRepository } from 'src/repositories/storage.repository'; import { SystemMetadataRepository } from 'src/repositories/system-metadata.repository'; import { TagRepository } from 'src/repositories/tag.repository'; @@ -69,7 +69,6 @@ export const repositories = [ { provide: IAlbumRepository, useClass: AlbumRepository }, { provide: IAlbumUserRepository, useClass: AlbumUserRepository }, { provide: IAssetRepository, useClass: AssetRepository }, - { provide: IAssetStackRepository, useClass: AssetStackRepository }, { provide: IAuditRepository, useClass: AuditRepository }, { provide: ICryptoRepository, useClass: CryptoRepository }, { provide: IDatabaseRepository, useClass: DatabaseRepository }, @@ -92,6 +91,7 @@ export const repositories = [ { provide: IServerInfoRepository, useClass: ServerInfoRepository }, { provide: ISessionRepository, useClass: SessionRepository }, { provide: ISharedLinkRepository, useClass: SharedLinkRepository }, + { provide: IStackRepository, useClass: StackRepository }, { provide: IStorageRepository, useClass: StorageRepository }, { provide: ISystemMetadataRepository, useClass: SystemMetadataRepository }, { provide: ITagRepository, useClass: TagRepository }, diff --git a/server/src/repositories/asset-stack.repository.ts b/server/src/repositories/stack.repository.ts similarity index 67% rename from server/src/repositories/asset-stack.repository.ts rename to server/src/repositories/stack.repository.ts index f4a42cedf8..4a99ba01e4 100644 --- a/server/src/repositories/asset-stack.repository.ts +++ b/server/src/repositories/stack.repository.ts @@ -1,16 +1,16 @@ import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; -import { AssetStackEntity } from 'src/entities/asset-stack.entity'; -import { IAssetStackRepository } from 'src/interfaces/asset-stack.interface'; +import { StackEntity } from 'src/entities/stack.entity'; +import { IStackRepository } from 'src/interfaces/stack.interface'; import { Instrumentation } from 'src/utils/instrumentation'; import { In, Repository } from 'typeorm'; @Instrumentation() @Injectable() -export class AssetStackRepository implements IAssetStackRepository { - constructor(@InjectRepository(AssetStackEntity) private repository: Repository) {} +export class StackRepository implements IStackRepository { + constructor(@InjectRepository(StackEntity) private repository: Repository) {} - create(entity: Partial) { + create(entity: Partial) { return this.save(entity); } @@ -18,11 +18,11 @@ export class AssetStackRepository implements IAssetStackRepository { await this.repository.delete(id); } - update(entity: Partial) { + update(entity: Partial) { return this.save(entity); } - async getById(id: string): Promise { + async getById(id: string): Promise { return this.repository.findOne({ where: { id, @@ -41,7 +41,7 @@ export class AssetStackRepository implements IAssetStackRepository { await this.repository.delete({ id: In([...stackIds]) }); } - private async save(entity: Partial) { + private async save(entity: Partial) { const { id } = await this.repository.save(entity); return this.repository.findOneOrFail({ where: { diff --git a/server/src/services/asset.service.spec.ts b/server/src/services/asset.service.spec.ts index c2edc63985..8efa78edf3 100755 --- a/server/src/services/asset.service.spec.ts +++ b/server/src/services/asset.service.spec.ts @@ -2,27 +2,27 @@ import { BadRequestException } from '@nestjs/common'; import { mapAsset } from 'src/dtos/asset-response.dto'; import { AssetJobName, AssetStatsResponseDto } from 'src/dtos/asset.dto'; import { AssetEntity, AssetType } from 'src/entities/asset.entity'; -import { IAssetStackRepository } from 'src/interfaces/asset-stack.interface'; import { AssetStats, IAssetRepository } from 'src/interfaces/asset.interface'; import { ClientEvent, IEventRepository } from 'src/interfaces/event.interface'; import { IJobRepository, JobName } from 'src/interfaces/job.interface'; import { ILoggerRepository } from 'src/interfaces/logger.interface'; import { IPartnerRepository } from 'src/interfaces/partner.interface'; +import { IStackRepository } from 'src/interfaces/stack.interface'; import { ISystemMetadataRepository } from 'src/interfaces/system-metadata.interface'; import { IUserRepository } from 'src/interfaces/user.interface'; import { AssetService } from 'src/services/asset.service'; -import { assetStackStub, assetStub } from 'test/fixtures/asset.stub'; +import { assetStub, stackStub } from 'test/fixtures/asset.stub'; import { authStub } from 'test/fixtures/auth.stub'; import { faceStub } from 'test/fixtures/face.stub'; import { partnerStub } from 'test/fixtures/partner.stub'; import { userStub } from 'test/fixtures/user.stub'; import { IAccessRepositoryMock, newAccessRepositoryMock } from 'test/repositories/access.repository.mock'; -import { newAssetStackRepositoryMock } from 'test/repositories/asset-stack.repository.mock'; import { newAssetRepositoryMock } from 'test/repositories/asset.repository.mock'; import { newEventRepositoryMock } from 'test/repositories/event.repository.mock'; import { newJobRepositoryMock } from 'test/repositories/job.repository.mock'; import { newLoggerRepositoryMock } from 'test/repositories/logger.repository.mock'; import { newPartnerRepositoryMock } from 'test/repositories/partner.repository.mock'; +import { newStackRepositoryMock } from 'test/repositories/stack.repository.mock'; import { newSystemMetadataRepositoryMock } from 'test/repositories/system-metadata.repository.mock'; import { newUserRepositoryMock } from 'test/repositories/user.repository.mock'; import { Mocked, vitest } from 'vitest'; @@ -47,9 +47,9 @@ describe(AssetService.name, () => { let jobMock: Mocked; let userMock: Mocked; let eventMock: Mocked; + let stackMock: Mocked; let systemMock: Mocked; let partnerMock: Mocked; - let assetStackMock: Mocked; let loggerMock: Mocked; it('should work', () => { @@ -70,7 +70,7 @@ describe(AssetService.name, () => { userMock = newUserRepositoryMock(); systemMock = newSystemMetadataRepositoryMock(); partnerMock = newPartnerRepositoryMock(); - assetStackMock = newAssetStackRepositoryMock(); + stackMock = newStackRepositoryMock(); loggerMock = newLoggerRepositoryMock(); sut = new AssetService( @@ -81,7 +81,7 @@ describe(AssetService.name, () => { userMock, eventMock, partnerMock, - assetStackMock, + stackMock, loggerMock, ); @@ -274,10 +274,10 @@ describe(AssetService.name, () => { { id: 'child-1', stackId: 'stack-1', - stack: assetStackStub('stack-1', [{ id: 'parent' } as AssetEntity, { id: 'child-1' } as AssetEntity]), + stack: stackStub('stack-1', [{ id: 'parent' } as AssetEntity, { id: 'child-1' } as AssetEntity]), } as AssetEntity, ]); - assetStackMock.getById.mockResolvedValue(assetStackStub('stack-1', [{ id: 'parent' } as AssetEntity])); + stackMock.getById.mockResolvedValue(stackStub('stack-1', [{ id: 'parent' } as AssetEntity])); await sut.updateAll(authStub.user1, { ids: ['child-1'], @@ -287,13 +287,13 @@ describe(AssetService.name, () => { expect(assetMock.updateAll).toHaveBeenCalledWith(expect.arrayContaining(['parent']), { updatedAt: expect.any(Date), }); - expect(assetStackMock.delete).toHaveBeenCalledWith('stack-1'); + expect(stackMock.delete).toHaveBeenCalledWith('stack-1'); }); it('update parentId for new children', async () => { accessMock.asset.checkOwnerAccess.mockResolvedValueOnce(new Set(['child-1', 'child-2'])); accessMock.asset.checkOwnerAccess.mockResolvedValueOnce(new Set(['parent'])); - const stack = assetStackStub('stack-1', [ + const stack = stackStub('stack-1', [ { id: 'parent' } as AssetEntity, { id: 'child-1' } as AssetEntity, { id: 'child-2' } as AssetEntity, @@ -308,8 +308,8 @@ describe(AssetService.name, () => { ids: ['child-1', 'child-2'], }); - expect(assetStackMock.update).toHaveBeenCalledWith({ - ...assetStackStub('stack-1', [ + expect(stackMock.update).toHaveBeenCalledWith({ + ...stackStub('stack-1', [ { id: 'child-1' } as AssetEntity, { id: 'child-2' } as AssetEntity, { id: 'parent' } as AssetEntity, @@ -337,18 +337,18 @@ describe(AssetService.name, () => { { id: 'child-1', stackId: 'stack-1', - stack: assetStackStub('stack-1', [{ id: 'child-1' } as AssetEntity, { id: 'child-2' } as AssetEntity]), + stack: stackStub('stack-1', [{ id: 'child-1' } as AssetEntity, { id: 'child-2' } as AssetEntity]), } as AssetEntity, ]); - assetStackMock.getById.mockResolvedValue(assetStackStub('stack-1', [{ id: 'parent' } as AssetEntity])); + stackMock.getById.mockResolvedValue(stackStub('stack-1', [{ id: 'parent' } as AssetEntity])); await sut.updateAll(authStub.user1, { ids: ['child-1'], stackParentId: 'parent', }); - expect(assetStackMock.delete).toHaveBeenCalledWith('stack-1'); - expect(assetStackMock.create).toHaveBeenCalledWith({ + expect(stackMock.delete).toHaveBeenCalledWith('stack-1'); + expect(stackMock.create).toHaveBeenCalledWith({ assets: [{ id: 'child-1' }, { id: 'parent' }, { id: 'child-1' }, { id: 'child-2' }], primaryAssetId: 'parent', }); @@ -437,7 +437,7 @@ describe(AssetService.name, () => { await sut.handleAssetDeletion({ id: assetStub.primaryImage.id, deleteOnDisk: true }); - expect(assetStackMock.update).toHaveBeenCalledWith({ + expect(stackMock.update).toHaveBeenCalledWith({ id: 'stack-1', primaryAssetId: 'stack-child-asset-1', }); @@ -552,7 +552,7 @@ describe(AssetService.name, () => { newParentId: 'new', }); - expect(assetStackMock.update).toBeCalledWith({ id: 'stack-1', primaryAssetId: 'new' }); + expect(stackMock.update).toBeCalledWith({ id: 'stack-1', primaryAssetId: 'new' }); expect(assetMock.updateAll).toBeCalledWith([assetStub.image.id, 'new', assetStub.image.id], { updatedAt: expect.any(Date), }); diff --git a/server/src/services/asset.service.ts b/server/src/services/asset.service.ts index 2a3d5aceb2..8a62dd89a7 100644 --- a/server/src/services/asset.service.ts +++ b/server/src/services/asset.service.ts @@ -23,7 +23,6 @@ import { MemoryLaneDto } from 'src/dtos/search.dto'; import { UpdateStackParentDto } from 'src/dtos/stack.dto'; import { AssetEntity } from 'src/entities/asset.entity'; import { IAccessRepository } from 'src/interfaces/access.interface'; -import { IAssetStackRepository } from 'src/interfaces/asset-stack.interface'; import { IAssetRepository } from 'src/interfaces/asset.interface'; import { ClientEvent, IEventRepository } from 'src/interfaces/event.interface'; import { @@ -37,6 +36,7 @@ import { } from 'src/interfaces/job.interface'; import { ILoggerRepository } from 'src/interfaces/logger.interface'; import { IPartnerRepository } from 'src/interfaces/partner.interface'; +import { IStackRepository } from 'src/interfaces/stack.interface'; import { ISystemMetadataRepository } from 'src/interfaces/system-metadata.interface'; import { IUserRepository } from 'src/interfaces/user.interface'; import { getMyPartnerIds } from 'src/utils/asset.util'; @@ -54,7 +54,7 @@ export class AssetService { @Inject(IUserRepository) private userRepository: IUserRepository, @Inject(IEventRepository) private eventRepository: IEventRepository, @Inject(IPartnerRepository) private partnerRepository: IPartnerRepository, - @Inject(IAssetStackRepository) private assetStackRepository: IAssetStackRepository, + @Inject(IStackRepository) private stackRepository: IStackRepository, @Inject(ILoggerRepository) private logger: ILoggerRepository, ) { this.logger.setContext(AssetService.name); @@ -211,13 +211,13 @@ export class AssetService { ids.push(...assetsWithChildren.flatMap((child) => child.stack!.assets.map((gChild) => gChild.id))); if (stack) { - await this.assetStackRepository.update({ + await this.stackRepository.update({ id: stack.id, primaryAssetId: primaryAsset.id, assets: ids.map((id) => ({ id }) as AssetEntity), }); } else { - stack = await this.assetStackRepository.create({ + stack = await this.stackRepository.create({ primaryAssetId: primaryAsset.id, assets: ids.map((id) => ({ id }) as AssetEntity), }); @@ -233,13 +233,11 @@ export class AssetService { } await this.assetRepository.updateAll(ids, options); - const stackIdsToDelete = await Promise.all( - stackIdsToCheckForDelete.map((id) => this.assetStackRepository.getById(id)), - ); + const stackIdsToDelete = await Promise.all(stackIdsToCheckForDelete.map((id) => this.stackRepository.getById(id))); const stacksToDelete = stackIdsToDelete .flatMap((stack) => (stack ? [stack] : [])) .filter((stack) => stack.assets.length < 2); - await Promise.all(stacksToDelete.map((as) => this.assetStackRepository.delete(as.id))); + await Promise.all(stacksToDelete.map((as) => this.stackRepository.delete(as.id))); this.eventRepository.clientSend(ClientEvent.ASSET_STACK_UPDATE, auth.user.id, ids); } @@ -289,12 +287,12 @@ export class AssetService { const stackAssetIds = asset.stack.assets.map((a) => a.id); if (stackAssetIds.length > 2) { const newPrimaryAssetId = stackAssetIds.find((a) => a !== id)!; - await this.assetStackRepository.update({ + await this.stackRepository.update({ id: asset.stack.id, primaryAssetId: newPrimaryAssetId, }); } else { - await this.assetStackRepository.delete(asset.stack.id); + await this.stackRepository.delete(asset.stack.id); } } @@ -365,7 +363,7 @@ export class AssetService { // Get all children of old parent childIds.push(oldParent.id, ...(oldParent.stack?.assets.map((a) => a.id) ?? [])); } - await this.assetStackRepository.update({ + await this.stackRepository.update({ id: oldParent.stackId, primaryAssetId: newParentId, }); diff --git a/server/src/services/user.service.spec.ts b/server/src/services/user.service.spec.ts index 54fe05df89..91cdfb30d0 100644 --- a/server/src/services/user.service.spec.ts +++ b/server/src/services/user.service.spec.ts @@ -2,10 +2,10 @@ import { BadRequestException, InternalServerErrorException, NotFoundException } import { UserMetadataKey } from 'src/entities/user-metadata.entity'; import { UserEntity } from 'src/entities/user.entity'; import { IAlbumRepository } from 'src/interfaces/album.interface'; -import { IAssetStackRepository } from 'src/interfaces/asset-stack.interface'; import { ICryptoRepository } from 'src/interfaces/crypto.interface'; import { IJobRepository, JobName } from 'src/interfaces/job.interface'; import { ILoggerRepository } from 'src/interfaces/logger.interface'; +import { IStackRepository } from 'src/interfaces/stack.interface'; import { IStorageRepository } from 'src/interfaces/storage.interface'; import { ISystemMetadataRepository } from 'src/interfaces/system-metadata.interface'; import { IUserRepository } from 'src/interfaces/user.interface'; @@ -15,10 +15,10 @@ import { authStub } from 'test/fixtures/auth.stub'; import { systemConfigStub } from 'test/fixtures/system-config.stub'; import { userStub } from 'test/fixtures/user.stub'; import { newAlbumRepositoryMock } from 'test/repositories/album.repository.mock'; -import { newAssetStackRepositoryMock } from 'test/repositories/asset-stack.repository.mock'; import { newCryptoRepositoryMock } from 'test/repositories/crypto.repository.mock'; import { newJobRepositoryMock } from 'test/repositories/job.repository.mock'; import { newLoggerRepositoryMock } from 'test/repositories/logger.repository.mock'; +import { newStackRepositoryMock } from 'test/repositories/stack.repository.mock'; import { newStorageRepositoryMock } from 'test/repositories/storage.repository.mock'; import { newSystemMetadataRepositoryMock } from 'test/repositories/system-metadata.repository.mock'; import { newUserRepositoryMock } from 'test/repositories/user.repository.mock'; @@ -37,7 +37,7 @@ describe(UserService.name, () => { let albumMock: Mocked; let jobMock: Mocked; - let stackMock: Mocked; + let stackMock: Mocked; let storageMock: Mocked; let systemMock: Mocked; let loggerMock: Mocked; @@ -47,7 +47,7 @@ describe(UserService.name, () => { systemMock = newSystemMetadataRepositoryMock(); cryptoRepositoryMock = newCryptoRepositoryMock(); jobMock = newJobRepositoryMock(); - stackMock = newAssetStackRepositoryMock(); + stackMock = newStackRepositoryMock(); storageMock = newStorageRepositoryMock(); userMock = newUserRepositoryMock(); loggerMock = newLoggerRepositoryMock(); diff --git a/server/src/services/user.service.ts b/server/src/services/user.service.ts index 0ee42b8081..b92e2822df 100644 --- a/server/src/services/user.service.ts +++ b/server/src/services/user.service.ts @@ -6,16 +6,16 @@ import { StorageCore, StorageFolder } from 'src/cores/storage.core'; import { SystemConfigCore } from 'src/cores/system-config.core'; import { AuthDto } from 'src/dtos/auth.dto'; import { LicenseKeyDto, LicenseResponseDto } from 'src/dtos/license.dto'; -import { mapPreferences, UserPreferencesResponseDto, UserPreferencesUpdateDto } from 'src/dtos/user-preferences.dto'; +import { UserPreferencesResponseDto, UserPreferencesUpdateDto, mapPreferences } from 'src/dtos/user-preferences.dto'; import { CreateProfileImageResponseDto, mapCreateProfileImageResponse } from 'src/dtos/user-profile.dto'; -import { mapUser, mapUserAdmin, UserAdminResponseDto, UserResponseDto, UserUpdateMeDto } from 'src/dtos/user.dto'; +import { UserAdminResponseDto, UserResponseDto, UserUpdateMeDto, mapUser, mapUserAdmin } from 'src/dtos/user.dto'; import { UserMetadataEntity, UserMetadataKey } from 'src/entities/user-metadata.entity'; import { UserEntity } from 'src/entities/user.entity'; import { IAlbumRepository } from 'src/interfaces/album.interface'; -import { IAssetStackRepository } from 'src/interfaces/asset-stack.interface'; import { ICryptoRepository } from 'src/interfaces/crypto.interface'; import { IEntityJob, IJobRepository, JobName, JobStatus } from 'src/interfaces/job.interface'; import { ILoggerRepository } from 'src/interfaces/logger.interface'; +import { IStackRepository } from 'src/interfaces/stack.interface'; import { IStorageRepository } from 'src/interfaces/storage.interface'; import { ISystemMetadataRepository } from 'src/interfaces/system-metadata.interface'; import { IUserRepository, UserFindOptions } from 'src/interfaces/user.interface'; @@ -30,7 +30,7 @@ export class UserService { @Inject(IAlbumRepository) private albumRepository: IAlbumRepository, @Inject(ICryptoRepository) private cryptoRepository: ICryptoRepository, @Inject(IJobRepository) private jobRepository: IJobRepository, - @Inject(IAssetStackRepository) private stackRepository: IAssetStackRepository, + @Inject(IStackRepository) private stackRepository: IStackRepository, @Inject(IStorageRepository) private storageRepository: IStorageRepository, @Inject(ISystemMetadataRepository) systemMetadataRepository: ISystemMetadataRepository, @Inject(IUserRepository) private userRepository: IUserRepository, diff --git a/server/test/fixtures/asset.stub.ts b/server/test/fixtures/asset.stub.ts index e4575e0b9b..290dd1623f 100644 --- a/server/test/fixtures/asset.stub.ts +++ b/server/test/fixtures/asset.stub.ts @@ -1,12 +1,12 @@ -import { AssetStackEntity } from 'src/entities/asset-stack.entity'; import { AssetEntity, AssetType } from 'src/entities/asset.entity'; import { ExifEntity } from 'src/entities/exif.entity'; +import { StackEntity } from 'src/entities/stack.entity'; import { authStub } from 'test/fixtures/auth.stub'; import { fileStub } from 'test/fixtures/file.stub'; import { libraryStub } from 'test/fixtures/library.stub'; import { userStub } from 'test/fixtures/user.stub'; -export const assetStackStub = (stackId: string, assets: AssetEntity[]): AssetStackEntity => { +export const stackStub = (stackId: string, assets: AssetEntity[]): StackEntity => { return { id: stackId, assets: assets, @@ -161,7 +161,7 @@ export const assetStub = { exifImageHeight: 1000, exifImageWidth: 1000, } as ExifEntity, - stack: assetStackStub('stack-1', [ + stack: stackStub('stack-1', [ { id: 'primary-asset-id' } as AssetEntity, { id: 'stack-child-asset-1' } as AssetEntity, { id: 'stack-child-asset-2' } as AssetEntity, diff --git a/server/test/repositories/asset-stack.repository.mock.ts b/server/test/repositories/stack.repository.mock.ts similarity index 54% rename from server/test/repositories/asset-stack.repository.mock.ts rename to server/test/repositories/stack.repository.mock.ts index 61bc001642..374afd1fbd 100644 --- a/server/test/repositories/asset-stack.repository.mock.ts +++ b/server/test/repositories/stack.repository.mock.ts @@ -1,7 +1,7 @@ -import { IAssetStackRepository } from 'src/interfaces/asset-stack.interface'; +import { IStackRepository } from 'src/interfaces/stack.interface'; import { Mocked, vitest } from 'vitest'; -export const newAssetStackRepositoryMock = (): Mocked => { +export const newStackRepositoryMock = (): Mocked => { return { create: vitest.fn(), update: vitest.fn(),