refactor(identity-service): 简化DeviceNameDto为接收任意JSON对象
- 将DeviceNameDto从class改为interface - 使用@IsObject()验证,允许前端传递任意设备信息字段 - 添加index signature允许扩展字段 - 后端只提取需要的字段存储到数据库 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
0c7f9b6da9
commit
592f13e939
|
|
@ -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: '邀请人推荐码' })
|
||||
|
|
|
|||
Loading…
Reference in New Issue