fix: 修复多品牌架构回归类型与校验问题
This commit is contained in:
1 parent
4902a564f0
commit
e2409c0848
6 files changed
+16
-15
No files matched your search
@@ -106,15 +106,16 @@ export class CustomerInquirySubmissionController {
|
||||
: [];
|
||||
for (const field of fields) {
|
||||
const key = typeof field.key === "string" ? field.key : "";
|
||||
const label = typeof field.label === "string" ? field.label : key;
|
||||
const value = body.values[key];
|
||||
const textValue = typeof value === "string" || typeof value === "number" ? String(value) : "";
|
||||
const empty = value === undefined || value === null || value === "";
|
||||
if (field.required === true && empty)
|
||||
throw new BadRequestException(`${String(field.label ?? key)}不能为空`);
|
||||
if (field.required === true && empty) throw new BadRequestException(`${label}不能为空`);
|
||||
if (empty) continue;
|
||||
if ((field.type === "phone" || field.type === "tel") && !/^1\d{10}$/.test(String(value)))
|
||||
throw new BadRequestException(`${String(field.label ?? key)}格式不正确`);
|
||||
if ((field.type === "phone" || field.type === "tel") && !/^1\d{10}$/.test(textValue))
|
||||
throw new BadRequestException(`${label}格式不正确`);
|
||||
if (field.type === "number" && !Number.isFinite(Number(value)))
|
||||
throw new BadRequestException(`${String(field.label ?? key)}必须是数字`);
|
||||
throw new BadRequestException(`${label}必须是数字`);
|
||||
}
|
||||
const allowedKeys = new Set(fields.map((field) => String(field.key)));
|
||||
const values = Object.fromEntries(
|
||||
|
||||
Reference in new issue
Block a user