From 592f13e939f1b33fd01021cd25fac4c8fe060aa6 Mon Sep 17 00:00:00 2001 From: hailin Date: Sun, 7 Dec 2025 10:59:45 -0800 Subject: [PATCH] =?UTF-8?q?refactor(identity-service):=20=E7=AE=80?= =?UTF-8?q?=E5=8C=96DeviceNameDto=E4=B8=BA=E6=8E=A5=E6=94=B6=E4=BB=BB?= =?UTF-8?q?=E6=84=8FJSON=E5=AF=B9=E8=B1=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将DeviceNameDto从class改为interface - 使用@IsObject()验证,允许前端传递任意设备信息字段 - 添加index signature允许扩展字段 - 后端只提取需要的字段存储到数据库 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../dto/request/auto-create-account.dto.ts | 75 ++++++------------- 1 file changed, 22 insertions(+), 53 deletions(-) diff --git a/backend/services/identity-service/src/api/dto/request/auto-create-account.dto.ts b/backend/services/identity-service/src/api/dto/request/auto-create-account.dto.ts index 7893d55b..0b07911d 100644 --- a/backend/services/identity-service/src/api/dto/request/auto-create-account.dto.ts +++ b/backend/services/identity-service/src/api/dto/request/auto-create-account.dto.ts @@ -1,55 +1,22 @@ -import { IsString, IsOptional, IsNotEmpty, Matches, ValidateNested } from 'class-validator'; +import { IsString, IsOptional, IsNotEmpty, Matches, IsObject } from 'class-validator'; import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; -import { Type } from 'class-transformer'; -export class DeviceNameDto { - @ApiPropertyOptional({ example: 'iPhone 15 Pro', description: '设备型号' }) - @IsOptional() - @IsString() - model?: string; - - @ApiPropertyOptional({ example: 'ios', description: '平台: ios, android, web' }) - @IsOptional() - @IsString() - platform?: string; - - @ApiPropertyOptional({ example: 'iOS 17.2', description: '系统版本' }) - @IsOptional() - @IsString() - osVersion?: string; - - @ApiPropertyOptional({ example: 'Apple', description: '品牌' }) - @IsOptional() - @IsString() - brand?: string; - - @ApiPropertyOptional({ example: 'Apple', description: '厂商' }) - @IsOptional() - @IsString() - manufacturer?: string; - - @ApiPropertyOptional({ example: 'iPhone15,2', description: '设备名' }) - @IsOptional() - @IsString() - device?: string; - - @ApiPropertyOptional({ example: 'iPhone15,2', description: '产品名' }) - @IsOptional() - @IsString() - product?: string; - - @ApiPropertyOptional({ example: 'qcom', description: '硬件名' }) - @IsOptional() - @IsString() - hardware?: string; - - @ApiPropertyOptional({ example: 33, description: 'SDK 版本 (Android)' }) - @IsOptional() - sdkInt?: number; - - @ApiPropertyOptional({ example: true, description: '是否真机' }) - @IsOptional() - isPhysicalDevice?: boolean; +/** + * 设备信息 - 接收任意 JSON 对象 + * 前端可以传递完整的设备硬件信息,后端只提取需要的字段存储 + */ +export interface DeviceNameDto { + model?: string; // 设备型号 + platform?: string; // 平台: ios, android, web + osVersion?: string; // 系统版本 + brand?: string; // 品牌 + manufacturer?: string; // 厂商 + device?: string; // 设备名 + product?: string; // 产品名 + hardware?: string; // 硬件名 + sdkInt?: number; // SDK 版本 (Android) + isPhysicalDevice?: boolean; // 是否真机 + [key: string]: unknown; // 允许其他字段 } export class AutoCreateAccountDto { @@ -58,10 +25,12 @@ export class AutoCreateAccountDto { @IsNotEmpty() deviceId: string; - @ApiPropertyOptional({ type: DeviceNameDto, description: '设备信息' }) + @ApiPropertyOptional({ + description: '设备信息 (JSON 对象)', + example: { model: 'iPhone 15 Pro', platform: 'ios', osVersion: '17.2' } + }) @IsOptional() - @ValidateNested() - @Type(() => DeviceNameDto) + @IsObject() deviceName?: DeviceNameDto; @ApiPropertyOptional({ example: 'ABC123', description: '邀请人推荐码' })