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"] });