feat: 收口多品牌与模板构建基础
This commit is contained in:
1 parent
0425a1c672
commit
77224ea51f
317 files changed
+11290
-1158
No files matched your search
@@ -15,10 +15,14 @@ import type { FastifyRequest } from "fastify";
|
||||
import { PrismaService } from "../../prisma.service.js";
|
||||
import { readIdentity } from "../../auth.js";
|
||||
import { CreateInquirySubmissionDto } from "../../booking.dto.js";
|
||||
import { BrandReleaseService } from "../../brand-release.service.js";
|
||||
|
||||
@Controller("customer/inquiry-submissions")
|
||||
export class CustomerInquirySubmissionController {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
constructor(
|
||||
private readonly prisma: PrismaService,
|
||||
private readonly releases: BrandReleaseService,
|
||||
) {}
|
||||
private present<T extends { customerSubject: string; adminNote?: string | null }>(submission: T) {
|
||||
const {
|
||||
customerSubject: _customerSubject,
|
||||
@@ -84,16 +88,27 @@ export class CustomerInquirySubmissionController {
|
||||
@Body() body: CreateInquirySubmissionDto,
|
||||
): Promise<unknown> {
|
||||
const identity = this.identity(request);
|
||||
const snapshot = await this.releases.getPublishedSnapshot(identity.brandId);
|
||||
const publishedForm = snapshot && this.releases.publishedForm(snapshot, body.formId);
|
||||
if (!publishedForm) throw new BadRequestException("咨询表单不存在或品牌尚未发布");
|
||||
const form = await this.prisma.inquiryForm.findFirst({
|
||||
where: {
|
||||
id: body.formId,
|
||||
brandId: identity.brandId,
|
||||
isEnabled: true,
|
||||
OR: [{ offeringId: null }, { offering: { isEnabled: true } }],
|
||||
},
|
||||
});
|
||||
if (!form) throw new BadRequestException("咨询表单不存在");
|
||||
const capabilityKey = form.purpose === "quote-request" ? "quote-request" : "inquiry";
|
||||
const offeringId =
|
||||
typeof publishedForm.offeringId === "string" ? publishedForm.offeringId : null;
|
||||
if (offeringId) {
|
||||
const offering = await this.prisma.offering.findFirst({
|
||||
where: { id: offeringId, brandId: identity.brandId, isEnabled: true },
|
||||
select: { id: true },
|
||||
});
|
||||
if (!offering) throw new BadRequestException("当前业务提供项不可用");
|
||||
}
|
||||
const capabilityKey = publishedForm.purpose === "quote-request" ? "quote-request" : "inquiry";
|
||||
const capability = await this.prisma.capabilityInstallation.findUnique({
|
||||
where: {
|
||||
brandId_capabilityKey: { brandId: identity.brandId, capabilityKey },
|
||||
@@ -101,8 +116,8 @@ export class CustomerInquirySubmissionController {
|
||||
});
|
||||
if (capability && capability.status !== "enabled")
|
||||
throw new BadRequestException("当前咨询能力不可用");
|
||||
const fields = Array.isArray(form.fieldsSnapshot)
|
||||
? (form.fieldsSnapshot as Array<Record<string, unknown>>)
|
||||
const fields = Array.isArray(publishedForm.fieldsSnapshot)
|
||||
? (publishedForm.fieldsSnapshot as Array<Record<string, unknown>>)
|
||||
: [];
|
||||
for (const field of fields) {
|
||||
const key = typeof field.key === "string" ? field.key : "";
|
||||
@@ -126,9 +141,9 @@ export class CustomerInquirySubmissionController {
|
||||
brandId: identity.brandId,
|
||||
customerSubject: identity.subject,
|
||||
inquiryFormId: form.id,
|
||||
offeringId: form.offeringId,
|
||||
formVersion: form.version,
|
||||
fieldsSnapshot: form.fieldsSnapshot as Prisma.InputJsonValue,
|
||||
offeringId,
|
||||
formVersion: Number(publishedForm.version),
|
||||
fieldsSnapshot: publishedForm.fieldsSnapshot as Prisma.InputJsonValue,
|
||||
values: values as Prisma.InputJsonValue,
|
||||
activeFields: Object.fromEntries(Object.keys(values).map((key) => [key, true])),
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user