refactor: 拆分会话控制器模块
This commit is contained in:
1 parent
1ea757555d
commit
4c8bda57b1
3 files changed
+43
-35
No files matched your search
@@ -3,7 +3,7 @@
|
|||||||
- 任务:多品牌后台与 API 架构收口
|
- 任务:多品牌后台与 API 架构收口
|
||||||
- 形态:epic
|
- 形态:epic
|
||||||
- 进度:1/3
|
- 进度:1/3
|
||||||
- 当前:API Controller 拆分
|
- 当前:API Controller 拆分(已完成 session 模块第一批迁移,继续拆分中)
|
||||||
- 真相文件:`SUBTASKS.csv`
|
- 真相文件:`SUBTASKS.csv`
|
||||||
|
|
||||||
## 已完成
|
## 已完成
|
||||||
@@ -11,3 +11,4 @@
|
|||||||
- 后台导航改为当前品牌工作区语义。
|
- 后台导航改为当前品牌工作区语义。
|
||||||
- Header 显示当前认证品牌名称。
|
- Header 显示当前认证品牌名称。
|
||||||
- 保持 membership 授权和现有 API 契约不变。
|
- 保持 membership 授权和现有 API 契约不变。
|
||||||
|
- `CustomerSessionController` 和 `AdminSessionController` 已迁移到 `modules/session/session.controller.ts`。
|
||||||
+2
-34
@@ -33,12 +33,11 @@ import {
|
|||||||
UpdateTrustContentDto,
|
UpdateTrustContentDto,
|
||||||
} from "./admin.dto.js";
|
} from "./admin.dto.js";
|
||||||
import { AdminAuthService } from "./admin-auth.service.js";
|
import { AdminAuthService } from "./admin-auth.service.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";
|
||||||
import { IsBoolean, IsEnum, IsOptional, IsString } from "class-validator";
|
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 { ApiExceptionFilter, RequestIdMiddleware } from "./http.js";
|
||||||
import {
|
import {
|
||||||
brandTemplates,
|
brandTemplates,
|
||||||
@@ -52,6 +51,7 @@ import { AdminWorkspaceController } from "./admin-workspace.controller.js";
|
|||||||
import { TemplateWorkspaceService } from "./template-workspace.service.js";
|
import { TemplateWorkspaceService } from "./template-workspace.service.js";
|
||||||
import { AdminAccessService } from "./admin-access.service.js";
|
import { AdminAccessService } from "./admin-access.service.js";
|
||||||
import { AdminMembershipGuard } from "./admin-membership.guard.js";
|
import { AdminMembershipGuard } from "./admin-membership.guard.js";
|
||||||
|
import { CustomerSessionController, AdminSessionController } from "./modules/session/session.controller.js";
|
||||||
import type {
|
import type {
|
||||||
RuntimeInquiryField,
|
RuntimeInquiryField,
|
||||||
RuntimeOffering,
|
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 {
|
class AdminBookingQueryDto {
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsEnum(BookingStatus)
|
@IsEnum(BookingStatus)
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
import { BadRequestException, Body, Controller, Post } from "@nestjs/common";
|
||||||
|
import { PrismaService } from "../../prisma.service.js";
|
||||||
|
import { WechatAuthService } from "../../wechat-auth.js";
|
||||||
|
import { AdminAuthService } from "../../admin-auth.service.js";
|
||||||
|
import { AdminLoginDto, WechatLoginDto } from "../../admin-auth.dto.js";
|
||||||
|
import { signIdentity } from "../../auth.js";
|
||||||
|
|
||||||
|
@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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user