fix: 展示模板默认能力来源
This commit is contained in:
1 parent
b3e2ece41b
commit
940dc4d6a3
3 files changed
+33
-4
No files matched your search
@@ -54,6 +54,13 @@ export function CapabilitiesPage() {
|
||||
locale={{ emptyText: "当前还没有品牌级能力覆盖,系统将使用模板默认能力。" }}
|
||||
columns={[
|
||||
{ title: "能力", dataIndex: "capabilityKey" },
|
||||
{
|
||||
title: "来源",
|
||||
dataIndex: "source",
|
||||
render: (value: CapabilityInstallation["source"]) => (
|
||||
<Tag>{value === "brand" ? "品牌覆盖" : "模板默认"}</Tag>
|
||||
),
|
||||
},
|
||||
{ title: "版本", dataIndex: "capabilityVersion" },
|
||||
{
|
||||
title: "状态",
|
||||
|
||||
@@ -27,7 +27,7 @@ import {
|
||||
UpdateInquirySubmissionDto,
|
||||
UpdateCapabilityInstallationDto,
|
||||
} from "./admin.dto.js";
|
||||
import { capabilityPlugins, getBrandTemplate } from "@personal-brand/config";
|
||||
import { capabilityPlugins, getBrandTemplate, resolveCapabilities } from "@personal-brand/config";
|
||||
import { TemplateWorkspaceService } from "./template-workspace.service.js";
|
||||
import { validateFieldSnapshot, validateOfferingConfig } from "@personal-brand/validation";
|
||||
|
||||
@@ -177,7 +177,28 @@ class AdminWorkspaceController {
|
||||
@Get("capabilities")
|
||||
async listCapabilities(@Req() request: FastifyRequest): Promise<unknown> {
|
||||
this.requireAdmin(request);
|
||||
return this.prisma.capabilityInstallation.findMany({ where: { brandId: this.brandId() } });
|
||||
const brandId = this.brandId();
|
||||
const [brand, installations] = await Promise.all([
|
||||
this.prisma.brandProfile.findUnique({
|
||||
where: { id: brandId },
|
||||
select: { templateKey: true },
|
||||
}),
|
||||
this.prisma.capabilityInstallation.findMany({ where: { brandId } }),
|
||||
]);
|
||||
const installed = new Map(installations.map((item) => [item.capabilityKey, item]));
|
||||
const template = getBrandTemplate(brand?.templateKey ?? "personal");
|
||||
return (template ? resolveCapabilities(template.capabilities) : []).map((definition) => {
|
||||
const item = installed.get(definition.key);
|
||||
return {
|
||||
id: item?.id ?? null,
|
||||
capabilityKey: definition.key,
|
||||
capabilityVersion: item?.capabilityVersion ?? definition.version,
|
||||
status: item?.status ?? "enabled",
|
||||
config: item?.config ?? {},
|
||||
source: item ? "brand" : "template",
|
||||
updatedAt: item?.updatedAt ?? null,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
@Patch("capabilities/:key")
|
||||
|
||||
@@ -191,12 +191,13 @@ export interface InquirySubmission {
|
||||
offering?: { id: string; name: string } | null;
|
||||
}
|
||||
export interface CapabilityInstallation {
|
||||
id: string;
|
||||
id: string | null;
|
||||
capabilityKey: string;
|
||||
capabilityVersion: string;
|
||||
status: "enabled" | "disabled" | "degraded";
|
||||
config?: Record<string, unknown> | null;
|
||||
updatedAt: string;
|
||||
updatedAt: string | null;
|
||||
source?: "template" | "brand";
|
||||
}
|
||||
export interface PublicWorkspace {
|
||||
schemaVersion?: string;
|
||||
|
||||
Reference in new issue
Block a user