fix: 保证品牌模板身份不被台账漂移
This commit is contained in:
1 parent
6073e72940
commit
aaeec14733
6 files changed
+53
-13
No files matched your search
@@ -13,10 +13,8 @@ import {
|
||||
} from "class-validator";
|
||||
import { brandTemplateKeys } from "@personal-brand/config";
|
||||
import type { BrandTemplateKey } from "@personal-brand/config";
|
||||
|
||||
export class UpdateBrandDto {
|
||||
@IsOptional() @IsString() name?: string;
|
||||
@IsOptional() @IsIn(brandTemplateKeys) templateKey?: BrandTemplateKey;
|
||||
@IsOptional() @IsString() tagline?: string;
|
||||
@IsOptional() @IsString() description?: string;
|
||||
@IsOptional() @IsString() avatarUrl?: string;
|
||||
|
||||
@@ -45,7 +45,7 @@ export async function buildBrandReleaseSnapshot(
|
||||
database.trustContent.findMany({ where: { brandId }, orderBy: { sortOrder: "asc" } }),
|
||||
database.capabilityInstallation.findMany({ where: { brandId } }),
|
||||
]);
|
||||
const templateKey = installation?.templateKey ?? brand?.templateKey ?? defaultBrandTemplateKey;
|
||||
const templateKey = brand?.templateKey ?? installation?.templateKey ?? defaultBrandTemplateKey;
|
||||
const config =
|
||||
brand?.config && typeof brand.config === "object" && !Array.isArray(brand.config)
|
||||
? (brand.config as Record<string, unknown>)
|
||||
|
||||
@@ -95,9 +95,9 @@ export function assemblePublicWorkspace(input: {
|
||||
) as Array<Record<string, unknown>>;
|
||||
const installationData = asRecord(releaseSnapshot.installation);
|
||||
const templateKey =
|
||||
asString(brandData.templateKey) ||
|
||||
asString(releaseSnapshot.templateKey) ||
|
||||
asString(installationData.templateKey) ||
|
||||
asString(brandData.templateKey) ||
|
||||
defaultBrandTemplateKey;
|
||||
const template = releaseSnapshot.templateDefinition ?? getBrandTemplate(templateKey);
|
||||
const capabilityData = asArray(releaseSnapshot.capabilities) as Array<Record<string, unknown>>;
|
||||
|
||||
@@ -91,12 +91,6 @@ export class TemplateWorkspaceService {
|
||||
select: { config: true, templateKey: true },
|
||||
}),
|
||||
]);
|
||||
if (existing)
|
||||
throw new BadRequestException(
|
||||
existing.templateKey === templateKey
|
||||
? "该模板已经安装"
|
||||
: "品牌已经安装主模板,更换行业模板不在本版本范围内",
|
||||
);
|
||||
// 一个品牌只使用一个行业模板(BrandProfile.templateKey 即身份)。安装只允许补建当前模板的版本台账,
|
||||
// 不得换成别的行业模板,否则会出现「身份是 A、台账是 B」的漂移,并把发布快照接到不适配的视觉模板上。
|
||||
const currentTemplate = brand?.templateKey ? getBrandTemplate(brand.templateKey) : undefined;
|
||||
@@ -104,6 +98,8 @@ export class TemplateWorkspaceService {
|
||||
throw new BadRequestException(
|
||||
`当前品牌已在使用「${currentTemplate.name}」行业模板,更换行业模板不在本版本范围内`,
|
||||
);
|
||||
if (existing && existing.templateKey === templateKey)
|
||||
throw new BadRequestException("该模板已经安装");
|
||||
const brandConfig =
|
||||
brand?.config && typeof brand.config === "object" && !Array.isArray(brand.config)
|
||||
? (brand.config as Record<string, unknown>)
|
||||
|
||||
Reference in new issue
Block a user