refactor: 完成公开与客户控制器拆分

This commit is contained in:
que01 committed 2026-09-23 12:40:40 +08:00
1 parent 178ffc2c11
commit 4902a564f0
5 files changed
+214 -223

No files matched your search

@@ -0,0 +1,52 @@
import { BadRequestException, Controller, Get, Param } from "@nestjs/common";
import { Prisma } from "@prisma/client";
import { PrismaService } from "../../prisma.service.js";
@Controller("public/offerings")
export class PublicOfferingController {
constructor(private readonly prisma: PrismaService) {}
@Get()
async list(): Promise<unknown> {
const brandId = process.env.DEFAULT_BRAND_ID ?? "00000000-0000-0000-0000-000000000001";
const items = await this.prisma.offering.findMany({
where: { brandId, isEnabled: true },
orderBy: { sortOrder: "asc" },
include: {
inquiryForms: {
where: { isEnabled: true },
orderBy: { updatedAt: "desc" },
select: { id: true, name: true, purpose: true, targetType: true, version: true },
},
},
});
return items.map((item) => this.present(item));
}
@Get(":id")
async get(@Param("id") id: string): Promise<unknown> {
const item = await this.prisma.offering.findFirst({
where: {
id,
brandId: process.env.DEFAULT_BRAND_ID ?? "00000000-0000-0000-0000-000000000001",
isEnabled: true,
},
include: {
inquiryForms: {
where: { isEnabled: true },
orderBy: { updatedAt: "desc" },
select: { id: true, name: true, purpose: true, targetType: true, version: true },
},
},
});
if (!item) throw new BadRequestException("业务提供项不存在");
return this.present(item);
}
private present(item: { config: Prisma.JsonValue; [key: string]: unknown }): unknown {
const config = (item.config ?? {}) as Record<string, unknown>;
return {
...item,
sections: config.sections ?? [],
media: config.media ?? [],
cta: config.cta ?? null,
};
}
}