feat: 建立版本化模板注册表
This commit is contained in:
1 parent
3524a6f322
commit
a3434ce2b9
3 files changed
+55
-6
No files matched your search
@@ -49,7 +49,7 @@ import type { TransformFnParams } from "class-transformer";
|
||||
import { IsBoolean, IsEnum, IsOptional, IsString } from "class-validator";
|
||||
import { readIdentity, signIdentity } from "./auth.js";
|
||||
import { ApiExceptionFilter, RequestIdMiddleware } from "./http.js";
|
||||
import { brandTemplates, type BrandTemplateKey } from "@personal-brand/config";
|
||||
import { brandTemplates, getBrandTemplate } from "@personal-brand/config";
|
||||
|
||||
@Controller("health")
|
||||
export class HealthController {
|
||||
@@ -122,7 +122,7 @@ export class PublicTrustContentController {
|
||||
export class PublicTemplateController {
|
||||
@Get(":key")
|
||||
get(@Param("key") key: string): unknown {
|
||||
const template = brandTemplates[key as BrandTemplateKey];
|
||||
const template = getBrandTemplate(key);
|
||||
if (!template) throw new BadRequestException("行业模板不存在");
|
||||
return template;
|
||||
}
|
||||
@@ -354,7 +354,8 @@ export class AdminWorkspaceController {
|
||||
): Promise<unknown> {
|
||||
this.requireAdmin(request);
|
||||
const brandId = this.brandId();
|
||||
const template = brandTemplates[body.templateKey];
|
||||
const template = getBrandTemplate(body.templateKey);
|
||||
if (!template) throw new BadRequestException("行业模板不存在");
|
||||
const existing = await this.prisma.brandTemplateInstallation.findFirst({ where: { brandId } });
|
||||
if (existing) {
|
||||
if (existing.templateKey === body.templateKey)
|
||||
@@ -376,7 +377,7 @@ export class AdminWorkspaceController {
|
||||
] as const;
|
||||
return this.prisma.$transaction(async (tx) => {
|
||||
const installation = await tx.brandTemplateInstallation.create({
|
||||
data: { brandId, templateKey: body.templateKey, templateVersion: "1.0.0" },
|
||||
data: { brandId, templateKey: body.templateKey, templateVersion: template.version },
|
||||
});
|
||||
await tx.brandModule.createMany({
|
||||
data: modules.map(([type, title], sortOrder) => ({
|
||||
|
||||
@@ -103,10 +103,18 @@ export interface ApiErrorBody {
|
||||
}
|
||||
export interface BrandTemplateDefinition {
|
||||
key: "personal" | "food";
|
||||
version: string;
|
||||
name: string;
|
||||
description: string;
|
||||
serviceCategories: string[];
|
||||
trustContentTypes: string[];
|
||||
modules: Array<{
|
||||
key: string;
|
||||
type: string;
|
||||
title: string;
|
||||
required: boolean;
|
||||
}>;
|
||||
capabilities: string[];
|
||||
}
|
||||
export interface OfferingSection {
|
||||
type: "text" | "image-list" | "timeline" | "faq";
|
||||
|
||||
@@ -1,16 +1,31 @@
|
||||
export const configPackageName = "personal-brand-config";
|
||||
|
||||
export type BrandTemplateKey = "personal" | "food";
|
||||
|
||||
export type BrandTemplateModuleType = "identity" | "trust" | "offering" | "inquiry" | "contact";
|
||||
|
||||
export interface BrandTemplateModuleDefinition {
|
||||
key: string;
|
||||
type: BrandTemplateModuleType;
|
||||
title: string;
|
||||
required: boolean;
|
||||
}
|
||||
|
||||
export interface BrandTemplateDefinition {
|
||||
key: BrandTemplateKey;
|
||||
version: string;
|
||||
name: string;
|
||||
description: string;
|
||||
serviceCategories: string[];
|
||||
trustContentTypes: string[];
|
||||
modules: BrandTemplateModuleDefinition[];
|
||||
capabilities: string[];
|
||||
}
|
||||
export const brandTemplates: Record<BrandTemplateKey, BrandTemplateDefinition> = {
|
||||
|
||||
export const brandTemplates = {
|
||||
personal: {
|
||||
key: "personal",
|
||||
version: "1.0.0",
|
||||
name: "个人品牌",
|
||||
description: "围绕定位、信任、作品与合作建立个人品牌。",
|
||||
serviceCategories: ["consulting", "collaboration", "custom"],
|
||||
@@ -22,9 +37,18 @@ export const brandTemplates: Record<BrandTemplateKey, BrandTemplateDefinition> =
|
||||
"process",
|
||||
"testimonial",
|
||||
],
|
||||
modules: [
|
||||
{ key: "identity", type: "identity", title: "品牌身份", required: true },
|
||||
{ key: "trust", type: "trust", title: "信任内容", required: true },
|
||||
{ key: "offerings", type: "offering", title: "业务提供项", required: true },
|
||||
{ key: "inquiry", type: "inquiry", title: "联系与咨询", required: true },
|
||||
{ key: "contact", type: "contact", title: "品牌表达", required: true },
|
||||
],
|
||||
capabilities: ["offerings", "inquiry"],
|
||||
},
|
||||
food: {
|
||||
key: "food",
|
||||
version: "1.0.0",
|
||||
name: "餐饮模板",
|
||||
description: "适用于餐饮服务与套餐预约的行业模板。",
|
||||
serviceCategories: ["food-package", "private-chef", "custom"],
|
||||
@@ -36,5 +60,21 @@ export const brandTemplates: Record<BrandTemplateKey, BrandTemplateDefinition> =
|
||||
"process",
|
||||
"testimonial",
|
||||
],
|
||||
modules: [
|
||||
{ key: "identity", type: "identity", title: "品牌身份", required: true },
|
||||
{ key: "trust", type: "trust", title: "信任内容", required: true },
|
||||
{ key: "offerings", type: "offering", title: "菜单与服务", required: true },
|
||||
{ key: "inquiry", type: "inquiry", title: "预约与咨询", required: true },
|
||||
{ key: "contact", type: "contact", title: "品牌表达", required: true },
|
||||
],
|
||||
capabilities: ["offerings", "inquiry", "booking"],
|
||||
},
|
||||
};
|
||||
} satisfies Record<BrandTemplateKey, BrandTemplateDefinition>;
|
||||
|
||||
export function isBrandTemplateKey(value: string): value is BrandTemplateKey {
|
||||
return Object.prototype.hasOwnProperty.call(brandTemplates, value);
|
||||
}
|
||||
|
||||
export function getBrandTemplate(key: string): BrandTemplateDefinition | undefined {
|
||||
return isBrandTemplateKey(key) ? brandTemplates[key] : undefined;
|
||||
}
|
||||
Reference in new issue
Block a user