refactor: 按领域拆分会话和订单控制器
This commit is contained in:
1 parent
4c8bda57b1
commit
ee7f64c5f3
3 files changed
+107
-106
No files matched your search
+7
-106
@@ -17,26 +17,16 @@ import {
|
||||
ValidationPipe,
|
||||
} from "@nestjs/common";
|
||||
import { NestFactory } from "@nestjs/core";
|
||||
import { BookingStatus, Prisma } from "@prisma/client";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { FastifyAdapter } from "@nestjs/platform-fastify";
|
||||
import type { NestFastifyApplication } from "@nestjs/platform-fastify";
|
||||
import { PrismaService } from "./prisma.service.js";
|
||||
import { WechatAuthService } from "./wechat-auth.js";
|
||||
import { BookingService } from "./booking.service.js";
|
||||
import { CreateBookingDto, CreateInquirySubmissionDto } from "./booking.dto.js";
|
||||
import {
|
||||
CreateTagDto,
|
||||
CreateTrustContentDto,
|
||||
UpdateBookingStatusDto,
|
||||
UpdateBookingTagsDto,
|
||||
UpdateBrandDto,
|
||||
UpdateTrustContentDto,
|
||||
} from "./admin.dto.js";
|
||||
import { CreateTrustContentDto, UpdateBrandDto, UpdateTrustContentDto } from "./admin.dto.js";
|
||||
import { AdminAuthService } from "./admin-auth.service.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 } from "./auth.js";
|
||||
import { ApiExceptionFilter, RequestIdMiddleware } from "./http.js";
|
||||
import {
|
||||
@@ -51,7 +41,11 @@ 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 {
|
||||
CustomerSessionController,
|
||||
AdminSessionController,
|
||||
} from "./modules/session/session.controller.js";
|
||||
import { AdminBookingController } from "./modules/admin/admin-booking.controller.js";
|
||||
import type {
|
||||
RuntimeInquiryField,
|
||||
RuntimeOffering,
|
||||
@@ -597,26 +591,6 @@ export class CustomerInquirySubmissionController {
|
||||
}
|
||||
}
|
||||
|
||||
class AdminBookingQueryDto {
|
||||
@IsOptional()
|
||||
@IsEnum(BookingStatus)
|
||||
status?: BookingStatus;
|
||||
|
||||
@IsOptional()
|
||||
@Transform((params: TransformFnParams): unknown => {
|
||||
const value: unknown = params.value;
|
||||
if (value === "true") return true;
|
||||
if (value === "false") return false;
|
||||
return value;
|
||||
})
|
||||
@IsBoolean()
|
||||
unreadOnly?: boolean;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
tagId?: string;
|
||||
}
|
||||
|
||||
@Controller("customer/bookings")
|
||||
export class CustomerBookingController {
|
||||
constructor(
|
||||
@@ -671,79 +645,6 @@ export class CustomerBookingController {
|
||||
}
|
||||
}
|
||||
|
||||
@Controller("admin/bookings")
|
||||
export class AdminBookingController {
|
||||
constructor(private readonly bookings: BookingService) {}
|
||||
@Get()
|
||||
list(@Req() request: FastifyRequest, @Query() query: AdminBookingQueryDto): Promise<unknown> {
|
||||
const brandId = this.requireAdmin(request);
|
||||
return this.bookings.listForAdmin(brandId, query);
|
||||
}
|
||||
|
||||
@Get("unread-count")
|
||||
unreadCount(@Req() request: FastifyRequest): Promise<unknown> {
|
||||
const brandId = this.requireAdmin(request);
|
||||
return this.bookings.unreadCountForAdmin(brandId);
|
||||
}
|
||||
|
||||
@Get(":id")
|
||||
detail(@Req() request: FastifyRequest, @Param("id") id: string): Promise<unknown> {
|
||||
const brandId = this.requireAdmin(request);
|
||||
return this.bookings.getForAdmin(brandId, id);
|
||||
}
|
||||
@Post(":id/status")
|
||||
update(
|
||||
@Req() request: FastifyRequest,
|
||||
@Param("id") id: string,
|
||||
@Body()
|
||||
body: UpdateBookingStatusDto,
|
||||
): Promise<unknown> {
|
||||
const brandId = this.requireAdmin(request);
|
||||
return this.bookings.updateStatus(brandId, id, body.status, body.adminNote);
|
||||
}
|
||||
|
||||
@Post(":id/read")
|
||||
markRead(@Req() request: FastifyRequest, @Param("id") id: string): Promise<unknown> {
|
||||
const brandId = this.requireAdmin(request);
|
||||
return this.bookings.markRead(brandId, id);
|
||||
}
|
||||
|
||||
@Post(":id/tags")
|
||||
updateTags(
|
||||
@Req() request: FastifyRequest,
|
||||
@Param("id") id: string,
|
||||
@Body() body: UpdateBookingTagsDto,
|
||||
): Promise<unknown> {
|
||||
const brandId = this.requireAdmin(request);
|
||||
return this.bookings.updateTags(brandId, id, body.tagIds);
|
||||
}
|
||||
|
||||
@Get("/tags")
|
||||
listTags(@Req() request: FastifyRequest): Promise<unknown> {
|
||||
const brandId = this.requireAdmin(request);
|
||||
return this.bookings.listTags(brandId);
|
||||
}
|
||||
|
||||
@Post("/tags")
|
||||
createTag(@Req() request: FastifyRequest, @Body() body: CreateTagDto): Promise<unknown> {
|
||||
const brandId = this.requireAdmin(request);
|
||||
return this.bookings.createTag(brandId, body.name);
|
||||
}
|
||||
|
||||
private requireAdmin(request: FastifyRequest): string {
|
||||
const token = request.headers.authorization?.replace(/^Bearer\s+/i, "");
|
||||
if (!token) throw new UnauthorizedException("缺少管理员登录态");
|
||||
let identity;
|
||||
try {
|
||||
identity = readIdentity(token);
|
||||
} catch {
|
||||
throw new UnauthorizedException("管理员登录态无效或已过期");
|
||||
}
|
||||
if (identity.role !== "admin") throw new ForbiddenException("无管理员权限");
|
||||
return identity.brandId;
|
||||
}
|
||||
}
|
||||
|
||||
@Controller("admin/config")
|
||||
export class AdminConfigController {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
Reference in new issue
Block a user