feat: 让模板声明驱动安装并保存快照
This commit is contained in:
1 parent
a3434ce2b9
commit
388032000a
6 files changed
+65
-18
No files matched your search
@@ -0,0 +1 @@
|
|||||||
|
ALTER TABLE "BrandTemplateInstallation" ADD COLUMN "configSnapshot" JSONB NOT NULL DEFAULT '{}';
|
||||||
@@ -90,6 +90,7 @@ model BrandTemplateInstallation {
|
|||||||
brand BrandProfile @relation(fields: [brandId], references: [id], onDelete: Cascade)
|
brand BrandProfile @relation(fields: [brandId], references: [id], onDelete: Cascade)
|
||||||
templateKey String
|
templateKey String
|
||||||
templateVersion String @default("1.0.0")
|
templateVersion String @default("1.0.0")
|
||||||
|
configSnapshot Json
|
||||||
installedAt DateTime @default(now())
|
installedAt DateTime @default(now())
|
||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
@@unique([brandId, templateKey])
|
@@unique([brandId, templateKey])
|
||||||
|
|||||||
+9
-17
@@ -362,25 +362,17 @@ export class AdminWorkspaceController {
|
|||||||
throw new BadRequestException("该模板已经安装");
|
throw new BadRequestException("该模板已经安装");
|
||||||
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) => {
|
return this.prisma.$transaction(async (tx) => {
|
||||||
const installation = await tx.brandTemplateInstallation.create({
|
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({
|
await tx.brandModule.createMany({
|
||||||
data: modules.map(([type, title], sortOrder) => ({
|
data: template.modules.map(({ type, title }, sortOrder) => ({
|
||||||
brandId,
|
brandId,
|
||||||
type,
|
type,
|
||||||
title,
|
title,
|
||||||
@@ -389,7 +381,7 @@ export class AdminWorkspaceController {
|
|||||||
})),
|
})),
|
||||||
});
|
});
|
||||||
await tx.brandFieldDefinition.createMany({
|
await tx.brandFieldDefinition.createMany({
|
||||||
data: fields.map(([scope, key, label, type], sortOrder) => ({
|
data: template.fields.map(({ scope, key, label, type, required }, sortOrder) => ({
|
||||||
brandId,
|
brandId,
|
||||||
scope,
|
scope,
|
||||||
key,
|
key,
|
||||||
@@ -397,7 +389,7 @@ export class AdminWorkspaceController {
|
|||||||
type,
|
type,
|
||||||
sortOrder,
|
sortOrder,
|
||||||
source: "core",
|
source: "core",
|
||||||
required: true,
|
required,
|
||||||
})),
|
})),
|
||||||
});
|
});
|
||||||
return { installation, template };
|
return { installation, template };
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ test("admin can install a template and public workspace exposes enabled configur
|
|||||||
assert.equal(JSON.parse(workspace.body).fields.length, 5);
|
assert.equal(JSON.parse(workspace.body).fields.length, 5);
|
||||||
const publicWorkspace = await request("/public/workspace");
|
const publicWorkspace = await request("/public/workspace");
|
||||||
assert.equal(publicWorkspace.statusCode, 200);
|
assert.equal(publicWorkspace.statusCode, 200);
|
||||||
assert.equal(JSON.parse(publicWorkspace.body).modules.length, 4);
|
assert.equal(JSON.parse(publicWorkspace.body).modules.length, 5);
|
||||||
assert.equal(JSON.parse(publicWorkspace.body).inquiryForm, null);
|
assert.equal(JSON.parse(publicWorkspace.body).inquiryForm, null);
|
||||||
const conflict = await request("/admin/workspace/install", {
|
const conflict = await request("/admin/workspace/install", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
|||||||
@@ -114,6 +114,13 @@ export interface BrandTemplateDefinition {
|
|||||||
title: string;
|
title: string;
|
||||||
required: boolean;
|
required: boolean;
|
||||||
}>;
|
}>;
|
||||||
|
fields: Array<{
|
||||||
|
scope: string;
|
||||||
|
key: string;
|
||||||
|
label: string;
|
||||||
|
type: string;
|
||||||
|
required: boolean;
|
||||||
|
}>;
|
||||||
capabilities: string[];
|
capabilities: string[];
|
||||||
}
|
}
|
||||||
export interface OfferingSection {
|
export interface OfferingSection {
|
||||||
|
|||||||
@@ -10,6 +10,13 @@ export interface BrandTemplateModuleDefinition {
|
|||||||
title: string;
|
title: string;
|
||||||
required: boolean;
|
required: boolean;
|
||||||
}
|
}
|
||||||
|
export interface BrandTemplateFieldDefinition {
|
||||||
|
scope: string;
|
||||||
|
key: string;
|
||||||
|
label: string;
|
||||||
|
type: string;
|
||||||
|
required: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
export interface BrandTemplateDefinition {
|
export interface BrandTemplateDefinition {
|
||||||
key: BrandTemplateKey;
|
key: BrandTemplateKey;
|
||||||
@@ -19,6 +26,7 @@ export interface BrandTemplateDefinition {
|
|||||||
serviceCategories: string[];
|
serviceCategories: string[];
|
||||||
trustContentTypes: string[];
|
trustContentTypes: string[];
|
||||||
modules: BrandTemplateModuleDefinition[];
|
modules: BrandTemplateModuleDefinition[];
|
||||||
|
fields: BrandTemplateFieldDefinition[];
|
||||||
capabilities: string[];
|
capabilities: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,6 +52,25 @@ export const brandTemplates = {
|
|||||||
{ key: "inquiry", type: "inquiry", title: "联系与咨询", required: true },
|
{ key: "inquiry", type: "inquiry", title: "联系与咨询", required: true },
|
||||||
{ key: "contact", type: "contact", title: "品牌表达", required: true },
|
{ key: "contact", type: "contact", title: "品牌表达", required: true },
|
||||||
],
|
],
|
||||||
|
fields: [
|
||||||
|
{ scope: "profile", key: "name", label: "品牌名称", type: "text", required: true },
|
||||||
|
{ scope: "profile", key: "tagline", label: "一句话定位", type: "text", required: true },
|
||||||
|
{ scope: "profile", key: "audience", label: "服务对象", type: "textarea", required: true },
|
||||||
|
{
|
||||||
|
scope: "profile",
|
||||||
|
key: "valueProposition",
|
||||||
|
label: "提供的价值",
|
||||||
|
type: "textarea",
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
scope: "profile",
|
||||||
|
key: "trustProof",
|
||||||
|
label: "信任证明入口",
|
||||||
|
type: "textarea",
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
capabilities: ["offerings", "inquiry"],
|
capabilities: ["offerings", "inquiry"],
|
||||||
},
|
},
|
||||||
food: {
|
food: {
|
||||||
@@ -67,6 +94,25 @@ export const brandTemplates = {
|
|||||||
{ key: "inquiry", type: "inquiry", title: "预约与咨询", required: true },
|
{ key: "inquiry", type: "inquiry", title: "预约与咨询", required: true },
|
||||||
{ key: "contact", type: "contact", title: "品牌表达", required: true },
|
{ key: "contact", type: "contact", title: "品牌表达", required: true },
|
||||||
],
|
],
|
||||||
|
fields: [
|
||||||
|
{ scope: "profile", key: "name", label: "品牌名称", type: "text", required: true },
|
||||||
|
{ scope: "profile", key: "tagline", label: "一句话定位", type: "text", required: true },
|
||||||
|
{ scope: "profile", key: "audience", label: "服务对象", type: "textarea", required: true },
|
||||||
|
{
|
||||||
|
scope: "profile",
|
||||||
|
key: "valueProposition",
|
||||||
|
label: "提供的价值",
|
||||||
|
type: "textarea",
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
scope: "profile",
|
||||||
|
key: "trustProof",
|
||||||
|
label: "信任证明入口",
|
||||||
|
type: "textarea",
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
capabilities: ["offerings", "inquiry", "booking"],
|
capabilities: ["offerings", "inquiry", "booking"],
|
||||||
},
|
},
|
||||||
} satisfies Record<BrandTemplateKey, BrandTemplateDefinition>;
|
} satisfies Record<BrandTemplateKey, BrandTemplateDefinition>;
|
||||||
|
|||||||
Reference in new issue
Block a user