fix(R56): 修复费用标准编辑时 expenseTypeId 校验失败

前端编辑提交时携带了只读字段 expenseTypeId,后端 strict schema 拒绝。
剔除只读字段后 PATCH 正常工作。
这个提交包含在:
2026-04-08 18:53:39 +08:00
父节点 845558ab17
当前提交 14c2cbd6da
共修改 2 个文件,包含 36 行新增和 6 行删除
+30 -2
查看文件
@@ -46,7 +46,16 @@ export type CreateExpenseStandardPayload = {
note?: string | null; note?: string | null;
}; };
export type UpdateExpenseStandardPayload = Partial<CreateExpenseStandardPayload>; 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<string, string | number | boolean | undefined>) { function toQueryString(query: Record<string, string | number | boolean | undefined>) {
const params = new URLSearchParams(); const params = new URLSearchParams();
@@ -76,9 +85,28 @@ export async function createExpenseStandard(payload: CreateExpenseStandardPayloa
} }
export async function updateExpenseStandard(standardId: string, payload: UpdateExpenseStandardPayload) { export async function updateExpenseStandard(standardId: string, payload: UpdateExpenseStandardPayload) {
const {
name,
maxAmount,
perUnit,
controlMode,
scopeType,
scopeKey,
enabled,
note,
} = payload;
return apiRequestData<ExpenseStandard>(`/api/expense-standards/${standardId}`, { return apiRequestData<ExpenseStandard>(`/api/expense-standards/${standardId}`, {
method: "PATCH", 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 }),
}),
}); });
} }
+6 -4
查看文件
@@ -140,8 +140,7 @@ export function ExpenseStandardsPage() {
const saveMutation = useMutation({ const saveMutation = useMutation({
mutationFn: async () => { mutationFn: async () => {
const payload = { const mutablePayload = {
expenseTypeId: form.expenseTypeId,
name: form.name.trim(), name: form.name.trim(),
maxAmount: form.maxAmount.trim(), maxAmount: form.maxAmount.trim(),
perUnit: form.perUnit, perUnit: form.perUnit,
@@ -153,10 +152,13 @@ export function ExpenseStandardsPage() {
}; };
if (editingItem) { if (editingItem) {
return updateExpenseStandard(editingItem.id, payload); return updateExpenseStandard(editingItem.id, mutablePayload);
} }
return createExpenseStandard(payload); return createExpenseStandard({
expenseTypeId: form.expenseTypeId,
...mutablePayload,
});
}, },
onSuccess: async () => { onSuccess: async () => {
await queryClient.invalidateQueries({ queryKey: ["expense-standards"] }); await queryClient.invalidateQueries({ queryKey: ["expense-standards"] });