ok
This commit is contained in:
@@ -18,7 +18,7 @@ export async function getOwnedCafes(userId) {
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error("Failed to fetch cart details");
|
||||
throw new Error("Failed to fetch cafes");
|
||||
}
|
||||
|
||||
const cafes = await response.json();
|
||||
@@ -30,48 +30,85 @@ export async function getOwnedCafes(userId) {
|
||||
|
||||
export async function createCafe(userId) {
|
||||
try {
|
||||
const response = await fetch(
|
||||
`${API_BASE_URL}/cafe/get-cafe-by-ownerId/` + userId,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${getAuthToken()}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
const response = await fetch(`${API_BASE_URL}/cafe/create-cafe`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${getAuthToken()}`,
|
||||
},
|
||||
body: JSON.stringify({ ownerId: userId }),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error("Failed to fetch cart details");
|
||||
throw new Error("Failed to create cafe");
|
||||
}
|
||||
|
||||
const cafes = await response.json();
|
||||
return cafes;
|
||||
const cafe = await response.json();
|
||||
return cafe;
|
||||
} catch (error) {
|
||||
console.error("Error:", error);
|
||||
}
|
||||
}
|
||||
|
||||
export async function updateCafe(userId) {
|
||||
export async function updateCafe(cafeId, cafeDetails) {
|
||||
try {
|
||||
const response = await fetch(
|
||||
`${API_BASE_URL}/cafe/get-cafe-by-ownerId/` + userId,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${getAuthToken()}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
const response = await fetch(`${API_BASE_URL}/cafe/update-cafe/${cafeId}`, {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${getAuthToken()}`,
|
||||
},
|
||||
body: JSON.stringify(cafeDetails),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error("Failed to fetch cart details");
|
||||
throw new Error("Failed to update cafe");
|
||||
}
|
||||
|
||||
const cafes = await response.json();
|
||||
return cafes;
|
||||
const updatedCafe = await response.json();
|
||||
return updatedCafe;
|
||||
} catch (error) {
|
||||
console.error("Error:", error);
|
||||
}
|
||||
}
|
||||
|
||||
// helpers/cafeHelpers.js
|
||||
export async function saveCafeDetails(cafeId, details) {
|
||||
try {
|
||||
const formData = new FormData();
|
||||
|
||||
// Append qrBackground file if it exists
|
||||
if (details.qrBackgroundFile) {
|
||||
formData.append("qrBackground", details.qrBackgroundFile);
|
||||
}
|
||||
|
||||
// Append qrPayment file if it exists
|
||||
if (details.qrPaymentFile) {
|
||||
formData.append("qrPayment", details.qrPaymentFile);
|
||||
}
|
||||
|
||||
// Append other form fields
|
||||
if (details.qrPosition) {
|
||||
formData.append("xposition", details.qrPosition.left);
|
||||
formData.append("yposition", details.qrPosition.top);
|
||||
}
|
||||
if (details.qrSize) formData.append("scale", details.qrSize);
|
||||
|
||||
const response = await fetch(`${API_BASE_URL}/cafe/set-cafe/${cafeId}`, {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
Authorization: `Bearer ${getAuthToken()}`,
|
||||
},
|
||||
body: formData,
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error("Failed to save cafe details");
|
||||
}
|
||||
|
||||
return await response.json();
|
||||
} catch (error) {
|
||||
console.error("Error saving cafe details:", error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user