fix: 为微信登录补充请求校验
This commit is contained in:
1 parent
41e4cc0f1c
commit
6edb9d7a30
3 files changed
+17
-3
No files matched your search
@@ -4,3 +4,9 @@ export class AdminLoginDto {
|
|||||||
@IsString() username!: string;
|
@IsString() username!: string;
|
||||||
@IsString() @MinLength(8) password!: string;
|
@IsString() @MinLength(8) password!: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class WechatLoginDto {
|
||||||
|
@IsString()
|
||||||
|
@MinLength(1)
|
||||||
|
code!: string;
|
||||||
|
}
|
||||||
@@ -42,7 +42,7 @@ import {
|
|||||||
UpdateInquiryFormDto,
|
UpdateInquiryFormDto,
|
||||||
} from "./admin.dto.js";
|
} from "./admin.dto.js";
|
||||||
import { AdminAuthService } from "./admin-auth.service.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 type { FastifyRequest } from "fastify";
|
||||||
import { Transform } from "class-transformer";
|
import { Transform } from "class-transformer";
|
||||||
import type { TransformFnParams } from "class-transformer";
|
import type { TransformFnParams } from "class-transformer";
|
||||||
@@ -253,8 +253,8 @@ export class CustomerSessionController {
|
|||||||
) {}
|
) {}
|
||||||
|
|
||||||
@Post("wechat")
|
@Post("wechat")
|
||||||
async wechatLogin(@Body() body: { code?: string }): Promise<{ token: string }> {
|
async wechatLogin(@Body() body: WechatLoginDto): Promise<{ token: string }> {
|
||||||
const session = await this.wechatAuth.exchangeCode(body.code ?? "");
|
const session = await this.wechatAuth.exchangeCode(body.code);
|
||||||
const brand = await this.prisma.brandProfile.findFirst({ select: { id: true } });
|
const brand = await this.prisma.brandProfile.findFirst({ select: { id: true } });
|
||||||
if (!brand) throw new BadRequestException("品牌尚未初始化");
|
if (!brand) throw new BadRequestException("品牌尚未初始化");
|
||||||
await this.prisma.customerUser.upsert({
|
await this.prisma.customerUser.upsert({
|
||||||
|
|||||||
@@ -453,6 +453,14 @@ test("customer booking endpoints require a valid customer session", async () =>
|
|||||||
assert.deepEqual(JSON.parse(list.body), []);
|
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 () => {
|
test("customer booking DTO rejects incomplete package requests", async () => {
|
||||||
const response = await request("/customer/bookings", {
|
const response = await request("/customer/bookings", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
|||||||
Reference in new issue
Block a user