fix(admin-service): 修复上传版本时isForceUpdate始终为true的问题

问题原因:
- 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 <noreply@anthropic.com>
This commit is contained in:
hailin 2025-12-27 19:31:47 -08:00
parent 058849dc2c
commit fe593714ae
1 changed files with 13 additions and 4 deletions

View File

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