Skip to content

Commit 0478bd7

Browse files
committed
finished update and create
1 parent 14860ff commit 0478bd7

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

client/src/components/ui/backend/organization_call_backend.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,19 @@ export const createItem = async (
9898
export const updateItem = async (
9999
id: number,
100100
newData: Inventory_Details_Interface,
101-
) => {
102-
// Django usually expects a trailing slash after the ID
101+
): Promise<boolean> => {
103102
const response = await fetch(`${BASE_INVENTORY_URL}${id}/`, {
104-
method: "PATCH",
103+
method: "PATCH", // PATCH is better than PUT for Partial updates
105104
headers: { "Content-Type": "application/json" },
106105
body: JSON.stringify(newData),
107106
});
108-
return await response.json();
107+
108+
if (response.ok) return true;
109+
110+
// If it's not OK, let's see why
111+
const errorText = await response.text();
112+
console.error("Server Error Response:", errorText);
113+
return false;
109114
};
110115

111116
// --- DELETE: Remove an item ---

client/src/pages/organization_add_product.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const Organization_Add_Product = () => {
3535
Partial<Inventory_Details_Interface>
3636
>({
3737
// id is excluded because it will be auto generated by backend
38-
// id: number,
38+
id: mode === "add" ? 0 : parsedData?.id,
3939
name: mode === "add" ? "" : parsedData?.name,
4040
details: mode === "add" ? "" : parsedData?.details,
4141
categories: mode === "add" ? "" : parsedData?.categories,

0 commit comments

Comments
 (0)