create: 查询字符串里的布尔参数 false 会被当成 true
MemRelay-Operation: memory-save:activated-filter-fix-20261115-1505 MemRelay-Resource: 7328e41a-7f77-4ca5-804b-f27d714f4c35
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
---
|
||||
title: 查询字符串里的布尔参数 false 会被当成 true
|
||||
type: experience
|
||||
permalink: main/projects/d44c219a-0b31-4de1-b160-323eb34a4c6a/查询字符串里的布尔参数-false-会被当成-true
|
||||
stable_id: 7328e41a-7f77-4ca5-804b-f27d714f4c35
|
||||
scope: project
|
||||
memory_type: experience
|
||||
project_id: d44c219a-0b31-4de1-b160-323eb34a4c6a
|
||||
usage_profile_id: 0c9feb46-d06e-43cd-9ef0-c5813c84a998
|
||||
status: active
|
||||
revision: 1
|
||||
request_id: activated-filter-fix-20261115-1505
|
||||
created_at: '2026-11-15T06:57:21.201932+00:00'
|
||||
updated_at: '2026-11-15T06:57:21.201932+00:00'
|
||||
tags:
|
||||
- api
|
||||
- admin
|
||||
- dashboard
|
||||
- pitfall
|
||||
---
|
||||
|
||||
main.ts 的全局 ValidationPipe 开了 transformOptions.enableImplicitConversion。对布尔类型的查询参数,class-transformer 会先做 Boolean('false') === true,再把结果交给 @Transform,所以 @Transform(({ value }) => ...) 里拿到的已经是 true。表现:GET /trace-codes?activated=false 返回的是激活过的码(线上一直如此,「上链管理」「出库管理」里的「未激活」筛选也因此不对)。原有单测用不带选项的 plainToInstance,测不出来。
|
||||
|
||||
修法:新增 apps/api/src/common/utils/query-boolean.util.ts 的 queryBoolean,读 obj[key] 原始值;所有查询布尔参数用 @Transform(queryBoolean)(TraceCodeFilterDto、QueryTraceCodeDto、ExportTraceCodeDto 的 activated,查询日志的 abnormal)。测试要用 plainToInstance(Dto, input, { enableImplicitConversion: true }) 才等同线上。JSON 请求体里的布尔字段不受影响。以后新增查询布尔参数一律用 queryBoolean。
|
||||
|
||||
同时完成:看板「已激活追溯码」按 firstActivatedAt 非空统计,点击改为跳 /trace-codes?activated=1;追溯码页「激活时间」表头新增筛选(激活过 / 从未激活),导出也带这个条件。本机实测 268 + 6430 = 6698。
|
||||
|
||||
本机界面验证方法:容器内用本机 JWT_SECRET 给一个临时 sys_user 签短期令牌写入浏览器 localStorage 的 artveris_token,测完删除该账号并恢复原令牌;不要改线上管理员密码。
|
||||
Reference in New Issue
Block a user