refactor: 模板注册与默认模板收敛到目录驱动

This commit is contained in:
que01 committed 2026-10-12 10:00:46 +08:00
1 parent f87b26b201
commit 89fdfd7d83
25 files changed
+122 -96

No files matched your search

+8 -5
View File
@@ -1,6 +1,8 @@
import { BadRequestException, Injectable } from "@nestjs/common";
import { Prisma } from "@prisma/client";
import {
type BrandTemplateKey,
defaultBrandTemplateKey,
getBrandTemplate,
getVisualTemplate,
getVisualTemplateManifest,
@@ -9,7 +11,6 @@ import {
isVisualTemplateCompatible,
} from "@personal-brand/config";
import type { CreateTrustContentDto, UpdateTrustContentDto } from "./admin.dto.js";
import type { BrandTemplateKey } from "@personal-brand/types";
import { PrismaService } from "./prisma.service.js";
@Injectable()
@@ -27,7 +28,7 @@ export class TemplateWorkspaceService {
const visualKey =
typeof config.visualTemplateKey === "string"
? config.visualTemplateKey
: getDefaultVisualTemplateKey(brand?.templateKey ?? "personal");
: getDefaultVisualTemplateKey(brand?.templateKey ?? defaultBrandTemplateKey);
return (
getTemplatePackageManifestForVisualKey(visualKey)?.trustContentTypes?.map(
(item) => item.type,
@@ -72,10 +73,12 @@ export class TemplateWorkspaceService {
select: { templateKey: true },
}),
]);
const key = installation?.templateKey ?? brand?.templateKey ?? "personal";
return getBrandTemplate(key) ? (key as BrandTemplateKey) : "personal";
const key =
getBrandTemplate(installation?.templateKey ?? brand?.templateKey ?? defaultBrandTemplateKey)
?.key ?? defaultBrandTemplateKey;
return key;
}
async install(brandId: string, templateKey: "personal" | "food" | "doors") {
async install(brandId: string, templateKey: BrandTemplateKey) {
const template = getBrandTemplate(templateKey);
if (!template) throw new BadRequestException("行业模板不存在");
const [existing, brand] = await Promise.all([