mirror of
https://github.com/immich-app/immich.git
synced 2025-12-24 01:11:32 +03:00
feat: paginate integrity report results
This commit is contained in:
@@ -42,7 +42,7 @@ export class IntegrityController {
|
||||
})
|
||||
@Authenticated({ permission: Permission.Maintenance, admin: true })
|
||||
getIntegrityReport(@Body() dto: IntegrityGetReportDto): Promise<IntegrityReportResponseDto> {
|
||||
return this.service.getIntegrityReport(dto.type);
|
||||
return this.service.getIntegrityReport(dto);
|
||||
}
|
||||
|
||||
@Delete('report/:id')
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { Type } from 'class-transformer';
|
||||
import { IsInt, IsOptional, Min } from 'class-validator';
|
||||
import { IntegrityReportType } from 'src/enum';
|
||||
import { ValidateEnum } from 'src/validation';
|
||||
|
||||
@@ -15,12 +17,17 @@ export class IntegrityGetReportDto {
|
||||
@ValidateEnum({ enum: IntegrityReportType, name: 'IntegrityReportType' })
|
||||
type!: IntegrityReportType;
|
||||
|
||||
// todo: paginate
|
||||
// @IsInt()
|
||||
// @Min(1)
|
||||
// @Type(() => Number)
|
||||
// @Optional()
|
||||
// page?: number;
|
||||
@IsInt()
|
||||
@Min(1)
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
page?: number;
|
||||
|
||||
@IsInt()
|
||||
@Min(1)
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
size?: number;
|
||||
}
|
||||
|
||||
export class IntegrityDeleteReportDto {
|
||||
@@ -37,4 +44,5 @@ class IntegrityReportDto {
|
||||
|
||||
export class IntegrityReportResponseDto {
|
||||
items!: IntegrityReportDto[];
|
||||
hasNextPage!: boolean;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,12 @@ import { DummyValue, GenerateSql } from 'src/decorators';
|
||||
import { IntegrityReportType } from 'src/enum';
|
||||
import { DB } from 'src/schema';
|
||||
import { IntegrityReportTable } from 'src/schema/tables/integrity-report.table';
|
||||
import { paginationHelper } from 'src/utils/pagination';
|
||||
|
||||
export interface ReportPaginationOptions {
|
||||
page: number;
|
||||
size: number;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class IntegrityRepository {
|
||||
@@ -58,14 +64,18 @@ export class IntegrityRepository {
|
||||
.executeTakeFirstOrThrow();
|
||||
}
|
||||
|
||||
@GenerateSql({ params: [DummyValue.STRING] })
|
||||
getIntegrityReports(type: IntegrityReportType) {
|
||||
return this.db
|
||||
@GenerateSql({ params: [{ page: 1, size: 100 }, DummyValue.STRING] })
|
||||
async getIntegrityReports(pagination: ReportPaginationOptions, type: IntegrityReportType) {
|
||||
const items = await this.db
|
||||
.selectFrom('integrity_report')
|
||||
.select(['id', 'type', 'path', 'assetId', 'fileAssetId'])
|
||||
.where('type', '=', type)
|
||||
.orderBy('createdAt', 'desc')
|
||||
.limit(pagination.size + 1)
|
||||
.offset((pagination.page - 1) * pagination.size)
|
||||
.execute();
|
||||
|
||||
return paginationHelper(items, pagination.size);
|
||||
}
|
||||
|
||||
@GenerateSql({ params: [DummyValue.STRING] })
|
||||
|
||||
@@ -24,7 +24,7 @@ describe(IntegrityService.name, () => {
|
||||
|
||||
describe('getIntegrityReport', () => {
|
||||
it('gets report', async () => {
|
||||
await expect(sut.getIntegrityReport(IntegrityReportType.ChecksumFail)).resolves.toEqual(
|
||||
await expect(sut.getIntegrityReport({ type: IntegrityReportType.ChecksumFail })).resolves.toEqual(
|
||||
expect.objectContaining({
|
||||
items: undefined,
|
||||
}),
|
||||
|
||||
@@ -9,7 +9,11 @@ import { JOBS_LIBRARY_PAGINATION_SIZE } from 'src/constants';
|
||||
import { StorageCore } from 'src/cores/storage.core';
|
||||
import { OnEvent, OnJob } from 'src/decorators';
|
||||
import { AuthDto } from 'src/dtos/auth.dto';
|
||||
import { IntegrityReportResponseDto, IntegrityReportSummaryResponseDto } from 'src/dtos/integrity.dto';
|
||||
import {
|
||||
IntegrityGetReportDto,
|
||||
IntegrityReportResponseDto,
|
||||
IntegrityReportSummaryResponseDto,
|
||||
} from 'src/dtos/integrity.dto';
|
||||
import {
|
||||
AssetStatus,
|
||||
CacheControl,
|
||||
@@ -154,10 +158,8 @@ export class IntegrityService extends BaseService {
|
||||
return this.integrityRepository.getIntegrityReportSummary();
|
||||
}
|
||||
|
||||
async getIntegrityReport(type: IntegrityReportType): Promise<IntegrityReportResponseDto> {
|
||||
return {
|
||||
items: await this.integrityRepository.getIntegrityReports(type),
|
||||
};
|
||||
async getIntegrityReport(dto: IntegrityGetReportDto): Promise<IntegrityReportResponseDto> {
|
||||
return this.integrityRepository.getIntegrityReports({ page: dto.page || 1, size: dto.size || 100 }, dto.type);
|
||||
}
|
||||
|
||||
getIntegrityReportCsv(type: IntegrityReportType): Readable {
|
||||
|
||||
Reference in New Issue
Block a user