fix: 修复系统一致性与安全问题

This commit is contained in:
que01 committed 2026-10-14 17:36:46 +08:00
1 parent aaeec14733
commit f158f906d5
19 files changed
+194 -34

No files matched your search

@@ -1,4 +1,11 @@
import { BadRequestException, Controller, Get, Param, Query } from "@nestjs/common";
import {
BadRequestException,
Controller,
Get,
NotFoundException,
Param,
Query,
} from "@nestjs/common";
import { PublicBrandContextService } from "./public-brand-context.service.js";
import { BrandReleaseService } from "../../brand-release.service.js";
@@ -34,7 +41,7 @@ export class PublicOfferingController {
const item = (snapshot?.offerings ?? [])
.map((raw) => this.object(raw))
.find((offering) => offering.id === id && offering.isEnabled === true);
if (!item) throw new BadRequestException("业务提供项不存在");
if (!item) throw new NotFoundException("业务提供项不存在");
const forms = (snapshot?.forms ?? []).filter((raw) => {
const form = this.object(raw);
return form.offeringId === id && form.isEnabled === true;
@@ -149,6 +149,35 @@ export function toRuntimeInquiryFields(snapshot: Prisma.JsonValue): RuntimeInqui
? [{ label: item.label, value: item.value }]
: [];
});
const visibleWhen = asArray(value.visibleWhen).flatMap((rule) => {
if (!rule || typeof rule !== "object") return [];
const item = rule as Record<string, unknown>;
if (typeof item.field !== "string") return [];
const operator: "equals" | "not-equals" | "exists" | "in" = item.operator as
"equals" | "not-equals" | "exists" | "in";
if (
operator !== "equals" &&
operator !== "not-equals" &&
operator !== "exists" &&
operator !== "in"
)
return [];
const ruleValue = item.value;
const normalizedValue =
typeof ruleValue === "string" ||
typeof ruleValue === "number" ||
typeof ruleValue === "boolean" ||
(Array.isArray(ruleValue) && ruleValue.every((entry) => typeof entry === "string"))
? ruleValue
: undefined;
return [
{
field: item.field,
operator,
...(normalizedValue === undefined ? {} : { value: normalizedValue }),
},
];
});
return [
{
key: value.key,
@@ -156,6 +185,7 @@ export function toRuntimeInquiryFields(snapshot: Prisma.JsonValue): RuntimeInqui
type,
required: value.required === true,
...(options.length ? { options } : {}),
...(visibleWhen.length ? { visibleWhen } : {}),
},
];
});