fix: 完善模板可视化编辑闭环与通用验收
This commit is contained in:
1 parent
fa6b492bce
commit
22a82dbfba
39 files changed
+7773
-443
No files matched your search
@@ -199,7 +199,7 @@ class AdminWorkspaceController {
|
||||
@Get("preview")
|
||||
async getPreviewWorkspace(@Req() request: FastifyRequest): Promise<unknown> {
|
||||
const { brandId } = this.requireAdmin(request);
|
||||
return this.publicWorkspace.getForBrandId(brandId);
|
||||
return this.publicWorkspace.getForBrandId(brandId, true);
|
||||
}
|
||||
private jsonObject(value: unknown): Record<string, unknown> {
|
||||
return value && typeof value === "object" && !Array.isArray(value)
|
||||
|
||||
@@ -18,6 +18,7 @@ import type {
|
||||
RuntimeTrustItem,
|
||||
RuntimeWorkspace,
|
||||
} from "@personal-brand/types";
|
||||
import { buildBrandReleaseSnapshot } from "../../brand-release.service.js";
|
||||
import {
|
||||
projectBrandAliases,
|
||||
projectOfferingDetails,
|
||||
@@ -30,14 +31,16 @@ import {
|
||||
export class PublicWorkspaceService {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
async getForBrandId(brandId: string): Promise<unknown> {
|
||||
async getForBrandId(brandId: string, draft = false): Promise<unknown> {
|
||||
const release = await this.prisma.brandRelease.findFirst({
|
||||
where: { brandId, status: "published" },
|
||||
orderBy: { version: "desc" },
|
||||
select: { version: true, createdAt: true, snapshot: true },
|
||||
});
|
||||
const releaseSnapshot = this.jsonObject(release?.snapshot) as unknown as BrandReleaseSnapshot;
|
||||
if (!release) {
|
||||
const draftSnapshot = draft ? await buildBrandReleaseSnapshot(this.prisma, brandId) : null;
|
||||
const sourceSnapshot = draftSnapshot ?? release?.snapshot;
|
||||
const releaseSnapshot = this.jsonObject(sourceSnapshot) as unknown as BrandReleaseSnapshot;
|
||||
if (!release && !draftSnapshot) {
|
||||
return {
|
||||
contractVersion: "1.0",
|
||||
schemaVersion: "1.0.0",
|
||||
@@ -258,9 +261,9 @@ export class PublicWorkspaceService {
|
||||
const runtimeWorkspace: RuntimeWorkspace = {
|
||||
schemaVersion: "1.0.0",
|
||||
publication: {
|
||||
status: "published",
|
||||
version: release.version,
|
||||
publishedAt: release.createdAt.toISOString(),
|
||||
status: draftSnapshot ? "draft" : "published",
|
||||
version: draftSnapshot ? null : (release?.version ?? null),
|
||||
...(!draftSnapshot && release ? { publishedAt: release.createdAt.toISOString() } : {}),
|
||||
},
|
||||
brand: runtimeBrand,
|
||||
templateData,
|
||||
|
||||
Reference in new issue
Block a user