From fe593714aeb5458db5e5eb21fb1461d74047724a Mon Sep 17 00:00:00 2001 From: hailin Date: Sat, 27 Dec 2025 19:31:47 -0800 Subject: [PATCH] =?UTF-8?q?fix(admin-service):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E7=89=88=E6=9C=AC=E6=97=B6isForceUpdate?= =?UTF-8?q?=E5=A7=8B=E7=BB=88=E4=B8=BAtrue=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题原因: - ValidationPipe配置了enableImplicitConversion: true - FormData发送字符串"false"时,Boolean("false")被隐式转换为true - @Transform装饰器在隐式转换之后执行,收到的value已经是true 解决方案: - 在@Transform中使用obj参数获取原始未转换的值 - 手动判断字符串"true"/"false"并正确转换为布尔值 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .../src/api/dto/request/upload-version.dto.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/backend/services/admin-service/src/api/dto/request/upload-version.dto.ts b/backend/services/admin-service/src/api/dto/request/upload-version.dto.ts index d2918381..620c3966 100644 --- a/backend/services/admin-service/src/api/dto/request/upload-version.dto.ts +++ b/backend/services/admin-service/src/api/dto/request/upload-version.dto.ts @@ -34,12 +34,21 @@ export class UploadVersionDto { @ApiPropertyOptional({ description: '是否强制更新', default: false }) @IsOptional() - @Transform(({ value }) => { + @Transform(({ obj }) => { + // Access the raw value directly from the source object + // This bypasses enableImplicitConversion which incorrectly converts "false" string to true + const rawValue = obj.isForceUpdate + // Handle string "true"/"false" from FormData - if (typeof value === 'string') { - return value.toLowerCase() === 'true' + if (typeof rawValue === 'string') { + return rawValue.toLowerCase() === 'true' } - return value === true + // Handle undefined/null - default to false + if (rawValue === undefined || rawValue === null) { + return false + } + // Handle actual boolean value + return rawValue === true }) @IsBoolean() isForceUpdate?: boolean