fix: 修复多品牌架构回归类型与校验问题

This commit is contained in:
que01 committed 2026-09-23 12:47:09 +08:00
1 parent 4902a564f0
commit e2409c0848
6 files changed
+16 -15

No files matched your search

+1 -1
View File
@@ -237,7 +237,7 @@ class AdminWorkspaceController {
kind: sortOrder === 3 ? "service" : "product", kind: sortOrder === 3 ? "service" : "product",
name: item[0]!, name: item[0]!,
summary: item[1]!, summary: item[1]!,
config: { categoryKey: item[2]! } as Prisma.InputJsonValue, config: { categoryKey: item[2]! },
sortOrder, sortOrder,
isEnabled: true, isEnabled: true,
})), })),
@@ -141,7 +141,7 @@ export class AdminConfigController {
config: { config: {
...config, ...config,
visualTemplateKey: previous.visualTemplateKey, visualTemplateKey: previous.visualTemplateKey,
} as Prisma.InputJsonValue, },
}, },
}), }),
...(installation ...(installation
@@ -106,15 +106,16 @@ export class CustomerInquirySubmissionController {
: []; : [];
for (const field of fields) { for (const field of fields) {
const key = typeof field.key === "string" ? field.key : ""; const key = typeof field.key === "string" ? field.key : "";
const label = typeof field.label === "string" ? field.label : key;
const value = body.values[key]; const value = body.values[key];
const textValue = typeof value === "string" || typeof value === "number" ? String(value) : "";
const empty = value === undefined || value === null || value === ""; const empty = value === undefined || value === null || value === "";
if (field.required === true && empty) if (field.required === true && empty) throw new BadRequestException(`${label}不能为空`);
throw new BadRequestException(`${String(field.label ?? key)}不能为空`);
if (empty) continue; if (empty) continue;
if ((field.type === "phone" || field.type === "tel") && !/^1\d{10}$/.test(String(value))) if ((field.type === "phone" || field.type === "tel") && !/^1\d{10}$/.test(textValue))
throw new BadRequestException(`${String(field.label ?? key)}格式不正确`); throw new BadRequestException(`${label}格式不正确`);
if (field.type === "number" && !Number.isFinite(Number(value))) 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 allowedKeys = new Set(fields.map((field) => String(field.key)));
const values = Object.fromEntries( const values = Object.fromEntries(
@@ -1,4 +1,4 @@
import { BadRequestException, Controller, Get, NotFoundException, Query } from "@nestjs/common"; import { Controller, Get, NotFoundException, Query } from "@nestjs/common";
import { Prisma } from "@prisma/client"; import { Prisma } from "@prisma/client";
import { PrismaService } from "../../prisma.service.js"; import { PrismaService } from "../../prisma.service.js";
import { import {
@@ -173,7 +173,7 @@ export class PublicWorkspaceController {
const inquiryForm = inquiryForms[0] ?? null; const inquiryForm = inquiryForms[0] ?? null;
const runtimeWorkspace: RuntimeWorkspace = { const runtimeWorkspace: RuntimeWorkspace = {
schemaVersion: "1.0.0", schemaVersion: "1.0.0",
brand: (brand ?? {}) as Record<string, unknown>, brand: brand ?? {},
navigation: { navigation: {
tabs: [ tabs: [
{ key: "home", label: "首页", page: "pages/index/index" }, { key: "home", label: "首页", page: "pages/index/index" },
@@ -242,7 +242,7 @@ export class PublicWorkspaceController {
: {}; : {};
} }
private jsonArray(value: unknown): Prisma.JsonValue[] { private jsonArray(value: unknown): Prisma.JsonValue[] {
return Array.isArray(value) ? value : []; return Array.isArray(value) ? (value as Prisma.JsonValue[]) : [];
} }
private moduleType(value: string): RuntimeModule["type"] { private moduleType(value: string): RuntimeModule["type"] {
const known: RuntimeModule["type"][] = [ const known: RuntimeModule["type"][] = [
@@ -1,5 +1,4 @@
import { import {
Body,
Controller, Controller,
ForbiddenException, ForbiddenException,
Get, Get,
+5 -4
View File
@@ -4,10 +4,11 @@ export type ContactPreference = "wechat" | "phone" | "none";
export type FulfillmentType = "pickup" | "delivery"; export type FulfillmentType = "pickup" | "delivery";
export type OrderStatus = BookingStatus; export type OrderStatus = BookingStatus;
export type BrandTemplateKey = "food" | "personal" | "doors"; export type BrandTemplateKey = "food" | "personal" | "doors";
export const BRAND_TEMPLATE = { FOOD: "food", PERSONAL: "personal" } as const satisfies Record< export const BRAND_TEMPLATE = {
Uppercase<BrandTemplateKey>, FOOD: "food",
BrandTemplateKey PERSONAL: "personal",
>; DOORS: "doors",
} as const satisfies Record<Uppercase<BrandTemplateKey>, BrandTemplateKey>;
export const HTTP_STATUS = { export const HTTP_STATUS = {
OK: 200, OK: 200,