feat: 收口多品牌与模板构建基础

This commit is contained in:
que01 committed 2026-09-25 02:55:46 +08:00
1 parent 0425a1c672
commit 77224ea51f
317 files changed
+11290 -1158

No files matched your search

@@ -1,51 +1,52 @@
import { BadRequestException, Controller, Get, Param, Query } from "@nestjs/common";
import { Prisma } from "@prisma/client";
import { PrismaService } from "../../prisma.service.js";
import { PublicBrandContextService } from "./public-brand-context.service.js";
import { BrandReleaseService } from "../../brand-release.service.js";
@Controller("public/offerings")
export class PublicOfferingController {
constructor(
private readonly prisma: PrismaService,
private readonly releases: BrandReleaseService,
private readonly brandContext: PublicBrandContextService,
) {}
@Get()
async list(@Query("brandSlug") brandSlug?: string): Promise<unknown> {
const brandId = await this.brandContext.resolveId(brandSlug);
const items = await this.prisma.offering.findMany({
where: { brandId, isEnabled: true },
orderBy: { sortOrder: "asc" },
include: {
inquiryForms: {
where: { isEnabled: true },
orderBy: { updatedAt: "desc" },
select: { id: true, name: true, purpose: true, targetType: true, version: true },
},
},
});
return items.map((item) => this.present(item));
const snapshot = await this.releases.getPublishedSnapshot(brandId);
const forms = snapshot?.forms ?? [];
return (snapshot?.offerings ?? [])
.filter((raw) => this.object(raw).isEnabled === true)
.map((raw) => this.object(raw))
.sort((a, b) => Number(a.sortOrder ?? 0) - Number(b.sortOrder ?? 0))
.map((item) =>
this.present({
...item,
inquiryForms: forms.filter((raw) => {
const form = this.object(raw);
return form.offeringId === item.id && form.isEnabled === true;
}),
}),
);
}
@Get(":id")
async get(@Param("id") id: string, @Query("brandSlug") brandSlug?: string): Promise<unknown> {
const brandId = await this.brandContext.resolveId(brandSlug);
const item = await this.prisma.offering.findFirst({
where: {
id,
brandId,
isEnabled: true,
},
include: {
inquiryForms: {
where: { isEnabled: true },
orderBy: { updatedAt: "desc" },
select: { id: true, name: true, purpose: true, targetType: true, version: true },
},
},
});
const snapshot = await this.releases.getPublishedSnapshot(brandId);
const item = (snapshot?.offerings ?? [])
.map((raw) => this.object(raw))
.find((offering) => offering.id === id && offering.isEnabled === true);
if (!item) throw new BadRequestException("业务提供项不存在");
return this.present(item);
const forms = (snapshot?.forms ?? []).filter((raw) => {
const form = this.object(raw);
return form.offeringId === id && form.isEnabled === true;
});
return this.present({ ...item, inquiryForms: forms });
}
private present(item: { config: Prisma.JsonValue; [key: string]: unknown }): unknown {
private object(value: unknown): Record<string, unknown> {
return value && typeof value === "object" && !Array.isArray(value)
? (value as Record<string, unknown>)
: {};
}
private present(item: { config?: unknown; [key: string]: unknown }): unknown {
const config = (item.config ?? {}) as Record<string, unknown>;
return {
...item,