fix: 看板异常查询点进去显示对应的查询记录

This commit is contained in:
Nixevol
2026-11-15 14:47:52 +08:00
parent d1ade47864
commit a5f7844125
6 changed files with 66 additions and 11 deletions
+2 -4
View File
@@ -1,6 +1,6 @@
import { Injectable } from '@nestjs/common';
import dayjs from 'dayjs';
import { QueryResult } from '@artveris/shared';
import { ABNORMAL_QUERY_RESULTS } from '@artveris/shared';
import { PrismaService } from '../prisma/prisma.service';
export interface DashboardOverviewQuery {
@@ -41,9 +41,7 @@ export class DashboardService {
this.prisma.traceCode.count({ where: { firstActivatedAt: { not: null } } }),
this.prisma.queryLog.count(),
this.prisma.queryLog.count({ where: { queriedAt: { gte: todayStart } } }),
this.prisma.queryLog.count({
where: { queryResult: { in: [QueryResult.INVALID, QueryResult.DISABLED, QueryResult.ABNORMAL] } },
}),
this.prisma.queryLog.count({ where: { queryResult: { in: [...ABNORMAL_QUERY_RESULTS] } } }),
]);
return {
@@ -0,0 +1,33 @@
import { QueryLogController } from './query-log.controller';
function createController() {
const prisma = {
queryLog: { findMany: jest.fn().mockReturnValue('rows'), count: jest.fn().mockReturnValue('total') },
$transaction: jest.fn().mockResolvedValue([[], 0]),
};
return { prisma, controller: new QueryLogController(prisma as any) };
}
const paging = { page: 1, pageSize: 20, skip: 0, take: 20 };
describe('QueryLogController result filters', () => {
it('lists invalid, disabled and abnormal queries together for the dashboard figure', async () => {
const { controller, prisma } = createController();
await controller.list({ ...paging, abnormal: true } as any);
expect(prisma.queryLog.count).toHaveBeenCalledWith({
where: { queryResult: { in: ['INVALID', 'DISABLED', 'ABNORMAL'] } },
});
expect(prisma.queryLog.findMany.mock.calls[0][0].where).toEqual(prisma.queryLog.count.mock.calls[0][0].where);
});
it('keeps a single chosen result when both filters are given', async () => {
const { controller, prisma } = createController();
await controller.list({ ...paging, abnormal: true, result: 'REPEAT' } as any);
expect(prisma.queryLog.count).toHaveBeenCalledWith({ where: { queryResult: 'REPEAT' } });
});
it('does not filter by result when neither is given', async () => {
const { controller, prisma } = createController();
await controller.list({ ...paging } as any);
expect(prisma.queryLog.count).toHaveBeenCalledWith({ where: {} });
});
});
+12 -2
View File
@@ -1,8 +1,9 @@
import { Controller, Get, Query } from '@nestjs/common';
import { ApiBearerAuth, ApiOperation, ApiPropertyOptional, ApiTags } from '@nestjs/swagger';
import { IsEnum, IsOptional, IsString } from 'class-validator';
import { Transform } from 'class-transformer';
import { IsBoolean, IsEnum, IsOptional, IsString } from 'class-validator';
import { Prisma } from '@prisma/client';
import { QueryResult } from '@artveris/shared';
import { ABNORMAL_QUERY_RESULTS, QueryResult } from '@artveris/shared';
import { PrismaService } from '../prisma/prisma.service';
import { buildPage } from '../common/utils/pagination.util';
import { PaginationDto } from '../common/dto/pagination.dto';
@@ -29,6 +30,14 @@ class QueryLogQueryDto extends PaginationDto {
@IsEnum(QueryResult)
result?: QueryResult;
@ApiPropertyOptional({ description: '只看异常查询(无效、停用、异常),与看板「异常查询」同一口径' })
@IsOptional()
@Transform(({ value }) =>
value === undefined || value === null || value === '' ? undefined : value === true || value === 'true',
)
@IsBoolean()
abnormal?: boolean;
@ApiPropertyOptional({ description: '开始时间' })
@IsOptional()
@IsString()
@@ -59,6 +68,7 @@ export class QueryLogController {
if (query.archiveNo) where.archiveNo = { contains: query.archiveNo };
if (query.batchNo) where.batchNo = { contains: query.batchNo };
if (query.result) where.queryResult = query.result;
else if (query.abnormal) where.queryResult = { in: [...ABNORMAL_QUERY_RESULTS] };
if (query.startTime || query.endTime) {
where.queriedAt = {};
if (query.startTime) where.queriedAt.gte = new Date(query.startTime);