feat: 增加模板示例内容导入接口

This commit is contained in:
que01 committed 2026-09-23 01:25:29 +08:00
1 parent cd9352a849
commit d451c93398
2 files changed
+95

No files matched your search

@@ -201,6 +201,91 @@ class AdminWorkspaceController {
});
}
@Get("sample-content/preview")
async previewSampleContent(@Req() request: FastifyRequest): Promise<unknown> {
this.requireAdmin(request);
const brandId = this.brandId();
const [offerings, trustContent, fields] = await Promise.all([
this.prisma.offering.count({ where: { brandId } }),
this.prisma.trustContent.count({ where: { brandId } }),
this.prisma.brandFieldDefinition.count({ where: { brandId, source: "sample" } }),
]);
return {
templateKey: "doors",
alreadyImported: offerings > 0 || trustContent > 0 || fields > 0,
counts: { offerings: 4, trustContent: 4, fields: 4 },
};
}
@Post("sample-content/import")
async importSampleContent(@Req() request: FastifyRequest): Promise<unknown> {
const identity = this.requireAdmin(request);
const brandId = this.brandId();
const existing = await this.prisma.brandFieldDefinition.count({
where: { brandId, source: "sample" },
});
if (existing) throw new BadRequestException("示例内容已经导入");
const result = await this.prisma.$transaction(async (tx) => {
const offerings = await tx.offering.createMany({
data: [
["序章·入户门", "为别墅入口定制的整樘门系统", "entrance-door"],
["庭院·边界门", "连接建筑与庭院的定制门", "garden-door"],
["室内·静谧门", "统一室内空间秩序的户内门", "interior-door"],
["一对一门系统设计咨询", "从现场到方案的完整设计沟通", "custom"],
].map((item, sortOrder) => ({
brandId,
kind: sortOrder === 3 ? "service" : "product",
name: item[0]!,
summary: item[1]!,
categoryKey: item[2]!,
sortOrder,
isEnabled: true,
})),
});
const trust = await tx.trustContent.createMany({
data: ["主理人的门作观", "别墅门系统案例", "从测量到交付", "材料与工艺标准"].map(
(title, sortOrder) => ({
brandId,
type: ["profile", "portfolio", "process", "credential"][sortOrder]!,
title,
content: "示例内容,待品牌主理人完善。",
sortOrder,
isPublished: false,
}),
),
});
const fields = await tx.brandFieldDefinition.createMany({
data: [
["projectType", "项目类型", "select"],
["projectStage", "项目阶段", "select"],
["siteDescription", "项目概况", "textarea"],
["phone", "联系方式", "phone"],
].map((item, sortOrder) => ({
brandId,
scope: "inquiry",
key: item[0]!,
label: item[1]!,
type: item[2]!,
sortOrder,
source: "sample",
required: item[2] === "phone",
})),
});
await tx.capabilityAuditLog.create({
data: {
brandId,
capabilityKey: "doors",
actorId: identity.subject,
action: "sample_content_imported",
toStatus: "enabled",
config: { offerings: offerings.count, trustContent: trust.count, fields: fields.count },
},
});
return { offerings: offerings.count, trustContent: trust.count, fields: fields.count };
});
return { imported: true, counts: result };
}
@Patch("capabilities/:key")
async updateCapability(
@Req() request: FastifyRequest,