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 { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||||
import { Type } from 'class-transformer';
|
|
||||||
|
|
||||||
export class DeviceNameDto {
|
/**
|
||||||
@ApiPropertyOptional({ example: 'iPhone 15 Pro', description: '设备型号' })
|
* 设备信息 - 接收任意 JSON 对象
|
||||||
@IsOptional()
|
* 前端可以传递完整的设备硬件信息,后端只提取需要的字段存储
|
||||||
@IsString()
|
*/
|
||||||
model?: string;
|
export interface DeviceNameDto {
|
||||||
|
model?: string; // 设备型号
|
||||||
@ApiPropertyOptional({ example: 'ios', description: '平台: ios, android, web' })
|
platform?: string; // 平台: ios, android, web
|
||||||
@IsOptional()
|
osVersion?: string; // 系统版本
|
||||||
@IsString()
|
brand?: string; // 品牌
|
||||||
platform?: string;
|
manufacturer?: string; // 厂商
|
||||||
|
device?: string; // 设备名
|
||||||
@ApiPropertyOptional({ example: 'iOS 17.2', description: '系统版本' })
|
product?: string; // 产品名
|
||||||
@IsOptional()
|
hardware?: string; // 硬件名
|
||||||
@IsString()
|
sdkInt?: number; // SDK 版本 (Android)
|
||||||
osVersion?: string;
|
isPhysicalDevice?: boolean; // 是否真机
|
||||||
|
[key: string]: unknown; // 允许其他字段
|
||||||
@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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class AutoCreateAccountDto {
|
export class AutoCreateAccountDto {
|
||||||
|
|
@ -58,10 +25,12 @@ export class AutoCreateAccountDto {
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
deviceId: string;
|
deviceId: string;
|
||||||
|
|
||||||
@ApiPropertyOptional({ type: DeviceNameDto, description: '设备信息' })
|
@ApiPropertyOptional({
|
||||||
|
description: '设备信息 (JSON 对象)',
|
||||||
|
example: { model: 'iPhone 15 Pro', platform: 'ios', osVersion: '17.2' }
|
||||||
|
})
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@ValidateNested()
|
@IsObject()
|
||||||
@Type(() => DeviceNameDto)
|
|
||||||
deviceName?: DeviceNameDto;
|
deviceName?: DeviceNameDto;
|
||||||
|
|
||||||
@ApiPropertyOptional({ example: 'ABC123', description: '邀请人推荐码' })
|
@ApiPropertyOptional({ example: 'ABC123', description: '邀请人推荐码' })
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue