From 14c2cbd6daed8bda148c6802203726ad0dd35af7 Mon Sep 17 00:00:00 2001 From: shunli Date: Wed, 8 Apr 2026 18:53:39 +0800 Subject: [PATCH] =?UTF-8?q?fix(R56):=20=E4=BF=AE=E5=A4=8D=E8=B4=B9?= =?UTF-8?q?=E7=94=A8=E6=A0=87=E5=87=86=E7=BC=96=E8=BE=91=E6=97=B6=20expens?= =?UTF-8?q?eTypeId=20=E6=A0=A1=E9=AA=8C=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 前端编辑提交时携带了只读字段 expenseTypeId,后端 strict schema 拒绝。 剔除只读字段后 PATCH 正常工作。 --- client/src/api/expenseStandards.ts | 32 +++++++++++++++++++++-- client/src/pages/ExpenseStandardsPage.tsx | 10 ++++--- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/client/src/api/expenseStandards.ts b/client/src/api/expenseStandards.ts index 8a4917e5..ea7d7ec3 100644 --- a/client/src/api/expenseStandards.ts +++ b/client/src/api/expenseStandards.ts @@ -46,7 +46,16 @@ export type CreateExpenseStandardPayload = { note?: string | null; }; -export type UpdateExpenseStandardPayload = Partial; +export type UpdateExpenseStandardPayload = { + name?: string; + maxAmount?: string; + perUnit?: ExpenseStandardPerUnit; + controlMode?: ExpenseStandardControlMode; + scopeType?: ExpenseStandardScopeType; + scopeKey?: string | null; + enabled?: boolean; + note?: string | null; +}; function toQueryString(query: Record) { const params = new URLSearchParams(); @@ -76,9 +85,28 @@ export async function createExpenseStandard(payload: CreateExpenseStandardPayloa } export async function updateExpenseStandard(standardId: string, payload: UpdateExpenseStandardPayload) { + const { + name, + maxAmount, + perUnit, + controlMode, + scopeType, + scopeKey, + enabled, + note, + } = payload; return apiRequestData(`/api/expense-standards/${standardId}`, { method: "PATCH", - body: JSON.stringify(payload), + body: JSON.stringify({ + ...(name === undefined ? {} : { name }), + ...(maxAmount === undefined ? {} : { maxAmount }), + ...(perUnit === undefined ? {} : { perUnit }), + ...(controlMode === undefined ? {} : { controlMode }), + ...(scopeType === undefined ? {} : { scopeType }), + ...(scopeKey === undefined ? {} : { scopeKey }), + ...(enabled === undefined ? {} : { enabled }), + ...(note === undefined ? {} : { note }), + }), }); } diff --git a/client/src/pages/ExpenseStandardsPage.tsx b/client/src/pages/ExpenseStandardsPage.tsx index ad4b70bf..f15a3004 100644 --- a/client/src/pages/ExpenseStandardsPage.tsx +++ b/client/src/pages/ExpenseStandardsPage.tsx @@ -140,8 +140,7 @@ export function ExpenseStandardsPage() { const saveMutation = useMutation({ mutationFn: async () => { - const payload = { - expenseTypeId: form.expenseTypeId, + const mutablePayload = { name: form.name.trim(), maxAmount: form.maxAmount.trim(), perUnit: form.perUnit, @@ -153,10 +152,13 @@ export function ExpenseStandardsPage() { }; if (editingItem) { - return updateExpenseStandard(editingItem.id, payload); + return updateExpenseStandard(editingItem.id, mutablePayload); } - return createExpenseStandard(payload); + return createExpenseStandard({ + expenseTypeId: form.expenseTypeId, + ...mutablePayload, + }); }, onSuccess: async () => { await queryClient.invalidateQueries({ queryKey: ["expense-standards"] });