fix: shared albums

This commit is contained in:
martabal 2023-11-21 16:22:52 +01:00
parent fa926ce3b1
commit 51a2e16e1a
No known key found for this signature in database
GPG key ID: C00196E3148A52BD
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 () => {
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);

View file

@ -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 {

View file

@ -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<AlbumEntity>): Promise<AlbumEntity>;
delete(album: AlbumEntity): Promise<void>;
updateThumbnails(): Promise<number | undefined>;
getVirtualColumns(id: string): Promise<AlbumEntity>;
}

View file

@ -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<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.
*/
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({
select: withoutVirtualColumns,
relations: { sharedUsers: true, sharedLinks: true, owner: true },
where: [
{ sharedUsers: { id: ownerId } },

View file

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