refactor: 拆分公开内容控制器
This commit is contained in:
1 parent
464c706021
commit
41ab3b6d23
3 files changed
+99
-81
No files matched your search
+5
-81
@@ -48,6 +48,11 @@ import {
|
||||
import { AdminBookingController } from "./modules/admin/admin-booking.controller.js";
|
||||
import { CustomerBookingController } from "./modules/customer/customer-booking.controller.js";
|
||||
import { TenantController } from "./modules/tenant/tenant.controller.js";
|
||||
import {
|
||||
PublicController,
|
||||
PublicTemplateController,
|
||||
PublicTrustContentController,
|
||||
} from "./modules/public/public.controller.js";
|
||||
import type {
|
||||
RuntimeInquiryField,
|
||||
RuntimeOffering,
|
||||
@@ -63,87 +68,6 @@ export class HealthController {
|
||||
}
|
||||
}
|
||||
|
||||
@Controller("public")
|
||||
export class PublicController {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
@Get("brand")
|
||||
async brand(): Promise<unknown> {
|
||||
return this.prisma.brandProfile.findUnique({
|
||||
where: {
|
||||
id: process.env.DEFAULT_BRAND_ID ?? "00000000-0000-0000-0000-000000000001",
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
templateKey: true,
|
||||
tagline: true,
|
||||
description: true,
|
||||
avatarUrl: true,
|
||||
coverUrl: true,
|
||||
hours: true,
|
||||
address: true,
|
||||
deliveryNote: true,
|
||||
contactPhone: true,
|
||||
contactWechat: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Controller("public/trust-content")
|
||||
export class PublicTrustContentController {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
@Get()
|
||||
list(): Promise<unknown> {
|
||||
return this.prisma.trustContent.findMany({
|
||||
where: {
|
||||
brandId: process.env.DEFAULT_BRAND_ID ?? "00000000-0000-0000-0000-000000000001",
|
||||
isPublished: true,
|
||||
},
|
||||
orderBy: [{ type: "asc" }, { sortOrder: "asc" }],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Controller("public/templates")
|
||||
export class PublicTemplateController {
|
||||
@Get()
|
||||
list(): unknown {
|
||||
return { industries: Object.values(brandTemplates), visuals: Object.values(visualTemplates) };
|
||||
}
|
||||
@Get("preview")
|
||||
preview(
|
||||
@Query("industry") industry = "personal",
|
||||
@Query("visual") visual = "linjing-editorial",
|
||||
): unknown {
|
||||
const industryTemplate = getBrandTemplate(industry);
|
||||
const visualTemplate = getVisualTemplate(visual) ?? getVisualTemplate("linjing-editorial");
|
||||
if (!industryTemplate || !visualTemplate) throw new BadRequestException("模板组合不存在");
|
||||
return {
|
||||
industry: industryTemplate,
|
||||
visual: visualTemplate,
|
||||
runtime: {
|
||||
schemaVersion: "1.0.0",
|
||||
modules: industryTemplate.modules.map((module) => ({
|
||||
key: module.key,
|
||||
type: module.type,
|
||||
title: module.title,
|
||||
variant: visualTemplate.variants[module.type] ?? "default",
|
||||
})),
|
||||
capabilities: resolveCapabilities(industryTemplate.capabilities),
|
||||
theme: visualTemplate.theme,
|
||||
},
|
||||
};
|
||||
}
|
||||
@Get(":key")
|
||||
get(@Param("key") key: string): unknown {
|
||||
const template = getBrandTemplate(key);
|
||||
if (!template) throw new BadRequestException("行业模板不存在");
|
||||
return template;
|
||||
}
|
||||
}
|
||||
|
||||
@Controller("public/workspace")
|
||||
export class PublicWorkspaceController {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
import { BadRequestException, Controller, Get, Param, Query } from "@nestjs/common";
|
||||
import { PrismaService } from "../../prisma.service.js";
|
||||
import {
|
||||
brandTemplates,
|
||||
getBrandTemplate,
|
||||
getVisualTemplate,
|
||||
resolveCapabilities,
|
||||
visualTemplates,
|
||||
} from "@personal-brand/config";
|
||||
|
||||
@Controller("public")
|
||||
export class PublicController {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
@Get("brand")
|
||||
async brand(): Promise<unknown> {
|
||||
return this.prisma.brandProfile.findUnique({
|
||||
where: {
|
||||
id: process.env.DEFAULT_BRAND_ID ?? "00000000-0000-0000-0000-000000000001",
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
templateKey: true,
|
||||
tagline: true,
|
||||
description: true,
|
||||
avatarUrl: true,
|
||||
coverUrl: true,
|
||||
hours: true,
|
||||
address: true,
|
||||
deliveryNote: true,
|
||||
contactPhone: true,
|
||||
contactWechat: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Controller("public/trust-content")
|
||||
export class PublicTrustContentController {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
@Get()
|
||||
list(): Promise<unknown> {
|
||||
return this.prisma.trustContent.findMany({
|
||||
where: {
|
||||
brandId: process.env.DEFAULT_BRAND_ID ?? "00000000-0000-0000-0000-000000000001",
|
||||
isPublished: true,
|
||||
},
|
||||
orderBy: [{ type: "asc" }, { sortOrder: "asc" }],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Controller("public/templates")
|
||||
export class PublicTemplateController {
|
||||
@Get()
|
||||
list(): unknown {
|
||||
return { industries: Object.values(brandTemplates), visuals: Object.values(visualTemplates) };
|
||||
}
|
||||
|
||||
@Get("preview")
|
||||
preview(
|
||||
@Query("industry") industry = "personal",
|
||||
@Query("visual") visual = "linjing-editorial",
|
||||
): unknown {
|
||||
const industryTemplate = getBrandTemplate(industry);
|
||||
const visualTemplate = getVisualTemplate(visual) ?? getVisualTemplate("linjing-editorial");
|
||||
if (!industryTemplate || !visualTemplate) throw new BadRequestException("模板组合不存在");
|
||||
return {
|
||||
industry: industryTemplate,
|
||||
visual: visualTemplate,
|
||||
runtime: {
|
||||
schemaVersion: "1.0.0",
|
||||
modules: industryTemplate.modules.map((module) => ({
|
||||
key: module.key,
|
||||
type: module.type,
|
||||
title: module.title,
|
||||
variant: visualTemplate.variants[module.type] ?? "default",
|
||||
})),
|
||||
capabilities: resolveCapabilities(industryTemplate.capabilities),
|
||||
theme: visualTemplate.theme,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@Get(":key")
|
||||
get(@Param("key") key: string): unknown {
|
||||
const template = getBrandTemplate(key);
|
||||
if (!template) throw new BadRequestException("行业模板不存在");
|
||||
return template;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user