From 1760f9b82c481b27255dcf82980239e030d59c5f Mon Sep 17 00:00:00 2001 From: hailin Date: Sun, 18 Jan 2026 06:14:06 -0800 Subject: [PATCH] =?UTF-8?q?fix(trading):=20=E4=B8=BA=E6=89=80=E6=9C=89=20D?= =?UTF-8?q?TO=20=E6=B7=BB=E5=8A=A0=20class-validator=20=E8=A3=85=E9=A5=B0?= =?UTF-8?q?=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复 trading.controller、admin.controller、transfer.controller 的 DTO 验证问题,解决 App 下单时 400 错误。 Co-Authored-By: Claude Opus 4.5 --- .../trading-service/src/api/controllers/admin.controller.ts | 3 +++ .../src/api/controllers/trading.controller.ts | 6 ++++++ .../src/api/controllers/transfer.controller.ts | 2 ++ 3 files changed, 11 insertions(+) diff --git a/backend/services/trading-service/src/api/controllers/admin.controller.ts b/backend/services/trading-service/src/api/controllers/admin.controller.ts index f6abbf4c..885cab8f 100644 --- a/backend/services/trading-service/src/api/controllers/admin.controller.ts +++ b/backend/services/trading-service/src/api/controllers/admin.controller.ts @@ -1,14 +1,17 @@ import { Controller, Get, Post, Body, HttpCode, HttpStatus } from '@nestjs/common'; import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger'; +import { IsBoolean } from 'class-validator'; import { PrismaService } from '../../infrastructure/persistence/prisma/prisma.service'; import { TradingConfigRepository } from '../../infrastructure/persistence/repositories/trading-config.repository'; import { Public } from '../../shared/guards/jwt-auth.guard'; class SetBuyEnabledDto { + @IsBoolean() enabled: boolean; } class SetDepthEnabledDto { + @IsBoolean() enabled: boolean; } diff --git a/backend/services/trading-service/src/api/controllers/trading.controller.ts b/backend/services/trading-service/src/api/controllers/trading.controller.ts index d2a07540..dc3b88aa 100644 --- a/backend/services/trading-service/src/api/controllers/trading.controller.ts +++ b/backend/services/trading-service/src/api/controllers/trading.controller.ts @@ -1,13 +1,19 @@ import { Controller, Get, Post, Param, Query, Body, NotFoundException, Req } from '@nestjs/common'; import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiQuery, ApiBearerAuth } from '@nestjs/swagger'; +import { IsString, IsIn } from 'class-validator'; import { OrderService } from '../../application/services/order.service'; import { OrderRepository } from '../../infrastructure/persistence/repositories/order.repository'; import { TradingAccountRepository } from '../../infrastructure/persistence/repositories/trading-account.repository'; import { OrderType } from '../../domain/aggregates/order.aggregate'; class CreateOrderDto { + @IsIn(['BUY', 'SELL']) type: 'BUY' | 'SELL'; + + @IsString() price: string; + + @IsString() quantity: string; } diff --git a/backend/services/trading-service/src/api/controllers/transfer.controller.ts b/backend/services/trading-service/src/api/controllers/transfer.controller.ts index ec0de5f3..bb187bdf 100644 --- a/backend/services/trading-service/src/api/controllers/transfer.controller.ts +++ b/backend/services/trading-service/src/api/controllers/transfer.controller.ts @@ -1,8 +1,10 @@ import { Controller, Get, Post, Param, Query, Body, Req } from '@nestjs/common'; import { ApiTags, ApiOperation, ApiResponse, ApiBearerAuth, ApiQuery } from '@nestjs/swagger'; +import { IsString } from 'class-validator'; import { TransferService } from '../../application/services/transfer.service'; class TransferDto { + @IsString() amount: string; }