refactor: 拆分会话控制器模块

This commit is contained in:
que01 committed 2026-09-23 11:26:46 +08:00
1 parent 1ea757555d
commit 4c8bda57b1
3 files changed
+43 -35

No files matched your search

+2 -34
View File
@@ -33,12 +33,11 @@ import {
UpdateTrustContentDto,
} from "./admin.dto.js";
import { AdminAuthService } from "./admin-auth.service.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";
import { IsBoolean, IsEnum, IsOptional, IsString } from "class-validator";
import { readIdentity, signIdentity } from "./auth.js";
import { readIdentity } from "./auth.js";
import { ApiExceptionFilter, RequestIdMiddleware } from "./http.js";
import {
brandTemplates,
@@ -52,6 +51,7 @@ import { AdminWorkspaceController } from "./admin-workspace.controller.js";
import { TemplateWorkspaceService } from "./template-workspace.service.js";
import { AdminAccessService } from "./admin-access.service.js";
import { AdminMembershipGuard } from "./admin-membership.guard.js";
import { CustomerSessionController, AdminSessionController } from "./modules/session/session.controller.js";
import type {
RuntimeInquiryField,
RuntimeOffering,
@@ -597,38 +597,6 @@ export class CustomerInquirySubmissionController {
}
}
@Controller("customer/session")
export class CustomerSessionController {
constructor(
private readonly wechatAuth: WechatAuthService,
private readonly prisma: PrismaService,
) {}
@Post("wechat")
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({
where: { brandId_openid: { brandId: brand.id, openid: session.openid } },
update: { lastLoginAt: new Date() },
create: { brandId: brand.id, openid: session.openid },
});
return {
token: signIdentity({ subject: session.openid, brandId: brand.id, role: "customer" }),
};
}
}
@Controller("admin/session")
export class AdminSessionController {
constructor(private readonly auth: AdminAuthService) {}
@Post("login")
login(@Body() body: AdminLoginDto): Promise<{ token: string; displayName: string }> {
return this.auth.login(body.username, body.password);
}
}
class AdminBookingQueryDto {
@IsOptional()
@IsEnum(BookingStatus)