feat: 让模板声明驱动安装并保存快照

This commit is contained in:
que01 committed 2026-09-20 17:48:33 +08:00
1 parent a3434ce2b9
commit 388032000a
6 files changed
+65 -18

No files matched your search

+9 -17
View File
@@ -362,25 +362,17 @@ export class AdminWorkspaceController {
throw new BadRequestException("该模板已经安装");
throw new BadRequestException("品牌已经安装主模板,请先完成模板切换流程");
}
const modules = [
["text", "品牌介绍"],
["trust-content", "信任证明"],
["services", "服务与合作"],
["inquiry", "咨询入口"],
] as const;
const fields = [
["profile", "name", "品牌名称", "text"],
["profile", "tagline", "一句话定位", "text"],
["profile", "audience", "服务对象", "textarea"],
["profile", "valueProposition", "提供的价值", "textarea"],
["profile", "trustProof", "信任证明入口", "textarea"],
] as const;
return this.prisma.$transaction(async (tx) => {
const installation = await tx.brandTemplateInstallation.create({
data: { brandId, templateKey: body.templateKey, templateVersion: template.version },
data: {
brandId,
templateKey: body.templateKey,
templateVersion: template.version,
configSnapshot: template as unknown as Prisma.InputJsonValue,
},
});
await tx.brandModule.createMany({
data: modules.map(([type, title], sortOrder) => ({
data: template.modules.map(({ type, title }, sortOrder) => ({
brandId,
type,
title,
@@ -389,7 +381,7 @@ export class AdminWorkspaceController {
})),
});
await tx.brandFieldDefinition.createMany({
data: fields.map(([scope, key, label, type], sortOrder) => ({
data: template.fields.map(({ scope, key, label, type, required }, sortOrder) => ({
brandId,
scope,
key,
@@ -397,7 +389,7 @@ export class AdminWorkspaceController {
type,
sortOrder,
source: "core",
required: true,
required,
})),
});
return { installation, template };