feat: 收口多品牌与模板构建基础
This commit is contained in:
1 parent
0425a1c672
commit
77224ea51f
317 files changed
+11290
-1158
No files matched your search
@@ -27,7 +27,12 @@ import {
|
||||
UpdateInquirySubmissionDto,
|
||||
UpdateCapabilityInstallationDto,
|
||||
} from "./admin.dto.js";
|
||||
import { capabilityPlugins, getBrandTemplate, resolveCapabilities } from "@personal-brand/config";
|
||||
import {
|
||||
capabilityPlugins,
|
||||
getBrandTemplate,
|
||||
getTemplateSampleContent,
|
||||
resolveCapabilities,
|
||||
} from "@personal-brand/config";
|
||||
import { TemplateWorkspaceService } from "./template-workspace.service.js";
|
||||
import { validateFieldSnapshot, validateOfferingConfig } from "@personal-brand/validation";
|
||||
|
||||
@@ -176,15 +181,12 @@ class AdminWorkspaceController {
|
||||
@Get("capabilities")
|
||||
async listCapabilities(@Req() request: FastifyRequest): Promise<unknown> {
|
||||
const brandId = this.requireAdmin(request).brandId;
|
||||
const [brand, installations] = await Promise.all([
|
||||
this.prisma.brandProfile.findUnique({
|
||||
where: { id: brandId },
|
||||
select: { templateKey: true },
|
||||
}),
|
||||
const [templateKey, installations] = await Promise.all([
|
||||
this.templateWorkspace.getEffectiveTemplateKey(brandId),
|
||||
this.prisma.capabilityInstallation.findMany({ where: { brandId } }),
|
||||
]);
|
||||
const installed = new Map(installations.map((item) => [item.capabilityKey, item]));
|
||||
const template = getBrandTemplate(brand?.templateKey ?? "personal");
|
||||
const template = getBrandTemplate(templateKey);
|
||||
return (template ? resolveCapabilities(template.capabilities) : []).map((definition) => {
|
||||
const item = installed.get(definition.key);
|
||||
return {
|
||||
@@ -202,15 +204,22 @@ class AdminWorkspaceController {
|
||||
@Get("sample-content/preview")
|
||||
async previewSampleContent(@Req() request: FastifyRequest): Promise<unknown> {
|
||||
const brandId = this.requireAdmin(request).brandId;
|
||||
const templateKey = await this.templateWorkspace.getEffectiveTemplateKey(brandId);
|
||||
const sample = getTemplateSampleContent(templateKey);
|
||||
if (!sample) throw new BadRequestException("模板示例内容不存在");
|
||||
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",
|
||||
templateKey: sample.templateKey,
|
||||
alreadyImported: offerings > 0 || trustContent > 0 || fields > 0,
|
||||
counts: { offerings: 4, trustContent: 4, fields: 4 },
|
||||
counts: {
|
||||
offerings: sample.offerings.length,
|
||||
trustContent: sample.trustContent.length,
|
||||
fields: sample.fields.length,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -218,6 +227,9 @@ class AdminWorkspaceController {
|
||||
async importSampleContent(@Req() request: FastifyRequest): Promise<unknown> {
|
||||
const identity = this.requireAdmin(request);
|
||||
const brandId = identity.brandId;
|
||||
const templateKey = await this.templateWorkspace.getEffectiveTemplateKey(brandId);
|
||||
const sample = getTemplateSampleContent(templateKey);
|
||||
if (!sample) throw new BadRequestException("模板示例内容不存在");
|
||||
const existing = await this.prisma.brandFieldDefinition.count({
|
||||
where: { brandId, source: "sample" },
|
||||
});
|
||||
@@ -227,54 +239,42 @@ class AdminWorkspaceController {
|
||||
if (existing || existingOffering) 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) => ({
|
||||
data: sample.offerings.map((item, sortOrder) => ({
|
||||
brandId,
|
||||
kind: sortOrder === 3 ? "service" : "product",
|
||||
name: item[0]!,
|
||||
summary: item[1]!,
|
||||
config: { categoryKey: item[2]! },
|
||||
kind: item.kind,
|
||||
name: item.name,
|
||||
summary: item.summary,
|
||||
config: { categoryKey: item.categoryKey },
|
||||
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,
|
||||
}),
|
||||
),
|
||||
data: sample.trustContent.map((item, sortOrder) => ({
|
||||
brandId,
|
||||
type: item.type,
|
||||
title: item.title,
|
||||
content: item.content,
|
||||
sortOrder,
|
||||
isPublished: false,
|
||||
})),
|
||||
});
|
||||
const fields = await tx.brandFieldDefinition.createMany({
|
||||
data: [
|
||||
["projectType", "项目类型", "select"],
|
||||
["projectStage", "项目阶段", "select"],
|
||||
["siteDescription", "项目概况", "textarea"],
|
||||
["phone", "联系方式", "phone"],
|
||||
].map((item, sortOrder) => ({
|
||||
data: sample.fields.map((item, sortOrder) => ({
|
||||
brandId,
|
||||
scope: "inquiry",
|
||||
key: item[0]!,
|
||||
label: item[1]!,
|
||||
type: item[2]!,
|
||||
key: item.key,
|
||||
label: item.label,
|
||||
type: item.type,
|
||||
sortOrder,
|
||||
source: "sample",
|
||||
required: item[2] === "phone",
|
||||
required: item.required,
|
||||
})),
|
||||
});
|
||||
await tx.capabilityAuditLog.create({
|
||||
data: {
|
||||
brandId,
|
||||
capabilityKey: "doors",
|
||||
capabilityKey: sample.capabilityKey,
|
||||
actorId: identity.subject,
|
||||
action: "sample_content_imported",
|
||||
toStatus: "enabled",
|
||||
@@ -294,8 +294,9 @@ class AdminWorkspaceController {
|
||||
): Promise<unknown> {
|
||||
const identity = this.requireAdmin(request);
|
||||
const brandId = identity.brandId;
|
||||
const brand = await this.prisma.brandProfile.findUnique({ where: { id: brandId } });
|
||||
const template = getBrandTemplate(brand?.templateKey ?? "personal");
|
||||
const template = getBrandTemplate(
|
||||
await this.templateWorkspace.getEffectiveTemplateKey(brandId),
|
||||
);
|
||||
if (!template?.capabilities.includes(key as never) && !(key in capabilityPlugins))
|
||||
throw new BadRequestException("能力未被当前模板声明");
|
||||
const existing = await this.prisma.capabilityInstallation.findUnique({
|
||||
|
||||
Reference in new issue
Block a user