added working item change route
This commit is contained in:
@@ -273,8 +273,13 @@ const ItemTable: React.FC = () => {
|
|||||||
if (response.success) {
|
if (response.success) {
|
||||||
setError(
|
setError(
|
||||||
"success",
|
"success",
|
||||||
"User edited",
|
"Gegenstand erfolgreich bearbeitet!",
|
||||||
"The user has been successfully edited."
|
"Gegenstand " +
|
||||||
|
'"' +
|
||||||
|
item.item_name +
|
||||||
|
'" mit ID ' +
|
||||||
|
item.id +
|
||||||
|
" bearbeitet."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@@ -163,7 +163,18 @@ export const handleEditItems = async (
|
|||||||
can_borrow_role: string
|
can_borrow_role: string
|
||||||
) => {
|
) => {
|
||||||
try {
|
try {
|
||||||
// write the logic for editing an item
|
const response = await fetch("http://localhost:8002/api/updateItemByID", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Authorization: `Bearer ${Cookies.get("token")}`,
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ itemId, item_name, can_borrow_role }),
|
||||||
|
});
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error("Failed to edit item");
|
||||||
|
}
|
||||||
|
return { success: true };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error editing item:", error);
|
console.error("Error editing item:", error);
|
||||||
return { success: false };
|
return { success: false };
|
||||||
|
@@ -309,9 +309,10 @@ router.post("/changePWadmin", authenticate, async (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
router.post("/updateItemByID", authenticate, async (req, res) => {
|
router.post("/updateItemByID", authenticate, async (req, res) => {
|
||||||
const itemId = req.body.id;
|
const role = req.body.can_borrow_role;
|
||||||
const { item_name, can_borrow_role } = req.body || {};
|
const itemId = req.body.itemId;
|
||||||
const result = await updateItemByID(itemId, item_name, can_borrow_role);
|
const item_name = req.body.item_name;
|
||||||
|
const result = await updateItemByID(itemId, item_name, role);
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
return res.status(200).json({ message: "Item updated successfully" });
|
return res.status(200).json({ message: "Item updated successfully" });
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user