feat: 建立版本化模板注册表

This commit is contained in:
que01 committed 2026-09-20 17:37:57 +08:00
1 parent 3524a6f322
commit a3434ce2b9
3 files changed
+55 -6

No files matched your search

+5 -4
View File
@@ -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) => ({