ok
This commit is contained in:
@@ -4,10 +4,17 @@ import { getItemsByCafeId } from "./cartHelpers.js";
|
||||
export async function getItemTypesWithItems(shopId) {
|
||||
try {
|
||||
const response = await fetch(
|
||||
`${API_BASE_URL}/item/get-cafe-items/` + shopId
|
||||
`${API_BASE_URL}/item/get-cafe-items/` + shopId,
|
||||
{
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${getAuthToken()}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
const data = await response.json();
|
||||
console.log(data);
|
||||
return { response, cafe: data.cafe, data: data.data }; // Return an object with response and data
|
||||
} catch (error) {
|
||||
console.error("Failed to fetch item types with items:", error);
|
||||
@@ -96,13 +103,20 @@ export async function createItem(
|
||||
}
|
||||
}
|
||||
|
||||
export async function updateItem(itemId, name, price, selectedImage) {
|
||||
export async function updateItem(
|
||||
itemId,
|
||||
name,
|
||||
price,
|
||||
selectedImage,
|
||||
isVisible
|
||||
) {
|
||||
try {
|
||||
console.log(selectedImage);
|
||||
const formData = new FormData();
|
||||
formData.append("name", name);
|
||||
formData.append("price", price);
|
||||
formData.append("image", selectedImage);
|
||||
formData.append("isVisible", isVisible);
|
||||
|
||||
const response = await fetch(`${API_BASE_URL}/item/set-item/${itemId}`, {
|
||||
method: "PUT",
|
||||
@@ -178,18 +192,36 @@ export async function createItemType(shopId, name, selectedImage) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export async function updateItemType(shopId, itemTypeId, newName) {
|
||||
export async function updateItemType(
|
||||
shopId,
|
||||
itemTypeId,
|
||||
newName,
|
||||
previewUrl,
|
||||
selectedImage,
|
||||
isVisible
|
||||
) {
|
||||
try {
|
||||
const formData = new FormData();
|
||||
formData.append("name", newName);
|
||||
console.log(selectedImage);
|
||||
console.log(previewUrl);
|
||||
// Check if selectedImage contains API_BASE_URL
|
||||
if (selectedImage == null) {
|
||||
// Remove the API_BASE_URL and any leading slashes
|
||||
previewUrl = previewUrl.replace(API_BASE_URL, "").replace(/^\/+/, "");
|
||||
formData.append("sampleImage", previewUrl);
|
||||
} else formData.append("image", selectedImage);
|
||||
console.log(selectedImage);
|
||||
formData.append("isVisible", isVisible);
|
||||
|
||||
const response = await fetch(
|
||||
`${API_BASE_URL}/item/updateType/` + shopId + "/" + itemTypeId,
|
||||
`${API_BASE_URL}/item/updateType/${shopId}/${itemTypeId}`,
|
||||
{
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${getAuthToken()}`,
|
||||
},
|
||||
body: JSON.stringify({ newName }),
|
||||
body: formData,
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user