feat: paginate integrity report results

This commit is contained in:
izzy
2025-12-18 14:08:06 +00:00
parent 31ac88f158
commit 5028c56ad8
10 changed files with 154 additions and 23 deletions

View File

@@ -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')

View File

@@ -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;
}

View File

@@ -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] })

View File

@@ -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,
}),

View File

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