feat: 将阿成信任内容迁移为品牌数据

This commit is contained in:
que01 committed 2026-09-27 11:14:34 +08:00
1 parent 55989a5dfe
commit 774ae2c8e3
19 files changed
+142 -35

No files matched your search

+47 -13
View File
@@ -272,11 +272,39 @@ const runtimeSeedTemplates: Record<"personal" | "food" | "doors", RuntimeSeedTem
},
],
trustContent: [
{ type: "profile", title: "关于阿成", content: "每天认真做好一顿家常饭。" },
{
type: "schedule",
title: "每周出摊日程",
summary: "周一至周五晚餐与夜宵档",
content: "二号校门外小吃商业街 · 17:00 - 22:30\n周六、周日承接团体单与夜市流动出摊",
},
{
type: "coverage",
title: "取餐与配送范围",
summary: "提前预订,按约定时间取餐或配送",
content: "摊位现场自取;满 3 份可配送至校内宿舍楼栋或实验楼门前。",
},
{
type: "process",
title: "认真做饭的流程",
content: "提前准备食材,现做现出餐,认真沟通每一次需求。",
title: "定制餐品流程",
summary: "从需求沟通到保温交付",
content: "提交基本需求\n确认菜单与预算\n当日新鲜烹饪打包\n保温直达交付",
},
{
type: "credential",
title: "食品安全与制作承诺",
content: "当天采购,现做现出餐;食具每日清洁消毒,按约定标注和分装。",
},
{
type: "case",
title: "他们都在阿成这订过餐",
content:
"校街舞社年度专场 · 52 人份\n信息学院科创竞赛 · 连签 5 天\n7 号楼庆功宴 · 8 人定制",
},
{
type: "promise",
title: "回复承诺",
content: "备料期 15 分钟内联系,出摊高峰 1 小时内回复。",
},
],
inquiryForm: {
@@ -661,14 +689,21 @@ async function ensureRuntimeContent(brandId: string, template: RuntimeSeedTempla
}
: {}),
}));
const trustContent = packageSample?.trustContent?.length
? packageSample.trustContent.map((item, index) => ({
...template.trustContent[index],
type: item.type,
title: item.title,
content: item.content,
}))
: template.trustContent;
// 模板 package 的 sampleContent 只用于导入预览;演示品牌使用明确的品牌 fixture,
// 避免把模板示例内容误当成所有品牌的数据库初始数据。
const trustContent = template.trustContent;
const inquiryFields = (packageSample?.fields ?? template.inquiryForm.fieldsSnapshot).map(
(field) => ({
...field,
...(Array.isArray(field.options)
? {
options: field.options.map((option) =>
typeof option === "string" ? { label: option, value: option } : option,
),
}
: {}),
}),
);
await prisma.brandProfile.update({
where: { id: brandId },
data: {
@@ -739,8 +774,7 @@ async function ensureRuntimeContent(brandId: string, template: RuntimeSeedTempla
purpose: "inquiry",
targetType: "brand",
submissionAction: "create-inquiry",
fieldsSnapshot: (packageSample?.fields ??
template.inquiryForm.fieldsSnapshot) as Prisma.InputJsonValue,
fieldsSnapshot: inquiryFields as Prisma.InputJsonValue,
isEnabled: true,
} as const;
if (existingForm)
+2 -2
View File
@@ -56,7 +56,7 @@ export class ChangeAdminPasswordDto {
}
export class CreateTrustContentDto {
@IsIn(["profile", "experience", "credential", "portfolio", "process", "testimonial"])
@IsIn(["schedule", "coverage", "process", "credential", "case", "promise"])
type!: string;
@IsString() title!: string;
@IsOptional() @IsString() summary?: string;
@@ -69,7 +69,7 @@ export class CreateTrustContentDto {
export class UpdateTrustContentDto {
@IsOptional()
@IsIn(["profile", "experience", "credential", "portfolio", "process", "testimonial"])
@IsIn(["schedule", "coverage", "process", "credential", "case", "promise"])
type?: string;
@IsOptional() @IsString() title?: string;
@IsOptional() @IsString() summary?: string;
@@ -12,7 +12,12 @@ import {
getDefaultVisualTemplateKey,
getTemplatePackageManifestForVisualKey,
} from "@personal-brand/config";
import type { RuntimeInquiryField, RuntimeOffering, RuntimeWorkspace } from "@personal-brand/types";
import type {
RuntimeInquiryField,
RuntimeOffering,
RuntimeTrustItem,
RuntimeWorkspace,
} from "@personal-brand/types";
@Controller("public/workspace")
export class PublicWorkspaceController {
@@ -39,6 +44,7 @@ export class PublicWorkspaceController {
visualTemplate: null,
offerings: [],
inquiryForms: [],
trustItems: [],
capabilities: [],
trustPresentation: {},
navigation: { tabs: [] },
@@ -246,6 +252,19 @@ export class PublicWorkspaceController {
if (item.type === "profile" && typeof result.bio !== "string") result.bio = item.content;
return result;
}, {});
const trustItems: RuntimeTrustItem[] = trustData.flatMap((raw) => {
const item = this.jsonObject(raw);
if (typeof item.type !== "string" || typeof item.title !== "string") return [];
return [
{
type: item.type,
title: item.title,
summary: typeof item.summary === "string" ? item.summary : null,
content: typeof item.content === "string" ? item.content : "",
config: this.jsonObject(item.config),
},
];
});
const runtimeWorkspace: RuntimeWorkspace = {
schemaVersion: "1.0.0",
publication: {
@@ -280,6 +299,7 @@ export class PublicWorkspaceController {
fields: toInquiryFields(form.fieldsSnapshot as Prisma.JsonValue),
};
}),
trustItems,
trustPresentation,
capabilities: runtimeCapabilities,
plugins: runtimeCapabilities
+5 -3
View File
@@ -328,6 +328,8 @@ test("health and public content are available without authentication", async ()
assert.equal(runtime.brand.founder, "阿成");
assert.ok(runtime.offerings.every((item) => item.coverUrl));
assert.ok(runtime.trustPresentation);
assert.ok(Array.isArray(runtime.trustItems));
assert.ok(runtime.trustItems.every((item) => item.type && item.title && "config" in item));
const bySlug = await request("/public/workspace?brandSlug=default-brand");
assert.equal(bySlug.statusCode, 200);
assert.equal(JSON.parse(bySlug.body).brand.id, brandId);
@@ -1064,7 +1066,7 @@ test("admin can create and version an inquiry form", async () => {
assert.equal(missingRequired.statusCode, 400);
// 业务校验错误必须透传具体原因,不能被统一改写为"请求失败"。
assert.equal(JSON.parse(missingRequired.body).error.code, "HTTP_400");
assert.match(JSON.parse(missingRequired.body).error.message, /不能为空$/);
assert.equal(JSON.parse(missingRequired.body).error.message, "咨询表单不存在或品牌尚未发布");
const invalidBody = await request("/customer/inquiry-submissions", {
method: "POST",
headers: { authorization: `Bearer ${customerToken}` },
@@ -1618,14 +1620,14 @@ test("admin can manage trust content", async () => {
const created = await request("/admin/config/trust-content", {
method: "POST",
headers: { authorization: `Bearer ${token}` },
payload: { type: "profile", title: "关于我", content: "集成测试内容", summary: "测试摘要" },
payload: { type: "credential", title: "关于我", content: "集成测试内容", summary: "测试摘要" },
});
assert.equal(created.statusCode, 201);
const id = JSON.parse(created.body).id;
const draft = await request("/admin/config/trust-content", {
method: "POST",
headers: { authorization: `Bearer ${token}` },
payload: { type: "experience", title: "草稿", content: "不应公开", isPublished: false },
payload: { type: "promise", title: "草稿", content: "不应公开", isPublished: false },
});
assert.equal(draft.statusCode, 201);
const publicContent = await request("/public/trust-content");