fix(R56): 修复费用标准编辑时 expenseTypeId 校验失败
前端编辑提交时携带了只读字段 expenseTypeId,后端 strict schema 拒绝。 剔除只读字段后 PATCH 正常工作。
这个提交包含在:
@@ -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 }),
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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"] });
|
||||||
|
|||||||
在新工单中引用
屏蔽一个用户