diff --git a/server/src/domain/album/album.service.spec.ts b/server/src/domain/album/album.service.spec.ts index 8182df040..8bc9f695d 100644 --- a/server/src/domain/album/album.service.spec.ts +++ b/server/src/domain/album/album.service.spec.ts @@ -79,6 +79,7 @@ describe(AlbumService.name, () => { it('gets list of albums that are shared', async () => { albumMock.getShared.mockResolvedValue([albumStub.sharedWithUser]); albumMock.getInvalidThumbnail.mockResolvedValue([]); + albumMock.getVirtualColumns.mockResolvedValue(albumStub.sharedWithUser); const result = await sut.getAll(authStub.admin, { shared: true }); expect(result).toHaveLength(1); diff --git a/server/src/domain/album/album.service.ts b/server/src/domain/album/album.service.ts index 9033bcd1c..fb348af67 100644 --- a/server/src/domain/album/album.service.ts +++ b/server/src/domain/album/album.service.ts @@ -60,6 +60,11 @@ export class AlbumService { albums = await this.albumRepository.getByAssetId(ownerId, assetId); } else if (shared === true) { albums = await this.albumRepository.getShared(ownerId); + for (let i = 0; i < albums.length; i++) { + const album = albums[i]; + const { assetCount, startDate, endDate } = await this.albumRepository.getVirtualColumns(album.id); + albums[i] = { ...album, assetCount, startDate, endDate }; + } } else if (shared === false) { albums = await this.albumRepository.getNotShared(ownerId); } else { diff --git a/server/src/domain/repositories/album.repository.ts b/server/src/domain/repositories/album.repository.ts index 3f37be69f..680a6cec0 100644 --- a/server/src/domain/repositories/album.repository.ts +++ b/server/src/domain/repositories/album.repository.ts @@ -2,11 +2,6 @@ import { AlbumEntity } from '@app/infra/entities'; export const IAlbumRepository = 'IAlbumRepository'; -export interface AlbumAssetCount { - albumId: string; - assetCount: number; -} - export interface AlbumInfoOptions { withAssets: boolean; } @@ -42,4 +37,5 @@ export interface IAlbumRepository { update(album: Partial): Promise; delete(album: AlbumEntity): Promise; updateThumbnails(): Promise; + getVirtualColumns(id: string): Promise; } diff --git a/server/src/infra/repositories/album.repository.ts b/server/src/infra/repositories/album.repository.ts index c71ce1c38..f2317cb75 100644 --- a/server/src/infra/repositories/album.repository.ts +++ b/server/src/infra/repositories/album.repository.ts @@ -1,7 +1,16 @@ import { AlbumAsset, AlbumAssets, AlbumInfoOptions, IAlbumRepository } from '@app/domain'; import { Injectable } from '@nestjs/common'; import { InjectDataSource, InjectRepository } from '@nestjs/typeorm'; -import { DataSource, FindOptionsOrder, FindOptionsRelations, In, IsNull, Not, Repository } from 'typeorm'; +import { + DataSource, + FindOptionsOrder, + FindOptionsRelations, + FindOptionsSelect, + In, + IsNull, + Not, + Repository, +} from 'typeorm'; import { dataSource } from '../database.config'; import { AlbumEntity, AssetEntity } from '../entities'; @@ -96,11 +105,27 @@ export class AlbumRepository implements IAlbumRepository { }); } + getVirtualColumns(id: string): Promise { + const withVirtualColumns = this.repository.metadata.columns + .filter((column) => column.isVirtualProperty) + .map((column) => column.propertyName) as FindOptionsSelect; + + return this.repository.findOneOrFail({ + select: withVirtualColumns, + where: { id }, + }); + } + /** * Get albums shared with and shared by owner. */ getShared(ownerId: string): Promise { + const withoutVirtualColumns = this.repository.metadata.columns + .filter((column) => !column.isVirtualProperty) + .map((column) => column.propertyName) as FindOptionsSelect; + return this.repository.find({ + select: withoutVirtualColumns, relations: { sharedUsers: true, sharedLinks: true, owner: true }, where: [ { sharedUsers: { id: ownerId } }, diff --git a/server/test/repositories/album.repository.mock.ts b/server/test/repositories/album.repository.mock.ts index a97393c0b..781652e20 100644 --- a/server/test/repositories/album.repository.mock.ts +++ b/server/test/repositories/album.repository.mock.ts @@ -22,5 +22,6 @@ export const newAlbumRepositoryMock = (): jest.Mocked => { update: jest.fn(), delete: jest.fn(), updateThumbnails: jest.fn(), + getVirtualColumns: jest.fn(), }; };