From 6edb9d7a303c7cf5d28bcfc35d8157343b82d8e1 Mon Sep 17 00:00:00 2001 From: que01 Date: Mon, 21 Sep 2026 11:51:38 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=B8=BA=E5=BE=AE=E4=BF=A1=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E8=A1=A5=E5=85=85=E8=AF=B7=E6=B1=82=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/api/src/admin-auth.dto.ts | 6 ++++++ apps/api/src/main.ts | 6 +++--- apps/api/test/http.integration.test.js | 8 ++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/apps/api/src/admin-auth.dto.ts b/apps/api/src/admin-auth.dto.ts index aba2187..333eb3c 100644 --- a/apps/api/src/admin-auth.dto.ts +++ b/apps/api/src/admin-auth.dto.ts @@ -4,3 +4,9 @@ export class AdminLoginDto { @IsString() username!: string; @IsString() @MinLength(8) password!: string; } + +export class WechatLoginDto { + @IsString() + @MinLength(1) + code!: string; +} diff --git a/apps/api/src/main.ts b/apps/api/src/main.ts index 49db6ec..e8cfb7d 100644 --- a/apps/api/src/main.ts +++ b/apps/api/src/main.ts @@ -42,7 +42,7 @@ import { UpdateInquiryFormDto, } from "./admin.dto.js"; import { AdminAuthService } from "./admin-auth.service.js"; -import { AdminLoginDto } from "./admin-auth.dto.js"; +import { AdminLoginDto, WechatLoginDto } from "./admin-auth.dto.js"; import type { FastifyRequest } from "fastify"; import { Transform } from "class-transformer"; import type { TransformFnParams } from "class-transformer"; @@ -253,8 +253,8 @@ export class CustomerSessionController { ) {} @Post("wechat") - async wechatLogin(@Body() body: { code?: string }): Promise<{ token: string }> { - const session = await this.wechatAuth.exchangeCode(body.code ?? ""); + async wechatLogin(@Body() body: WechatLoginDto): Promise<{ token: string }> { + const session = await this.wechatAuth.exchangeCode(body.code); const brand = await this.prisma.brandProfile.findFirst({ select: { id: true } }); if (!brand) throw new BadRequestException("品牌尚未初始化"); await this.prisma.customerUser.upsert({ diff --git a/apps/api/test/http.integration.test.js b/apps/api/test/http.integration.test.js index cfa88a2..0a15ee3 100644 --- a/apps/api/test/http.integration.test.js +++ b/apps/api/test/http.integration.test.js @@ -453,6 +453,14 @@ test("customer booking endpoints require a valid customer session", async () => assert.deepEqual(JSON.parse(list.body), []); }); +test("wechat login validates the request DTO before exchanging the code", async () => { + const response = await request("/customer/session/wechat", { + method: "POST", + payload: {}, + }); + assert.equal(response.statusCode, 400); +}); + test("customer booking DTO rejects incomplete package requests", async () => { const response = await request("/customer/bookings", { method: "POST",