mirror of
https://github.com/immich-app/immich.git
synced 2025-12-17 01:11:13 +03:00
fix(server): album statistics endpoint (#11924)
This commit is contained in:
@@ -2,9 +2,9 @@ import { Body, Controller, Delete, Get, Param, Patch, Post, Put, Query } from '@
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
import {
|
||||
AddUsersDto,
|
||||
AlbumCountResponseDto,
|
||||
AlbumInfoDto,
|
||||
AlbumResponseDto,
|
||||
AlbumStatisticsResponseDto,
|
||||
CreateAlbumDto,
|
||||
GetAlbumsDto,
|
||||
UpdateAlbumDto,
|
||||
@@ -22,12 +22,6 @@ import { ParseMeUUIDPipe, UUIDParamDto } from 'src/validation';
|
||||
export class AlbumController {
|
||||
constructor(private service: AlbumService) {}
|
||||
|
||||
@Get('count')
|
||||
@Authenticated({ permission: Permission.ALBUM_STATISTICS })
|
||||
getAlbumCount(@Auth() auth: AuthDto): Promise<AlbumCountResponseDto> {
|
||||
return this.service.getCount(auth);
|
||||
}
|
||||
|
||||
@Get()
|
||||
@Authenticated({ permission: Permission.ALBUM_READ })
|
||||
getAllAlbums(@Auth() auth: AuthDto, @Query() query: GetAlbumsDto): Promise<AlbumResponseDto[]> {
|
||||
@@ -40,6 +34,12 @@ export class AlbumController {
|
||||
return this.service.create(auth, dto);
|
||||
}
|
||||
|
||||
@Get('statistics')
|
||||
@Authenticated({ permission: Permission.ALBUM_STATISTICS })
|
||||
getAlbumStatistics(@Auth() auth: AuthDto): Promise<AlbumStatisticsResponseDto> {
|
||||
return this.service.getStatistics(auth);
|
||||
}
|
||||
|
||||
@Authenticated({ permission: Permission.ALBUM_READ, sharedLink: true })
|
||||
@Get(':id')
|
||||
getAlbumInfo(
|
||||
|
||||
@@ -95,7 +95,7 @@ export class GetAlbumsDto {
|
||||
assetId?: string;
|
||||
}
|
||||
|
||||
export class AlbumCountResponseDto {
|
||||
export class AlbumStatisticsResponseDto {
|
||||
@ApiProperty({ type: 'integer' })
|
||||
owned!: number;
|
||||
|
||||
|
||||
@@ -43,12 +43,12 @@ describe(AlbumService.name, () => {
|
||||
expect(sut).toBeDefined();
|
||||
});
|
||||
|
||||
describe('getCount', () => {
|
||||
describe('getStatistics', () => {
|
||||
it('should get the album count', async () => {
|
||||
albumMock.getOwned.mockResolvedValue([]);
|
||||
albumMock.getShared.mockResolvedValue([]);
|
||||
albumMock.getNotShared.mockResolvedValue([]);
|
||||
await expect(sut.getCount(authStub.admin)).resolves.toEqual({
|
||||
await expect(sut.getStatistics(authStub.admin)).resolves.toEqual({
|
||||
owned: 0,
|
||||
shared: 0,
|
||||
notShared: 0,
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { BadRequestException, Inject, Injectable } from '@nestjs/common';
|
||||
import {
|
||||
AddUsersDto,
|
||||
AlbumCountResponseDto,
|
||||
AlbumInfoDto,
|
||||
AlbumResponseDto,
|
||||
AlbumStatisticsResponseDto,
|
||||
CreateAlbumDto,
|
||||
GetAlbumsDto,
|
||||
UpdateAlbumDto,
|
||||
@@ -37,7 +37,7 @@ export class AlbumService {
|
||||
@Inject(IAlbumUserRepository) private albumUserRepository: IAlbumUserRepository,
|
||||
) {}
|
||||
|
||||
async getCount(auth: AuthDto): Promise<AlbumCountResponseDto> {
|
||||
async getStatistics(auth: AuthDto): Promise<AlbumStatisticsResponseDto> {
|
||||
const [owned, shared, notShared] = await Promise.all([
|
||||
this.albumRepository.getOwned(auth.user.id),
|
||||
this.albumRepository.getShared(auth.user.id),
|
||||
|
||||
Reference in New Issue
Block a user