refactor(server): album count (#2746)

* refactor(server): album count

* chore: open api
This commit is contained in:
Jason Rasmussen
2023-06-16 11:48:48 -04:00
committed by GitHub
parent 441ee2ef90
commit 07f7fffae7
21 changed files with 100 additions and 95 deletions

View File

@@ -1,7 +1,7 @@
import { AlbumEntity } from '@app/infra/entities';
import { ApiProperty } from '@nestjs/swagger';
import { AssetResponseDto, mapAsset } from '../../asset';
import { mapUser, UserResponseDto } from '../../user';
import { AssetResponseDto, mapAsset } from '../asset';
import { mapUser, UserResponseDto } from '../user';
export class AlbumResponseDto {
id!: string;
@@ -63,3 +63,14 @@ export function mapAlbumExcludeAssetInfo(entity: AlbumEntity): AlbumResponseDto
assetCount: entity.assets?.length || 0,
};
}
export class AlbumCountResponseDto {
@ApiProperty({ type: 'integer' })
owned!: number;
@ApiProperty({ type: 'integer' })
shared!: number;
@ApiProperty({ type: 'integer' })
notShared!: number;
}

View File

@@ -35,6 +35,23 @@ describe(AlbumService.name, () => {
expect(sut).toBeDefined();
});
describe('getCount', () => {
it('should get the album count', async () => {
albumMock.getOwned.mockResolvedValue([]),
albumMock.getShared.mockResolvedValue([]),
albumMock.getNotShared.mockResolvedValue([]),
await expect(sut.getCount(authStub.admin)).resolves.toEqual({
owned: 0,
shared: 0,
notShared: 0,
});
expect(albumMock.getOwned).toHaveBeenCalledWith(authStub.admin.id);
expect(albumMock.getShared).toHaveBeenCalledWith(authStub.admin.id);
expect(albumMock.getNotShared).toHaveBeenCalledWith(authStub.admin.id);
});
});
describe('getAll', () => {
it('gets list of albums for auth user', async () => {
albumMock.getOwned.mockResolvedValue([albumStub.empty, albumStub.sharedWithUser]);

View File

@@ -4,9 +4,9 @@ import { IAssetRepository, mapAsset } from '../asset';
import { AuthUserDto } from '../auth';
import { IJobRepository, JobName } from '../job';
import { IUserRepository } from '../user';
import { AlbumCountResponseDto, AlbumResponseDto, mapAlbum } from './album-response.dto';
import { IAlbumRepository } from './album.repository';
import { AddUsersDto, CreateAlbumDto, GetAlbumsDto, UpdateAlbumDto } from './dto';
import { AlbumResponseDto, mapAlbum } from './response-dto';
@Injectable()
export class AlbumService {
@@ -17,6 +17,20 @@ export class AlbumService {
@Inject(IUserRepository) private userRepository: IUserRepository,
) {}
async getCount(authUser: AuthUserDto): Promise<AlbumCountResponseDto> {
const [owned, shared, notShared] = await Promise.all([
this.albumRepository.getOwned(authUser.id),
this.albumRepository.getShared(authUser.id),
this.albumRepository.getNotShared(authUser.id),
]);
return {
owned: owned.length,
shared: shared.length,
notShared: notShared.length,
};
}
async getAll({ id: ownerId }: AuthUserDto, { assetId, shared }: GetAlbumsDto): Promise<AlbumResponseDto[]> {
await this.updateInvalidThumbnails();

View File

@@ -1,4 +1,4 @@
export * from './album-response.dto';
export * from './album.repository';
export * from './album.service';
export * from './dto';
export * from './response-dto';

View File

@@ -1 +0,0 @@
export * from './album-response.dto';