import { IsString, IsOptional, IsInt, IsNumber, IsArray, ValidateNested, MinLength, MaxLength, } from 'class-validator'; import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; import { Type } from 'class-transformer'; export class AddonConfigDto { @ApiProperty({ description: '配置键', example: 'appid' }) @IsString() config_key: string; @ApiProperty({ description: '配置名称', example: 'AppID' }) @IsString() config_name: string; @ApiProperty({ description: '配置值', example: 'wx123456' }) @IsString() config_value: string; @ApiProperty({ description: '配置类型', example: 'text' }) @IsString() config_type: string; @ApiPropertyOptional({ description: '配置描述', example: '微信小程序AppID' }) @IsOptional() @IsString() config_desc?: string; @ApiPropertyOptional({ description: '排序', example: 0 }) @IsOptional() @IsInt() config_sort?: number; @ApiPropertyOptional({ description: '是否必填', example: 1 }) @IsOptional() @IsInt() is_required?: number; } export class CreateAddonDto { @ApiProperty({ description: '插件名称', example: 'wechat' }) @IsString() @MinLength(2) @MaxLength(50) addon_name: string; @ApiProperty({ description: '插件标识', example: 'wechat' }) @IsString() @MinLength(2) @MaxLength(50) addon_key: string; @ApiProperty({ description: '插件标题', example: '微信插件' }) @IsString() @MaxLength(100) addon_title: string; @ApiPropertyOptional({ description: '插件描述', example: '微信相关功能插件' }) @IsOptional() @IsString() @MaxLength(500) addon_desc?: string; @ApiPropertyOptional({ description: '插件图标', example: '/addon/wechat/icon.png' }) @IsOptional() @IsString() addon_icon?: string; @ApiProperty({ description: '插件版本', example: '1.0.0' }) @IsString() addon_version: string; @ApiProperty({ description: '插件作者', example: 'NiuCloud' }) @IsString() @MaxLength(100) addon_author: string; @ApiPropertyOptional({ description: '插件官网', example: 'https://www.niucloud.com' }) @IsOptional() @IsString() addon_url?: string; @ApiPropertyOptional({ description: '插件配置', type: [AddonConfigDto] }) @IsOptional() @IsArray() @ValidateNested({ each: true }) @Type(() => AddonConfigDto) addon_config?: AddonConfigDto[]; @ApiPropertyOptional({ description: '排序', example: 0 }) @IsOptional() @IsInt() addon_sort?: number; } export class UpdateAddonDto { @ApiPropertyOptional({ description: '插件标题', example: '微信插件' }) @IsOptional() @IsString() @MaxLength(100) addon_title?: string; @ApiPropertyOptional({ description: '插件描述', example: '微信相关功能插件' }) @IsOptional() @IsString() @MaxLength(500) addon_desc?: string; @ApiPropertyOptional({ description: '插件图标', example: '/addon/wechat/icon.png' }) @IsOptional() @IsString() addon_icon?: string; @ApiPropertyOptional({ description: '插件版本', example: '1.0.1' }) @IsOptional() @IsString() addon_version?: string; @ApiPropertyOptional({ description: '插件作者', example: 'NiuCloud' }) @IsOptional() @IsString() @MaxLength(100) addon_author?: string; @ApiPropertyOptional({ description: '插件官网', example: 'https://www.niucloud.com' }) @IsOptional() @IsString() addon_url?: string; @ApiPropertyOptional({ description: '排序', example: 0 }) @IsOptional() @IsInt() addon_sort?: number; } export class QueryAddonDto { @ApiPropertyOptional({ description: '页码', example: 1 }) @IsOptional() @IsInt() page?: number; @ApiPropertyOptional({ description: '每页数量', example: 20 }) @IsOptional() @IsInt() limit?: number; @ApiPropertyOptional({ description: '关键词搜索', example: 'wechat' }) @IsOptional() @IsString() keyword?: string; @ApiPropertyOptional({ description: '状态筛选', example: 1 }) @IsOptional() @IsInt() addon_status?: number; @ApiPropertyOptional({ description: '是否安装', example: 1 }) @IsOptional() @IsInt() is_install?: number; }