From 9a3a01ca780ce36a7d936954b2b9bddd9d5a80ab Mon Sep 17 00:00:00 2001 From: Jason Rasmussen Date: Fri, 9 Jun 2023 16:21:00 -0400 Subject: [PATCH] chore: remove unused code (#2700) --- .../immich/api-v1/asset/asset-repository.ts | 51 +++++-------------- .../immich/api-v1/asset/asset.service.spec.ts | 6 --- 2 files changed, 13 insertions(+), 44 deletions(-) diff --git a/server/src/immich/api-v1/asset/asset-repository.ts b/server/src/immich/api-v1/asset/asset-repository.ts index def006c79e..2170d20684 100644 --- a/server/src/immich/api-v1/asset/asset-repository.ts +++ b/server/src/immich/api-v1/asset/asset-repository.ts @@ -26,11 +26,7 @@ export interface IAssetRepository { asset: Omit, ): Promise; remove(asset: AssetEntity): Promise; - save(asset: Partial): Promise; - update(userId: string, asset: AssetEntity, dto: UpdateAssetDto): Promise; - getAll(): Promise; - getAllVideos(): Promise; getAllByUserId(userId: string, dto: AssetSearchDto): Promise; getAllByDeviceId(userId: string, deviceId: string): Promise; getById(assetId: string): Promise; @@ -55,22 +51,6 @@ export class AssetRepository implements IAssetRepository { @InjectRepository(ExifEntity) private exifRepository: Repository, ) {} - async getAllVideos(): Promise { - return await this.assetRepository.find({ - where: { type: AssetType.VIDEO }, - }); - } - - async getAll(): Promise { - return await this.assetRepository.find({ - where: { isVisible: true }, - relations: { - exifInfo: true, - smartInfo: true, - }, - }); - } - async getAssetCountByUserId(ownerId: string): Promise { // Get asset count by AssetType const items = await this.assetRepository @@ -151,8 +131,8 @@ export class AssetRepository implements IAssetRepository { return builder.getRawMany(); } - async getSearchPropertiesByUserId(userId: string): Promise { - return await this.assetRepository + getSearchPropertiesByUserId(userId: string): Promise { + return this.assetRepository .createQueryBuilder('asset') .where('asset.ownerId = :userId', { userId: userId }) .andWhere('asset.isVisible = true') @@ -172,8 +152,8 @@ export class AssetRepository implements IAssetRepository { .getRawMany(); } - async getDetectedObjectsByUserId(userId: string): Promise { - return await this.assetRepository.query( + getDetectedObjectsByUserId(userId: string): Promise { + return this.assetRepository.query( ` SELECT DISTINCT ON (unnest(si.objects)) a.id, unnest(si.objects) as "object", a."resizePath", a."deviceAssetId", a."deviceId" FROM assets a @@ -186,8 +166,8 @@ export class AssetRepository implements IAssetRepository { ); } - async getLocationsByUserId(userId: string): Promise { - return await this.assetRepository.query( + getLocationsByUserId(userId: string): Promise { + return this.assetRepository.query( ` SELECT DISTINCT ON (e.city) a.id, e.city, a."resizePath", a."deviceAssetId", a."deviceId" FROM assets a @@ -206,8 +186,8 @@ export class AssetRepository implements IAssetRepository { * - include exif info * @param assetId */ - async getById(assetId: string): Promise { - return await this.assetRepository.findOneOrFail({ + getById(assetId: string): Promise { + return this.assetRepository.findOneOrFail({ where: { id: assetId, }, @@ -227,7 +207,7 @@ export class AssetRepository implements IAssetRepository { * Get all assets belong to the user on the database * @param ownerId */ - async getAllByUserId(ownerId: string, dto: AssetSearchDto): Promise { + getAllByUserId(ownerId: string, dto: AssetSearchDto): Promise { return this.assetRepository.find({ where: { ownerId, @@ -258,7 +238,7 @@ export class AssetRepository implements IAssetRepository { }); } - async create( + create( asset: Omit, ): Promise { return this.assetRepository.save(asset); @@ -268,11 +248,6 @@ export class AssetRepository implements IAssetRepository { await this.assetRepository.remove(asset); } - async save(asset: Partial): Promise { - const { id } = await this.assetRepository.save(asset); - return this.assetRepository.findOneOrFail({ where: { id } }); - } - /** * Update asset */ @@ -329,7 +304,7 @@ export class AssetRepository implements IAssetRepository { * @param checksums * */ - async getAssetsByChecksums(ownerId: string, checksums: Buffer[]): Promise { + getAssetsByChecksums(ownerId: string, checksums: Buffer[]): Promise { return this.assetRepository.find({ select: { id: true, @@ -354,8 +329,8 @@ export class AssetRepository implements IAssetRepository { return assets.map((asset) => asset.deviceAssetId); } - async countByIdAndUser(assetId: string, ownerId: string): Promise { - return await this.assetRepository.count({ + countByIdAndUser(assetId: string, ownerId: string): Promise { + return this.assetRepository.count({ where: { id: assetId, ownerId, diff --git a/server/src/immich/api-v1/asset/asset.service.spec.ts b/server/src/immich/api-v1/asset/asset.service.spec.ts index f49eb1c92b..acea758b4b 100644 --- a/server/src/immich/api-v1/asset/asset.service.spec.ts +++ b/server/src/immich/api-v1/asset/asset.service.spec.ts @@ -146,11 +146,8 @@ describe('AssetService', () => { get: jest.fn(), create: jest.fn(), remove: jest.fn(), - save: jest.fn(), update: jest.fn(), - getAll: jest.fn(), - getAllVideos: jest.fn(), getAllByUserId: jest.fn(), getAllByDeviceId: jest.fn(), getAssetCountByTimeBucket: jest.fn(), @@ -283,7 +280,6 @@ describe('AssetService', () => { const dto = _getCreateAssetDto(); assetRepositoryMock.create.mockResolvedValue(assetEntity); - assetRepositoryMock.save.mockResolvedValue(assetEntity); await expect(sut.uploadFile(authStub.user1, dto, file)).resolves.toEqual({ duplicate: false, id: 'id_1' }); @@ -319,9 +315,7 @@ describe('AssetService', () => { (error as any).constraint = 'UQ_userid_checksum'; assetRepositoryMock.create.mockResolvedValueOnce(assetEntityStub.livePhotoMotionAsset); - assetRepositoryMock.save.mockResolvedValueOnce(assetEntityStub.livePhotoMotionAsset); assetRepositoryMock.create.mockResolvedValueOnce(assetEntityStub.livePhotoStillAsset); - assetRepositoryMock.save.mockResolvedValueOnce(assetEntityStub.livePhotoStillAsset); await expect( sut.uploadFile(authStub.user1, dto, fileStub.livePhotoStill, fileStub.livePhotoMotion),