fix: 看板已激活追溯码与列表口径一致,修正未激活筛选返回已激活的码
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
import { plainToInstance } from 'class-transformer';
|
||||
import { TraceCodeFilterDto } from './trace-code-selection.dto';
|
||||
import { QueryTraceCodeDto } from '../../trace-code/dto/trace-code.dto';
|
||||
import { ExportTraceCodeDto, QueryTraceCodeDto } from '../../trace-code/dto/trace-code.dto';
|
||||
import { buildTraceCodeFilterWhere, buildTraceCodeSelectionWhere } from '../utils/trace-code-selection.util';
|
||||
|
||||
describe('activated query transformation', () => {
|
||||
it.each([
|
||||
[TraceCodeFilterDto, {}],
|
||||
[QueryTraceCodeDto, {}],
|
||||
[ExportTraceCodeDto, {}],
|
||||
])('does not turn an omitted activated filter into false', (Dto, input) => {
|
||||
const dto = plainToInstance(Dto, input);
|
||||
expect(dto.activated).toBeUndefined();
|
||||
@@ -21,6 +22,28 @@ describe('activated query transformation', () => {
|
||||
])('parses %p as %p', (input, expected) => {
|
||||
expect(plainToInstance(TraceCodeFilterDto, { activated: input }).activated).toBe(expected);
|
||||
expect(plainToInstance(QueryTraceCodeDto, { activated: input }).activated).toBe(expected);
|
||||
expect(plainToInstance(ExportTraceCodeDto, { activated: input }).activated).toBe(expected);
|
||||
});
|
||||
|
||||
// 与 main.ts 的全局校验管道一致:查询字符串会先做隐式类型转换,'false' 不能因此变成 true
|
||||
it.each([
|
||||
['true', true],
|
||||
['false', false],
|
||||
])('parses the query string %p as %p under the global pipe options', (input, expected) => {
|
||||
for (const Dto of [TraceCodeFilterDto, QueryTraceCodeDto, ExportTraceCodeDto]) {
|
||||
const dto = plainToInstance(Dto, { activated: input }, { enableImplicitConversion: true });
|
||||
expect(dto.activated).toBe(expected);
|
||||
}
|
||||
});
|
||||
|
||||
it('lists only never-activated codes for activated=false', () => {
|
||||
const dto = plainToInstance(QueryTraceCodeDto, { activated: 'false' }, { enableImplicitConversion: true });
|
||||
expect(buildTraceCodeFilterWhere(dto)).toMatchObject({ firstActivatedAt: null });
|
||||
});
|
||||
|
||||
it('exports only the codes that were ever activated when that filter is on', () => {
|
||||
const dto = plainToInstance(ExportTraceCodeDto, { activated: 'true' });
|
||||
expect(buildTraceCodeFilterWhere(dto)).toMatchObject({ firstActivatedAt: { not: null } });
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
ValidateNested,
|
||||
} from 'class-validator';
|
||||
import { MAX_BATCH_SELECTION, ProofStatus, TraceCodeStatus } from '@artveris/shared';
|
||||
import { queryBoolean } from '../utils/query-boolean.util';
|
||||
|
||||
export const ONCHAIN_FILTER_STATUSES = ['ELIGIBLE', 'NONE', ...Object.values(ProofStatus)] as const;
|
||||
export type OnchainFilterStatus = (typeof ONCHAIN_FILTER_STATUSES)[number];
|
||||
@@ -55,9 +56,7 @@ export class TraceCodeFilterDto {
|
||||
|
||||
@ApiPropertyOptional({ description: '是否已经首次激活' })
|
||||
@IsOptional()
|
||||
@Transform(({ value }) =>
|
||||
value === undefined || value === null || value === '' ? undefined : value === true || value === 'true',
|
||||
)
|
||||
@Transform(queryBoolean)
|
||||
@IsBoolean()
|
||||
activated?: boolean;
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import type { TransformFnParams } from 'class-transformer';
|
||||
|
||||
/**
|
||||
* 解析查询参数里的布尔值,配合 @Transform 使用。
|
||||
* 全局校验管道开启了隐式类型转换,查询字符串 'false' 会先被转成 true 再交给 @Transform,
|
||||
* 所以这里读取转换前的原始值;未传或传空时保持未设置,不当作 false。
|
||||
*/
|
||||
export function queryBoolean({ obj, key }: TransformFnParams): boolean | undefined {
|
||||
const raw: unknown = obj?.[key];
|
||||
if (raw === undefined || raw === null || raw === '') return undefined;
|
||||
return raw === true || raw === 'true';
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import { PrismaService } from '../prisma/prisma.service';
|
||||
import { buildPage } from '../common/utils/pagination.util';
|
||||
import { PaginationDto } from '../common/dto/pagination.dto';
|
||||
import { buildOrderBy } from '../common/utils/sort.util';
|
||||
import { queryBoolean } from '../common/utils/query-boolean.util';
|
||||
|
||||
class QueryLogQueryDto extends PaginationDto {
|
||||
@ApiPropertyOptional({ description: '关键词(追溯码 / 档案编号)' })
|
||||
@@ -32,9 +33,7 @@ class QueryLogQueryDto extends PaginationDto {
|
||||
|
||||
@ApiPropertyOptional({ description: '只看异常查询(无效、停用、异常),与看板「异常查询」同一口径' })
|
||||
@IsOptional()
|
||||
@Transform(({ value }) =>
|
||||
value === undefined || value === null || value === '' ? undefined : value === true || value === 'true',
|
||||
)
|
||||
@Transform(queryBoolean)
|
||||
@IsBoolean()
|
||||
abnormal?: boolean;
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
import { TraceCodeStatus } from '@artveris/shared';
|
||||
import { PaginationDto } from '../../common/dto/pagination.dto';
|
||||
import { ONCHAIN_FILTER_STATUSES, OnchainFilterStatus } from '../../common/dto/trace-code-selection.dto';
|
||||
import { queryBoolean } from '../../common/utils/query-boolean.util';
|
||||
|
||||
export class GenerateBatchDto {
|
||||
@ApiProperty({ description: '所属作品(款)ID' })
|
||||
@@ -73,9 +74,7 @@ export class QueryTraceCodeDto extends PaginationDto {
|
||||
|
||||
@ApiPropertyOptional({ description: '是否已经首次激活' })
|
||||
@IsOptional()
|
||||
@Transform(({ value }) =>
|
||||
value === undefined || value === null || value === '' ? undefined : value === true || value === 'true',
|
||||
)
|
||||
@Transform(queryBoolean)
|
||||
@IsBoolean()
|
||||
activated?: boolean;
|
||||
|
||||
@@ -230,6 +229,12 @@ export class ExportTraceCodeDto {
|
||||
@IsIn(['OUTBOUND', 'NOT_OUTBOUND'])
|
||||
outboundStatus?: 'OUTBOUND' | 'NOT_OUTBOUND';
|
||||
|
||||
@ApiPropertyOptional({ description: '是否已经首次激活' })
|
||||
@IsOptional()
|
||||
@Transform(queryBoolean)
|
||||
@IsBoolean()
|
||||
activated?: boolean;
|
||||
|
||||
@ApiPropertyOptional({ description: '关键词' })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
|
||||
Reference in New Issue
Block a user