fix: 收敛模板编辑发布契约并还原餐饮页面视觉
This commit is contained in:
1 parent
20bcb43534
commit
f4061a24bd
102 files changed
+4510
-870
No files matched your search
@@ -183,6 +183,11 @@ class AdminWorkspaceController {
|
||||
? {
|
||||
displayName: manifest.displayName,
|
||||
admin: manifest.admin,
|
||||
navigation: manifest.navigation.map(({ key, label, page }) => ({ key, label, page })),
|
||||
templateFields: (manifest.templateFields ?? []).map((field) => ({
|
||||
...field,
|
||||
binding: field.binding ?? `brand.config.templateData.${field.key}`,
|
||||
})),
|
||||
assetSlots: manifest.assetSlots,
|
||||
trustContentTypes: manifest.trustContentTypes ?? [],
|
||||
}
|
||||
@@ -244,7 +249,10 @@ class AdminWorkspaceController {
|
||||
offerings: sample.offerings.length,
|
||||
trustContent: sample.trustContent.length,
|
||||
fields: sample.fields.length,
|
||||
inquiryForms: 1,
|
||||
},
|
||||
willCreateInquiryForm:
|
||||
(await this.prisma.inquiryForm.count({ where: { brandId, isEnabled: true } })) === 0,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -255,6 +263,8 @@ class AdminWorkspaceController {
|
||||
const templateKey = await this.templateWorkspace.getEffectiveTemplateKey(brandId);
|
||||
const sample = getTemplateSampleContent(templateKey);
|
||||
if (!sample) throw new BadRequestException("模板示例内容不存在");
|
||||
const fieldIssues = validateFieldSnapshot(sample.fields);
|
||||
if (fieldIssues.length) throw new BadRequestException("模板咨询表单示例字段无效");
|
||||
const existing = await this.prisma.brandFieldDefinition.count({
|
||||
where: { brandId, source: "sample" },
|
||||
});
|
||||
@@ -280,6 +290,7 @@ class AdminWorkspaceController {
|
||||
type: item.type,
|
||||
title: item.title,
|
||||
content: item.content,
|
||||
...(item.config ? { config: item.config as Prisma.InputJsonValue } : {}),
|
||||
sortOrder,
|
||||
isPublished: false,
|
||||
})),
|
||||
@@ -296,6 +307,20 @@ class AdminWorkspaceController {
|
||||
required: item.required,
|
||||
})),
|
||||
});
|
||||
const hasEnabledForm = await tx.inquiryForm.count({ where: { brandId, isEnabled: true } });
|
||||
const inquiryForm = hasEnabledForm
|
||||
? null
|
||||
: await tx.inquiryForm.create({
|
||||
data: {
|
||||
brandId,
|
||||
name: sample.inquiryFormName,
|
||||
purpose: "inquiry",
|
||||
targetType: "brand",
|
||||
submissionAction: "create-inquiry",
|
||||
fieldsSnapshot: sample.fields,
|
||||
isEnabled: true,
|
||||
},
|
||||
});
|
||||
await tx.capabilityAuditLog.create({
|
||||
data: {
|
||||
brandId,
|
||||
@@ -303,10 +328,20 @@ class AdminWorkspaceController {
|
||||
actorId: identity.subject,
|
||||
action: "sample_content_imported",
|
||||
toStatus: "enabled",
|
||||
config: { offerings: offerings.count, trustContent: trust.count, fields: fields.count },
|
||||
config: {
|
||||
offerings: offerings.count,
|
||||
trustContent: trust.count,
|
||||
fields: fields.count,
|
||||
inquiryForms: inquiryForm ? 1 : 0,
|
||||
},
|
||||
},
|
||||
});
|
||||
return { offerings: offerings.count, trustContent: trust.count, fields: fields.count };
|
||||
return {
|
||||
offerings: offerings.count,
|
||||
trustContent: trust.count,
|
||||
fields: fields.count,
|
||||
inquiryForms: inquiryForm ? 1 : 0,
|
||||
};
|
||||
});
|
||||
return { imported: true, counts: result };
|
||||
}
|
||||
|
||||
@@ -56,28 +56,25 @@ export class ChangeAdminPasswordDto {
|
||||
}
|
||||
|
||||
export class CreateTrustContentDto {
|
||||
@IsIn(["schedule", "coverage", "process", "credential", "case", "promise"])
|
||||
type!: string;
|
||||
@IsString() type!: string;
|
||||
@IsString() title!: string;
|
||||
@IsOptional() @IsString() summary?: string;
|
||||
@IsString() content!: string;
|
||||
@IsOptional() @IsString() coverUrl?: string;
|
||||
@IsOptional() @IsInt() @Min(0) @Max(9999) sortOrder?: number;
|
||||
@IsOptional() @IsBoolean() isPublished?: boolean;
|
||||
@IsOptional() config?: Record<string, unknown>;
|
||||
@IsOptional() @IsObject() config?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export class UpdateTrustContentDto {
|
||||
@IsOptional()
|
||||
@IsIn(["schedule", "coverage", "process", "credential", "case", "promise"])
|
||||
type?: string;
|
||||
@IsOptional() @IsString() type?: string;
|
||||
@IsOptional() @IsString() title?: string;
|
||||
@IsOptional() @IsString() summary?: string;
|
||||
@IsOptional() @IsString() content?: string;
|
||||
@IsOptional() @IsString() coverUrl?: string;
|
||||
@IsOptional() @IsInt() @Min(0) @Max(9999) sortOrder?: number;
|
||||
@IsOptional() @IsBoolean() isPublished?: boolean;
|
||||
@IsOptional() config?: Record<string, unknown>;
|
||||
@IsOptional() @IsObject() config?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export class UpdateBookingStatusDto {
|
||||
@@ -125,7 +122,7 @@ export class CreateOfferingDto {
|
||||
@IsOptional() @IsInt() @Min(0) priceAmount?: number;
|
||||
@IsOptional() @IsInt() @Min(0) @Max(9999) sortOrder?: number;
|
||||
@IsOptional() @IsBoolean() isEnabled?: boolean;
|
||||
@IsOptional() config?: Record<string, unknown>;
|
||||
@IsOptional() @IsObject() config?: Record<string, unknown>;
|
||||
@IsOptional() sections?: Array<{
|
||||
type: string;
|
||||
title: string;
|
||||
@@ -146,7 +143,7 @@ export class UpdateOfferingDto {
|
||||
@IsOptional() @IsInt() @Min(0) priceAmount?: number;
|
||||
@IsOptional() @IsInt() @Min(0) @Max(9999) sortOrder?: number;
|
||||
@IsOptional() @IsBoolean() isEnabled?: boolean;
|
||||
@IsOptional() config?: Record<string, unknown>;
|
||||
@IsOptional() @IsObject() config?: Record<string, unknown>;
|
||||
@IsOptional() sections?: Array<{
|
||||
type: string;
|
||||
title: string;
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
getDefaultVisualTemplateKey,
|
||||
getTemplatePackageManifestForVisualKey,
|
||||
} from "@personal-brand/config";
|
||||
import { isTrustContentComplete } from "@personal-brand/types";
|
||||
import { PrismaService } from "./prisma.service.js";
|
||||
import { BrandReleaseService } from "./brand-release.service.js";
|
||||
import { validateFieldSnapshot } from "@personal-brand/validation";
|
||||
@@ -80,11 +81,14 @@ export class BrandReleaseApiService {
|
||||
}),
|
||||
database.trustContent.findMany({
|
||||
where: { brandId, isPublished: true },
|
||||
select: { type: true, title: true, content: true },
|
||||
select: { type: true, title: true, content: true, config: true },
|
||||
}),
|
||||
]);
|
||||
const validTrustItems = trustItems.filter(
|
||||
(item) => item.title.trim().length > 0 && item.content.trim().length > 0,
|
||||
const validTrustItems = trustItems.filter((item) =>
|
||||
isTrustContentComplete(
|
||||
item,
|
||||
packageManifest?.trustContentTypes?.find((type) => type.type === item.type),
|
||||
),
|
||||
);
|
||||
const offeringIds = new Set(offerings.map((item) => item.id));
|
||||
const usableForms = forms.filter(
|
||||
@@ -145,8 +149,19 @@ export class BrandReleaseApiService {
|
||||
checks.push({
|
||||
key: `trust:${type.type}`,
|
||||
label: `请完善${type.label}`,
|
||||
passed: publishedTrustTypes.has(type.type),
|
||||
help: ["标题和详细内容都填写后才能发布。", type.help].filter(Boolean).join(" "),
|
||||
passed:
|
||||
publishedTrustTypes.has(type.type) &&
|
||||
(type.maxPublishedItems === undefined ||
|
||||
trustItems.filter((item) => item.type === type.type).length <= type.maxPublishedItems),
|
||||
help: [
|
||||
"请完整填写该区块的可编辑字段。",
|
||||
type.maxPublishedItems === undefined
|
||||
? undefined
|
||||
: `此区块最多保留 ${type.maxPublishedItems} 条公开记录。`,
|
||||
type.help,
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(" "),
|
||||
destination: "/admin/trust",
|
||||
});
|
||||
}
|
||||
|
||||
@@ -80,7 +80,15 @@ export class AdminConfigController {
|
||||
current?.config && typeof current.config === "object" && !Array.isArray(current.config)
|
||||
? (current.config as Record<string, unknown>)
|
||||
: {};
|
||||
const nextConfig = config ? { ...currentConfig, ...config } : undefined;
|
||||
const nextConfig = {
|
||||
...currentConfig,
|
||||
...(config ?? {}),
|
||||
// 兼容旧模板:品牌简介的唯一编辑入口是 BrandProfile.description,
|
||||
// 旧视觉模板仍从 config.slogan 读取,保存时保持两者同步。
|
||||
...(fields.description !== undefined && config?.slogan === undefined
|
||||
? { slogan: fields.description }
|
||||
: {}),
|
||||
};
|
||||
if (config?.visualTemplateKey && config.visualTemplateKey !== currentConfig.visualTemplateKey) {
|
||||
const templateKey = await this.templateWorkspace.getEffectiveTemplateKey(
|
||||
this.brandId(request),
|
||||
@@ -121,7 +129,7 @@ export class AdminConfigController {
|
||||
where: { id: this.brandId(request) },
|
||||
data: {
|
||||
...fields,
|
||||
...(nextConfig ? { config: nextConfig as Prisma.InputJsonValue } : {}),
|
||||
...(Object.keys(nextConfig).length ? { config: nextConfig } : {}),
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -300,34 +308,17 @@ export class AdminConfigController {
|
||||
@Body() body: CreateTrustContentDto,
|
||||
): Promise<unknown> {
|
||||
this.requireAdmin(request);
|
||||
const { config, ...fields } = body;
|
||||
return this.prisma.trustContent.create({
|
||||
data: {
|
||||
...fields,
|
||||
brandId: this.brandId(request),
|
||||
...(config === undefined ? {} : { config: config as Prisma.InputJsonValue }),
|
||||
},
|
||||
});
|
||||
const brandId = this.brandId(request);
|
||||
return this.templateWorkspace.createTrustContent(brandId, body);
|
||||
}
|
||||
@Patch("trust-content/:id")
|
||||
async updateTrustContent(
|
||||
updateTrustContent(
|
||||
@Req() request: FastifyRequest,
|
||||
@Param("id") id: string,
|
||||
@Body() body: UpdateTrustContentDto,
|
||||
): Promise<unknown> {
|
||||
this.requireAdmin(request);
|
||||
const item = await this.prisma.trustContent.findFirst({
|
||||
where: { id, brandId: this.brandId(request) },
|
||||
});
|
||||
if (!item) throw new BadRequestException("信任内容不存在");
|
||||
const { config, ...fields } = body;
|
||||
return this.prisma.trustContent.update({
|
||||
where: { id },
|
||||
data: {
|
||||
...fields,
|
||||
...(config === undefined ? {} : { config: config as Prisma.InputJsonValue }),
|
||||
},
|
||||
});
|
||||
return this.templateWorkspace.updateTrustContent(this.brandId(request), id, body);
|
||||
}
|
||||
@Delete("trust-content/:id")
|
||||
async deleteTrustContent(
|
||||
|
||||
@@ -18,6 +18,13 @@ import type {
|
||||
RuntimeTrustItem,
|
||||
RuntimeWorkspace,
|
||||
} from "@personal-brand/types";
|
||||
import {
|
||||
projectBrandAliases,
|
||||
projectOfferingDetails,
|
||||
projectTemplateData,
|
||||
projectTrustItem,
|
||||
projectTrustPresentation,
|
||||
} from "@personal-brand/types";
|
||||
|
||||
@Controller("public/workspace")
|
||||
export class PublicWorkspaceController {
|
||||
@@ -113,15 +120,19 @@ export class PublicWorkspaceController {
|
||||
const templatePackageManifest =
|
||||
releaseSnapshot.templatePackageManifest ??
|
||||
getTemplatePackageManifestForVisualKey(visualTemplateKey);
|
||||
const runtimeBrand = {
|
||||
...brandData,
|
||||
...brandConfig,
|
||||
};
|
||||
// 标准 BrandProfile 字段优先,兼容旧模板仍使用的 config 字段。
|
||||
// 这样后台编辑 description/contactPhone 等标准字段后,旧模板也会立即读取新值。
|
||||
const runtimeBrand = projectBrandAliases(brandData, brandConfig);
|
||||
const declaredTemplateFields = templatePackageManifest?.templateFields ?? [];
|
||||
const templateData = projectTemplateData(
|
||||
brandConfig,
|
||||
declaredTemplateFields.map((field) => field.key),
|
||||
);
|
||||
const runtimeOfferings: RuntimeOffering[] = offeringsData.map((raw) => {
|
||||
const item = raw;
|
||||
const config = this.jsonObject(item.config);
|
||||
const sections = Array.isArray(config.sections) ? config.sections : [];
|
||||
const details = this.jsonObject(config.details);
|
||||
const details = projectOfferingDetails(config);
|
||||
const media = Array.isArray(config.media)
|
||||
? config.media.flatMap((entry) => {
|
||||
const value = this.jsonObject(entry);
|
||||
@@ -139,14 +150,6 @@ export class PublicWorkspaceController {
|
||||
: [];
|
||||
})
|
||||
: [];
|
||||
const materialsList = Array.isArray(details.materialsList)
|
||||
? details.materialsList.flatMap((entry) => {
|
||||
const value = this.jsonObject(entry);
|
||||
return typeof value.name === "string" && typeof value.spec === "string"
|
||||
? [{ name: value.name, spec: value.spec }]
|
||||
: [];
|
||||
})
|
||||
: [];
|
||||
return {
|
||||
id: this.string(item.id),
|
||||
name: this.string(item.name),
|
||||
@@ -187,12 +190,10 @@ export class PublicWorkspaceController {
|
||||
: [],
|
||||
media,
|
||||
details: {
|
||||
background: typeof details.background === "string" ? details.background : "",
|
||||
designConcept: typeof details.designConcept === "string" ? details.designConcept : "",
|
||||
crafts: Array.isArray(details.crafts)
|
||||
? details.crafts.filter((craft): craft is string => typeof craft === "string")
|
||||
: [],
|
||||
materialsList,
|
||||
background: details.background,
|
||||
designConcept: details.designConcept,
|
||||
crafts: details.crafts,
|
||||
materialsList: details.materialsList,
|
||||
},
|
||||
},
|
||||
sections: sections
|
||||
@@ -211,18 +212,25 @@ export class PublicWorkspaceController {
|
||||
if (!field || typeof field !== "object") return [];
|
||||
const value = field as Record<string, unknown>;
|
||||
if (typeof value.key !== "string" || typeof value.label !== "string") return [];
|
||||
const type = [
|
||||
"text",
|
||||
"tel",
|
||||
"number",
|
||||
"select",
|
||||
"radio",
|
||||
"checkbox",
|
||||
"textarea",
|
||||
"date",
|
||||
].includes(this.string(value.type))
|
||||
? (value.type as RuntimeInquiryField["type"])
|
||||
: "text";
|
||||
const sourceType = this.string(value.type);
|
||||
const type =
|
||||
sourceType === "phone"
|
||||
? "tel"
|
||||
: sourceType === "multi-select"
|
||||
? "checkbox"
|
||||
: [
|
||||
"text",
|
||||
"tel",
|
||||
"number",
|
||||
"select",
|
||||
"radio",
|
||||
"checkbox",
|
||||
"checkbox",
|
||||
"textarea",
|
||||
"date",
|
||||
].includes(sourceType)
|
||||
? (sourceType as RuntimeInquiryField["type"])
|
||||
: "text";
|
||||
const options = Array.isArray(value.options)
|
||||
? value.options.flatMap((option) => {
|
||||
if (typeof option === "string") return [{ label: option, value: option }];
|
||||
@@ -243,28 +251,14 @@ export class PublicWorkspaceController {
|
||||
},
|
||||
];
|
||||
});
|
||||
const trustPresentation = trustData.reduce<Record<string, unknown>>((result, raw) => {
|
||||
const item = this.jsonObject(raw);
|
||||
const config = this.jsonObject(item.config);
|
||||
for (const [key, value] of Object.entries(config)) {
|
||||
if (!(key in result)) result[key] = value;
|
||||
}
|
||||
if (item.type === "profile" && typeof result.bio !== "string") result.bio = item.content;
|
||||
return result;
|
||||
}, {});
|
||||
const trustDeclarations = templatePackageManifest?.trustContentTypes ?? [];
|
||||
const trustItems: RuntimeTrustItem[] = trustData.flatMap((raw) => {
|
||||
const item = this.jsonObject(raw);
|
||||
if (typeof item.type !== "string" || typeof item.title !== "string") return [];
|
||||
return [
|
||||
{
|
||||
type: item.type,
|
||||
title: item.title,
|
||||
summary: typeof item.summary === "string" ? item.summary : null,
|
||||
content: typeof item.content === "string" ? item.content : "",
|
||||
config: this.jsonObject(item.config),
|
||||
},
|
||||
];
|
||||
const item = projectTrustItem(this.jsonObject(raw));
|
||||
return item && trustDeclarations.some((declaration) => declaration.type === item.type)
|
||||
? [item]
|
||||
: [];
|
||||
});
|
||||
const trustPresentation = projectTrustPresentation(trustItems, trustDeclarations);
|
||||
const runtimeWorkspace: RuntimeWorkspace = {
|
||||
schemaVersion: "1.0.0",
|
||||
publication: {
|
||||
@@ -273,6 +267,7 @@ export class PublicWorkspaceController {
|
||||
publishedAt: release.createdAt.toISOString(),
|
||||
},
|
||||
brand: runtimeBrand,
|
||||
templateData,
|
||||
navigation: {
|
||||
tabs:
|
||||
templatePackageManifest?.navigation.map((tab) => ({
|
||||
|
||||
@@ -5,14 +5,61 @@ import {
|
||||
getVisualTemplate,
|
||||
getVisualTemplateManifest,
|
||||
getDefaultVisualTemplateKey,
|
||||
getTemplatePackageManifestForVisualKey,
|
||||
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()
|
||||
export class TemplateWorkspaceService {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
async getTrustContentTypes(brandId: string): Promise<string[]> {
|
||||
const brand = await this.prisma.brandProfile.findUnique({
|
||||
where: { id: brandId },
|
||||
select: { templateKey: true, config: true },
|
||||
});
|
||||
const config =
|
||||
brand?.config && typeof brand.config === "object" && !Array.isArray(brand.config)
|
||||
? (brand.config as Record<string, unknown>)
|
||||
: {};
|
||||
const visualKey =
|
||||
typeof config.visualTemplateKey === "string"
|
||||
? config.visualTemplateKey
|
||||
: getDefaultVisualTemplateKey(brand?.templateKey ?? "personal");
|
||||
return (
|
||||
getTemplatePackageManifestForVisualKey(visualKey)?.trustContentTypes?.map(
|
||||
(item) => item.type,
|
||||
) ?? []
|
||||
);
|
||||
}
|
||||
async createTrustContent(brandId: string, body: CreateTrustContentDto) {
|
||||
if (!(await this.getTrustContentTypes(brandId)).includes(body.type))
|
||||
throw new BadRequestException("当前模板不支持此信任内容类型");
|
||||
const { config, ...fields } = body;
|
||||
return this.prisma.trustContent.create({
|
||||
data: {
|
||||
...fields,
|
||||
brandId,
|
||||
...(config === undefined ? {} : { config: config as Prisma.InputJsonValue }),
|
||||
},
|
||||
});
|
||||
}
|
||||
async updateTrustContent(brandId: string, id: string, body: UpdateTrustContentDto) {
|
||||
const item = await this.prisma.trustContent.findFirst({ where: { id, brandId } });
|
||||
if (!item) throw new BadRequestException("信任内容不存在");
|
||||
if (body.type !== undefined && !(await this.getTrustContentTypes(brandId)).includes(body.type))
|
||||
throw new BadRequestException("当前模板不支持此信任内容类型");
|
||||
const { config, ...fields } = body;
|
||||
return this.prisma.trustContent.update({
|
||||
where: { id },
|
||||
data: {
|
||||
...fields,
|
||||
...(config === undefined ? {} : { config: config as Prisma.InputJsonValue }),
|
||||
},
|
||||
});
|
||||
}
|
||||
async getEffectiveTemplateKey(brandId: string): Promise<BrandTemplateKey> {
|
||||
const [installation, brand] = await Promise.all([
|
||||
this.prisma.brandTemplateInstallation.findFirst({
|
||||
|
||||
Reference in new issue
Block a user