refactor: 拆分品牌业务类型与页面方案
CI / Static checks (push) Has been cancelled
CI / Production build (push) Has been cancelled
CI / API integration (push) Has been cancelled
CI / Taro builds (acheng-campus-food) (push) Has been cancelled
CI / Taro builds (atelier-solopreneur) (push) Has been cancelled
CI / Taro builds (linjing-editorial) (push) Has been cancelled
CI / Browser regression (push) Has been cancelled
CI / Static checks (push) Has been cancelled
CI / Production build (push) Has been cancelled
CI / API integration (push) Has been cancelled
CI / Taro builds (acheng-campus-food) (push) Has been cancelled
CI / Taro builds (atelier-solopreneur) (push) Has been cancelled
CI / Taro builds (linjing-editorial) (push) Has been cancelled
CI / Browser regression (push) Has been cancelled
This commit is contained in:
1 parent
f02e2cafbb
commit
0d9f4a7d6f
86 files changed
+4111
-1543
No files matched your search
@@ -11,6 +11,7 @@ import {
|
||||
MinLength,
|
||||
Matches,
|
||||
Max,
|
||||
MaxLength,
|
||||
Min,
|
||||
} from "class-validator";
|
||||
import { brandTemplateKeys } from "@personal-brand/config";
|
||||
@@ -53,6 +54,26 @@ export class CreateBrandMemberDto {
|
||||
@IsIn(["owner", "editor"]) role!: "owner" | "editor";
|
||||
}
|
||||
|
||||
export class CreateBrandDto {
|
||||
@IsString()
|
||||
@MinLength(1)
|
||||
@MaxLength(80)
|
||||
name!: string;
|
||||
|
||||
@IsString()
|
||||
@Matches(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, {
|
||||
message: "slug 只能包含小写字母、数字和连字符",
|
||||
})
|
||||
@MaxLength(80)
|
||||
slug!: string;
|
||||
|
||||
@IsIn(brandTemplateKeys)
|
||||
businessType!: BrandTemplateKey;
|
||||
|
||||
@IsUUID()
|
||||
templatePackageVersionId!: string;
|
||||
}
|
||||
|
||||
export class ChangeAdminPasswordDto {
|
||||
@IsString() currentPassword!: string;
|
||||
@IsString() @MinLength(8) newPassword!: string;
|
||||
|
||||
@@ -3,7 +3,8 @@ import { Body, Controller, Get, Param, Patch, Post, Req, Res } from "@nestjs/com
|
||||
import type { FastifyReply, FastifyRequest } from "fastify";
|
||||
import { setAdminSessionCookie } from "../../admin-session-cookie.js";
|
||||
import { requireAdminIdentity } from "../../admin-access.identity.js";
|
||||
import { CreateBrandMemberDto, UpdateBrandMemberDto } from "../../admin.dto.js";
|
||||
import { signIdentity } from "../../auth.js";
|
||||
import { CreateBrandDto, CreateBrandMemberDto, UpdateBrandMemberDto } from "../../admin.dto.js";
|
||||
import { TenantService } from "./tenant.service.js";
|
||||
|
||||
@AdminBrand()
|
||||
@@ -11,10 +12,38 @@ import { TenantService } from "./tenant.service.js";
|
||||
export class TenantController {
|
||||
constructor(private readonly tenants: TenantService) {}
|
||||
|
||||
@AdminRoles(["owner"])
|
||||
@Get("creation-options")
|
||||
async creationOptions(): Promise<unknown> {
|
||||
return this.tenants.getCreationOptions();
|
||||
}
|
||||
|
||||
@AdminRoles(["owner"])
|
||||
@Post()
|
||||
async create(
|
||||
@Req() request: FastifyRequest,
|
||||
@Body() body: CreateBrandDto,
|
||||
@Res({ passthrough: true }) reply: FastifyReply,
|
||||
): Promise<{ role: string; brand: unknown }> {
|
||||
const identity = adminIdentity(request);
|
||||
const requestId = request.headers["x-request-id"]?.toString() ?? request.id;
|
||||
const brand = await this.tenants.createBrand(identity, body, requestId);
|
||||
setAdminSessionCookie(
|
||||
reply,
|
||||
signIdentity({
|
||||
subject: identity.subject,
|
||||
brandId: brand.id,
|
||||
role: "admin",
|
||||
...(identity.tokenVersion === undefined ? {} : { tokenVersion: identity.tokenVersion }),
|
||||
}),
|
||||
);
|
||||
return { role: "owner", brand };
|
||||
}
|
||||
|
||||
@AdminRoles(["owner", "admin", "platform-admin"])
|
||||
@Get("members")
|
||||
async listMembers(@Req() request: FastifyRequest): Promise<unknown> {
|
||||
const current = this.adminIdentity(request);
|
||||
const current = adminIdentity(request);
|
||||
return this.tenants.listMembers(current.brandId);
|
||||
}
|
||||
|
||||
@@ -24,7 +53,7 @@ export class TenantController {
|
||||
@Req() request: FastifyRequest,
|
||||
@Body() body: CreateBrandMemberDto,
|
||||
): Promise<unknown> {
|
||||
const actor = this.adminIdentity(request);
|
||||
const actor = adminIdentity(request);
|
||||
return this.tenants.createMember(actor.brandId, body);
|
||||
}
|
||||
|
||||
@@ -35,13 +64,13 @@ export class TenantController {
|
||||
@Param("id") id: string,
|
||||
@Body() body: UpdateBrandMemberDto,
|
||||
): Promise<unknown> {
|
||||
const actor = this.adminIdentity(request);
|
||||
const actor = adminIdentity(request);
|
||||
return this.tenants.updateMember(actor.brandId, actor.subject, id, body);
|
||||
}
|
||||
|
||||
@Get()
|
||||
async list(@Req() request: FastifyRequest): Promise<unknown> {
|
||||
const identity = this.adminIdentity(request);
|
||||
const identity = adminIdentity(request);
|
||||
return this.tenants.listMemberships(identity.subject);
|
||||
}
|
||||
|
||||
@@ -51,13 +80,13 @@ export class TenantController {
|
||||
@Param("brandId") brandId: string,
|
||||
@Res({ passthrough: true }) reply: FastifyReply,
|
||||
): Promise<{ role: string; brand: unknown }> {
|
||||
const identity = this.adminIdentity(request);
|
||||
const identity = adminIdentity(request);
|
||||
const result = await this.tenants.switchBrand(identity, brandId);
|
||||
setAdminSessionCookie(reply, result.token);
|
||||
return { role: result.role, brand: result.brand };
|
||||
}
|
||||
}
|
||||
|
||||
private adminIdentity(request: FastifyRequest) {
|
||||
return requireAdminIdentity(request);
|
||||
}
|
||||
function adminIdentity(request: FastifyRequest) {
|
||||
return requireAdminIdentity(request);
|
||||
}
|
||||
@@ -5,15 +5,107 @@ import {
|
||||
Injectable,
|
||||
} from "@nestjs/common";
|
||||
import bcrypt from "bcryptjs";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { getBrandTemplate } from "@personal-brand/config";
|
||||
import { PrismaService } from "../../prisma.service.js";
|
||||
import { signIdentity } from "../../auth.js";
|
||||
import type { CreateBrandMemberDto, UpdateBrandMemberDto } from "../../admin.dto.js";
|
||||
import type {
|
||||
CreateBrandDto,
|
||||
CreateBrandMemberDto,
|
||||
UpdateBrandMemberDto,
|
||||
} from "../../admin.dto.js";
|
||||
import { TemplateWorkspaceService } from "../../template-workspace.service.js";
|
||||
|
||||
type AdminIdentity = { subject: string; brandId: string; tokenVersion?: number };
|
||||
|
||||
@Injectable()
|
||||
export class TenantService {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
constructor(
|
||||
private readonly prisma: PrismaService,
|
||||
private readonly templateWorkspace: TemplateWorkspaceService,
|
||||
) {}
|
||||
|
||||
async getCreationOptions() {
|
||||
const catalog = await this.templateWorkspace.getPageSchemeCatalog();
|
||||
// 创建品牌只应从每个页面方案的最新已发布版本开始;旧版本仍可在页面方案页显式切换。
|
||||
return {
|
||||
...catalog,
|
||||
pageSchemes: catalog.pageSchemes.filter((scheme) => scheme.isLatestForPackage),
|
||||
};
|
||||
}
|
||||
|
||||
async createBrand(identity: AdminIdentity, body: CreateBrandDto, requestId?: string) {
|
||||
const template = getBrandTemplate(body.businessType);
|
||||
if (!template) throw new BadRequestException("业务类型不存在");
|
||||
const name = body.name.trim();
|
||||
const slug = body.slug.trim();
|
||||
if (!name || !slug) throw new BadRequestException("品牌名称和小程序地址标识不能为空");
|
||||
const packageVersion = await this.templateWorkspace.resolveInstallablePackageVersion(
|
||||
body.businessType,
|
||||
body.templatePackageVersionId,
|
||||
);
|
||||
|
||||
try {
|
||||
return await this.prisma.$transaction(async (tx) => {
|
||||
const brand = await tx.brandProfile.create({
|
||||
data: {
|
||||
name,
|
||||
slug,
|
||||
templateKey: body.businessType,
|
||||
config: {},
|
||||
},
|
||||
});
|
||||
await tx.brandTemplateInstallation.create({
|
||||
data: {
|
||||
brandId: brand.id,
|
||||
templateKey: body.businessType,
|
||||
templateVersion: packageVersion.version,
|
||||
templatePackageVersionId: packageVersion.id,
|
||||
contentChecksum: packageVersion.contentChecksum,
|
||||
configSnapshot: packageVersion.manifestSnapshot as Prisma.InputJsonValue,
|
||||
},
|
||||
});
|
||||
await tx.brandFieldDefinition.createMany({
|
||||
data: template.fields.map(({ scope, key, label, type, required }, sortOrder) => ({
|
||||
brandId: brand.id,
|
||||
scope,
|
||||
key,
|
||||
label,
|
||||
type,
|
||||
required,
|
||||
sortOrder,
|
||||
source: "core",
|
||||
})),
|
||||
});
|
||||
await tx.brandMembership.create({
|
||||
data: {
|
||||
adminUserId: identity.subject,
|
||||
brandId: brand.id,
|
||||
role: "owner",
|
||||
isEnabled: true,
|
||||
},
|
||||
});
|
||||
await tx.templatePackageAuditLog.create({
|
||||
data: {
|
||||
templatePackageVersionId: packageVersion.id,
|
||||
actorId: identity.subject,
|
||||
action: "brand_created",
|
||||
...(requestId ? { requestId } : {}),
|
||||
metadata: {
|
||||
brandId: brand.id,
|
||||
businessType: body.businessType,
|
||||
slug: brand.slug,
|
||||
},
|
||||
},
|
||||
});
|
||||
return brand;
|
||||
});
|
||||
} catch (error) {
|
||||
if (error instanceof Prisma.PrismaClientKnownRequestError && error.code === "P2002")
|
||||
throw new ConflictException("小程序地址标识已被使用,请更换后重试");
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
listMembers(brandId: string) {
|
||||
return this.prisma.brandMembership.findMany({
|
||||
|
||||
@@ -10,6 +10,13 @@ import { requireAdminIdentity } from "../../admin-access.identity.js";
|
||||
class AdminTemplateController {
|
||||
constructor(private readonly templateWorkspace: TemplateWorkspaceService) {}
|
||||
|
||||
@AdminRoles(["owner", "admin", "platform-admin"])
|
||||
@Get("template/options")
|
||||
options(@Req() request: FastifyRequest): Promise<unknown> {
|
||||
return this.templateWorkspace.getPageSchemeOptions(requireAdminIdentity(request).brandId);
|
||||
}
|
||||
|
||||
@AdminRoles(["owner", "admin", "platform-admin"])
|
||||
@Get("template/preview")
|
||||
preview(@Req() request: FastifyRequest): Promise<unknown> {
|
||||
return this.templateWorkspace.preview(requireAdminIdentity(request).brandId);
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
const SEMVER_PATTERN =
|
||||
/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
|
||||
const fallbackVersionCollator = new Intl.Collator("en", {
|
||||
numeric: true,
|
||||
sensitivity: "base",
|
||||
});
|
||||
|
||||
type VersionOrderable = {
|
||||
version: string;
|
||||
importedAt?: Date;
|
||||
createdAt?: Date;
|
||||
};
|
||||
|
||||
function comparePrerelease(left: string, right: string) {
|
||||
if (left === right) return 0;
|
||||
if (!left) return 1;
|
||||
if (!right) return -1;
|
||||
const leftParts = left.split(".");
|
||||
const rightParts = right.split(".");
|
||||
for (let index = 0; index < Math.max(leftParts.length, rightParts.length); index += 1) {
|
||||
const leftPart = leftParts[index];
|
||||
const rightPart = rightParts[index];
|
||||
if (leftPart === undefined) return -1;
|
||||
if (rightPart === undefined) return 1;
|
||||
if (leftPart === rightPart) continue;
|
||||
const leftNumeric = /^\d+$/.test(leftPart);
|
||||
const rightNumeric = /^\d+$/.test(rightPart);
|
||||
if (leftNumeric && rightNumeric) return Number(leftPart) - Number(rightPart);
|
||||
if (leftNumeric !== rightNumeric) return leftNumeric ? -1 : 1;
|
||||
return leftPart.localeCompare(rightPart);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
export function compareTemplateVersions(left: string, right: string) {
|
||||
const leftMatch = SEMVER_PATTERN.exec(left);
|
||||
const rightMatch = SEMVER_PATTERN.exec(right);
|
||||
if (!leftMatch || !rightMatch) return fallbackVersionCollator.compare(left, right);
|
||||
for (let index = 1; index <= 3; index += 1) {
|
||||
const difference = Number(leftMatch[index]) - Number(rightMatch[index]);
|
||||
if (difference !== 0) return difference;
|
||||
}
|
||||
return comparePrerelease(leftMatch[4] ?? "", rightMatch[4] ?? "");
|
||||
}
|
||||
|
||||
/** 按 SemVer 从新到旧排序;同版本使用导入和创建时间保证顺序稳定。 */
|
||||
export function compareTemplateVersionOrder(left: VersionOrderable, right: VersionOrderable) {
|
||||
const versionOrder = compareTemplateVersions(right.version, left.version);
|
||||
if (versionOrder !== 0) return versionOrder;
|
||||
const importedOrder = (right.importedAt?.getTime() ?? 0) - (left.importedAt?.getTime() ?? 0);
|
||||
if (importedOrder !== 0) return importedOrder;
|
||||
return (right.createdAt?.getTime() ?? 0) - (left.createdAt?.getTime() ?? 0);
|
||||
}
|
||||
|
||||
export function latestTemplateVersion<T extends VersionOrderable>(versions: readonly T[]) {
|
||||
return versions.reduce<T | undefined>((latest, current) => {
|
||||
if (!latest || compareTemplateVersionOrder(current, latest) < 0) return current;
|
||||
return latest;
|
||||
}, undefined);
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import type { TemplatePackageVersion } from "@prisma/client";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import {
|
||||
type BrandTemplateKey,
|
||||
brandTemplateKeys,
|
||||
getBrandTemplate,
|
||||
getVisualTemplate,
|
||||
getVisualTemplateManifest,
|
||||
@@ -14,10 +15,99 @@ import type { CreateTrustContentDto, UpdateTrustContentDto } from "./admin.dto.j
|
||||
import type { RollbackTemplateDto, UpgradeTemplateDto } from "./admin.dto.js";
|
||||
import { PrismaService } from "./prisma.service.js";
|
||||
import { recordTemplateOperationFailure } from "./modules/admin/template-operation-failure.js";
|
||||
import { compareTemplateVersions, latestTemplateVersion } from "./template-version-order.js";
|
||||
|
||||
@Injectable()
|
||||
export class TemplateWorkspaceService {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
async getPageSchemeCatalog() {
|
||||
const versions = await this.prisma.templatePackageVersion.findMany({
|
||||
where: { status: "published" },
|
||||
orderBy: [{ importedAt: "desc" }, { createdAt: "desc" }],
|
||||
});
|
||||
const candidates = versions.flatMap((version) => {
|
||||
const manifest = record(version.manifestSnapshot);
|
||||
const visualTemplateKey = manifest.visualTemplateKey;
|
||||
if (
|
||||
manifest.packageKey !== version.packageKey ||
|
||||
manifest.version !== version.version ||
|
||||
typeof visualTemplateKey !== "string" ||
|
||||
visualTemplateKey !== version.packageKey
|
||||
)
|
||||
return [];
|
||||
const visualTemplate = getVisualTemplate(visualTemplateKey);
|
||||
const visualManifest = getVisualTemplateManifest(visualTemplateKey);
|
||||
if (!visualTemplate || !visualManifest) return [];
|
||||
const supportedBusinessTypes = Array.isArray(manifest.supportedIndustryTemplates)
|
||||
? manifest.supportedIndustryTemplates.filter(
|
||||
(value): value is BrandTemplateKey =>
|
||||
typeof value === "string" &&
|
||||
brandTemplateKeys.includes(value) &&
|
||||
Boolean(getBrandTemplate(value)),
|
||||
)
|
||||
: [];
|
||||
if (
|
||||
supportedBusinessTypes.length === 0 ||
|
||||
supportedBusinessTypes.some(
|
||||
(businessType) => !isVisualTemplateCompatible(visualTemplate, businessType),
|
||||
) ||
|
||||
validateTemplatePackageManifest(manifest).length > 0
|
||||
)
|
||||
return [];
|
||||
return [
|
||||
{
|
||||
templatePackageVersionId: version.id,
|
||||
packageKey: version.packageKey,
|
||||
name: version.displayName,
|
||||
description: visualManifest.description,
|
||||
version: version.version,
|
||||
supportedBusinessTypes,
|
||||
},
|
||||
];
|
||||
});
|
||||
const latestByPackage = new Map<string, string>();
|
||||
for (const candidate of candidates) {
|
||||
const latestVersion = latestByPackage.get(candidate.packageKey);
|
||||
if (!latestVersion || compareTemplateVersions(candidate.version, latestVersion) > 0) {
|
||||
latestByPackage.set(candidate.packageKey, candidate.version);
|
||||
}
|
||||
}
|
||||
const pageSchemes = candidates.map(({ packageKey, ...candidate }) => ({
|
||||
...candidate,
|
||||
isLatestForPackage: latestByPackage.get(packageKey) === candidate.version,
|
||||
}));
|
||||
|
||||
return {
|
||||
businesses: brandTemplateKeys.map((key) => {
|
||||
const template = getBrandTemplate(key);
|
||||
if (!template) throw new BadRequestException("业务类型配置不完整");
|
||||
return { key, name: template.name, description: template.description };
|
||||
}),
|
||||
pageSchemes,
|
||||
};
|
||||
}
|
||||
|
||||
async getPageSchemeOptions(brandId: string) {
|
||||
const brand = await this.prisma.brandProfile.findUnique({
|
||||
where: { id: brandId },
|
||||
select: { templateKey: true },
|
||||
});
|
||||
const template = brand ? getBrandTemplate(brand.templateKey) : undefined;
|
||||
if (!brand || !template) throw new BadRequestException("品牌业务类型无效");
|
||||
const catalog = await this.getPageSchemeCatalog();
|
||||
return {
|
||||
business: {
|
||||
key: template.key,
|
||||
name: template.name,
|
||||
description: template.description,
|
||||
},
|
||||
pageSchemes: catalog.pageSchemes.filter((scheme) =>
|
||||
scheme.supportedBusinessTypes.includes(template.key),
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
async getTrustContentTypes(brandId: string): Promise<string[]> {
|
||||
const installation = await this.prisma.brandTemplateInstallation.findUnique({
|
||||
where: { brandId },
|
||||
@@ -124,6 +214,7 @@ export class TemplateWorkspaceService {
|
||||
select: { templateKey: true },
|
||||
}),
|
||||
]);
|
||||
if (!brand) throw new BadRequestException("品牌不存在");
|
||||
// 一个品牌只使用一个行业模板(BrandProfile.templateKey 即身份)。安装只允许补建当前模板的版本台账,
|
||||
// 不得换成别的行业模板,否则会出现「身份是 A、台账是 B」的漂移,并把发布快照接到不适配的视觉模板上。
|
||||
const currentTemplate = brand?.templateKey ? getBrandTemplate(brand.templateKey) : undefined;
|
||||
@@ -147,15 +238,11 @@ export class TemplateWorkspaceService {
|
||||
)
|
||||
throw new BadRequestException("当前视觉模板不适配行业模板");
|
||||
return this.prisma.$transaction(async (tx) => {
|
||||
await tx.brandProfile.update({
|
||||
where: { id: brandId },
|
||||
data: { templateKey },
|
||||
});
|
||||
const installation = await tx.brandTemplateInstallation.create({
|
||||
data: {
|
||||
brandId,
|
||||
templateKey,
|
||||
templateVersion: template.version,
|
||||
templateVersion: packageVersion.version,
|
||||
templatePackageVersionId: packageVersion.id,
|
||||
contentChecksum: packageVersion.contentChecksum,
|
||||
configSnapshot: packageVersion.manifestSnapshot as Prisma.InputJsonValue,
|
||||
@@ -176,7 +263,7 @@ export class TemplateWorkspaceService {
|
||||
return { installation, template, visualTemplate: visualManifest };
|
||||
});
|
||||
}
|
||||
private async resolveInstallablePackageVersion(
|
||||
async resolveInstallablePackageVersion(
|
||||
templateKey: BrandTemplateKey,
|
||||
templatePackageVersionId: string,
|
||||
): Promise<TemplatePackageVersion> {
|
||||
@@ -195,7 +282,7 @@ export class TemplateWorkspaceService {
|
||||
!Array.isArray(manifest.supportedIndustryTemplates) ||
|
||||
!manifest.supportedIndustryTemplates.includes(templateKey)
|
||||
) {
|
||||
throw new BadRequestException("模板包版本与行业或视觉模板不匹配");
|
||||
throw new BadRequestException("页面方案与所选业务类型不兼容,请重新选择");
|
||||
}
|
||||
if (validateTemplatePackageManifest(manifest).length)
|
||||
throw new BadRequestException("模板包版本不符合统一模板契约");
|
||||
@@ -253,11 +340,17 @@ export class TemplateWorkspaceService {
|
||||
if (!target || target.status !== "published")
|
||||
throw new BadRequestException("指定模板包版本不存在或未发布");
|
||||
const manifest = record(target.manifestSnapshot) as unknown as TemplatePackageManifest;
|
||||
const visualTemplate =
|
||||
typeof manifest.visualTemplateKey === "string"
|
||||
? getVisualTemplate(manifest.visualTemplateKey)
|
||||
: undefined;
|
||||
if (
|
||||
target.packageKey !== manifest.packageKey ||
|
||||
target.version !== manifest.version ||
|
||||
manifest.packageKey !== manifest.visualTemplateKey ||
|
||||
!manifest.supportedIndustryTemplates?.includes(brand.templateKey) ||
|
||||
!visualTemplate ||
|
||||
!isVisualTemplateCompatible(visualTemplate, brand.templateKey) ||
|
||||
validateTemplatePackageManifest(manifest).length
|
||||
)
|
||||
throw new BadRequestException("指定模板包版本不符合当前品牌的统一模板契约");
|
||||
@@ -329,15 +422,28 @@ export class TemplateWorkspaceService {
|
||||
).visualTemplateKey;
|
||||
if (typeof visualTemplateKey !== "string")
|
||||
throw new BadRequestException("已安装模板版本缺少 visualTemplateKey 声明");
|
||||
const [currentPackage, targetPackage] = await Promise.all([
|
||||
const [currentPackage, publishedTargets] = await Promise.all([
|
||||
this.prisma.templatePackageVersion.findUnique({
|
||||
where: { id: installation.templatePackageVersionId },
|
||||
}),
|
||||
this.prisma.templatePackageVersion.findFirst({
|
||||
this.prisma.templatePackageVersion.findMany({
|
||||
where: { packageKey: visualTemplateKey, status: "published" },
|
||||
orderBy: { importedAt: "desc" },
|
||||
}),
|
||||
]);
|
||||
const targetPackage = latestTemplateVersion(
|
||||
publishedTargets.filter((candidate) => {
|
||||
const manifest = record(candidate.manifestSnapshot);
|
||||
return (
|
||||
candidate.packageKey === visualTemplateKey &&
|
||||
manifest.packageKey === candidate.packageKey &&
|
||||
manifest.version === candidate.version &&
|
||||
manifest.visualTemplateKey === visualTemplateKey &&
|
||||
Array.isArray(manifest.supportedIndustryTemplates) &&
|
||||
manifest.supportedIndustryTemplates.includes(installation.templateKey) &&
|
||||
validateTemplatePackageManifest(manifest).length === 0
|
||||
);
|
||||
}),
|
||||
);
|
||||
if (!currentPackage) throw new BadRequestException("当前安装引用的模板包版本不存在");
|
||||
if (
|
||||
currentPackage.packageKey !== visualTemplateKey ||
|
||||
@@ -507,7 +613,7 @@ export class TemplateWorkspaceService {
|
||||
})
|
||||
.sort();
|
||||
if (JSON.stringify(expectedConflicts) !== JSON.stringify(preserved))
|
||||
throw new ConflictException("冲突处理与当前预览不一致,请重新预览并逐项确认");
|
||||
throw new ConflictException("冲突处理与当前预览不一致,请重新预览后再升级");
|
||||
const manifest = record(target.manifestSnapshot);
|
||||
if (
|
||||
target.packageKey !==
|
||||
|
||||
Reference in new issue
Block a user