Compare commits

...

5 commits

Author SHA1 Message Date
martabal
22bff8e562
fix: format 2023-11-21 16:28:55 +01:00
martabal
e7bd1b17e0
chore: merge main 2023-11-21 16:25:23 +01:00
martabal
51a2e16e1a
fix: shared albums 2023-11-21 16:22:52 +01:00
martabal
fa926ce3b1
fix: tests 2023-11-21 14:22:06 +01:00
martabal
202e2174a2
fix: album performances 2023-11-21 13:38:07 +01:00
5 changed files with 34 additions and 6 deletions

View file

@ -79,6 +79,7 @@ describe(AlbumService.name, () => {
it('gets list of albums that are shared', async () => { it('gets list of albums that are shared', async () => {
albumMock.getShared.mockResolvedValue([albumStub.sharedWithUser]); albumMock.getShared.mockResolvedValue([albumStub.sharedWithUser]);
albumMock.getInvalidThumbnail.mockResolvedValue([]); albumMock.getInvalidThumbnail.mockResolvedValue([]);
albumMock.getVirtualColumns.mockResolvedValue(albumStub.sharedWithUser);
const result = await sut.getAll(authStub.admin, { shared: true }); const result = await sut.getAll(authStub.admin, { shared: true });
expect(result).toHaveLength(1); expect(result).toHaveLength(1);

View file

@ -60,6 +60,11 @@ export class AlbumService {
albums = await this.albumRepository.getByAssetId(ownerId, assetId); albums = await this.albumRepository.getByAssetId(ownerId, assetId);
} else if (shared === true) { } else if (shared === true) {
albums = await this.albumRepository.getShared(ownerId); 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) { } else if (shared === false) {
albums = await this.albumRepository.getNotShared(ownerId); albums = await this.albumRepository.getNotShared(ownerId);
} else { } else {

View file

@ -2,11 +2,6 @@ import { AlbumEntity } from '@app/infra/entities';
export const IAlbumRepository = 'IAlbumRepository'; export const IAlbumRepository = 'IAlbumRepository';
export interface AlbumAssetCount {
albumId: string;
assetCount: number;
}
export interface AlbumInfoOptions { export interface AlbumInfoOptions {
withAssets: boolean; withAssets: boolean;
} }
@ -42,4 +37,5 @@ export interface IAlbumRepository {
update(album: Partial<AlbumEntity>): Promise<AlbumEntity>; update(album: Partial<AlbumEntity>): Promise<AlbumEntity>;
delete(album: AlbumEntity): Promise<void>; delete(album: AlbumEntity): Promise<void>;
updateThumbnails(): Promise<number | undefined>; updateThumbnails(): Promise<number | undefined>;
getVirtualColumns(id: string): Promise<AlbumEntity>;
} }

View file

@ -1,7 +1,16 @@
import { AlbumAsset, AlbumAssets, AlbumInfoOptions, IAlbumRepository } from '@app/domain'; import { AlbumAsset, AlbumAssets, AlbumInfoOptions, IAlbumRepository } from '@app/domain';
import { Injectable } from '@nestjs/common'; import { Injectable } from '@nestjs/common';
import { InjectDataSource, InjectRepository } from '@nestjs/typeorm'; 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 { dataSource } from '../database.config';
import { AlbumEntity, AssetEntity } from '../entities'; import { AlbumEntity, AssetEntity } from '../entities';
@ -96,11 +105,27 @@ export class AlbumRepository implements IAlbumRepository {
}); });
} }
getVirtualColumns(id: string): Promise<AlbumEntity> {
const withVirtualColumns = this.repository.metadata.columns
.filter((column) => column.isVirtualProperty)
.map((column) => column.propertyName) as FindOptionsSelect<AlbumEntity>;
return this.repository.findOneOrFail({
select: withVirtualColumns,
where: { id },
});
}
/** /**
* Get albums shared with and shared by owner. * Get albums shared with and shared by owner.
*/ */
getShared(ownerId: string): Promise<AlbumEntity[]> { getShared(ownerId: string): Promise<AlbumEntity[]> {
const withoutVirtualColumns = this.repository.metadata.columns
.filter((column) => !column.isVirtualProperty)
.map((column) => column.propertyName) as FindOptionsSelect<AlbumEntity>;
return this.repository.find({ return this.repository.find({
select: withoutVirtualColumns,
relations: { sharedUsers: true, sharedLinks: true, owner: true }, relations: { sharedUsers: true, sharedLinks: true, owner: true },
where: [ where: [
{ sharedUsers: { id: ownerId } }, { sharedUsers: { id: ownerId } },

View file

@ -22,5 +22,6 @@ export const newAlbumRepositoryMock = (): jest.Mocked<IAlbumRepository> => {
update: jest.fn(), update: jest.fn(),
delete: jest.fn(), delete: jest.fn(),
updateThumbnails: jest.fn(), updateThumbnails: jest.fn(),
getVirtualColumns: jest.fn(),
}; };
}; };