This commit is contained in:
client perkafean
2024-09-27 09:07:57 +00:00
parent faee9dfd2d
commit 69b3fe4347
33 changed files with 824 additions and 204 deletions

View File

@@ -4,6 +4,26 @@ function getAuthToken() {
return localStorage.getItem("auth");
}
export async function getCafe(cafeId) {
try {
const response = await fetch(`${API_BASE_URL}/cafe/get-cafe/` + cafeId, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
});
if (!response.ok) {
throw new Error("Failed to fetch cafes");
}
const cafe = await response.json();
return cafe;
} catch (error) {
console.error("Error:", error);
}
}
export async function getOwnedCafes(userId) {
try {
const response = await fetch(
@@ -36,8 +56,9 @@ export async function createCafe(cafeName) {
"Content-Type": "application/json",
Authorization: `Bearer ${getAuthToken()}`,
},
body: JSON.stringify({
name: cafeName }),
body: JSON.stringify({
name: cafeName,
}),
});
if (!response.ok) {
@@ -73,6 +94,33 @@ export async function updateCafe(cafeId, cafeDetails) {
}
}
export async function setConfirmationStatus(cafeId, isNeedConfirmation) {
try {
const response = await fetch(
`${API_BASE_URL}/cafe/confirmation-status/` + cafeId,
{
method: "PUT",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${getAuthToken()}`,
},
body: JSON.stringify({ isNeedConfirmation: isNeedConfirmation }),
}
);
if (!response.ok) {
// throw new Error(`Error: ${response.statusText}`);
}
const data = await response.json();
console.log(data);
return data;
} catch (error) {
console.error("Failed to update item type:", error);
throw error;
}
}
// helpers/cafeHelpers.js
export async function saveCafeDetails(cafeId, details) {
try {

View File

@@ -4,7 +4,7 @@ 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
);
const data = await response.json();
@@ -37,7 +37,7 @@ export async function getCartDetails(shopId) {
"Content-Type": "application/json",
},
body: JSON.stringify(getItemsByCafeId(shopId)),
},
}
);
if (!response.ok) {
@@ -66,7 +66,7 @@ export async function createItem(
price,
qty,
selectedImage,
itemTypeId,
itemTypeId
) {
try {
console.log(selectedImage);
@@ -98,6 +98,33 @@ export async function createItem(
}
}
export async function updateItemAvalilability(itemId, isAvailable) {
try {
const response = await fetch(
`${API_BASE_URL}/item/set-availability/` + itemId,
{
method: "PUT",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${getAuthToken()}`,
},
body: JSON.stringify({ isAvailable: isAvailable }),
}
);
if (!response.ok) {
// throw new Error(`Error: ${response.statusText}`);
}
const data = await response.json();
console.log(data);
return data;
} catch (error) {
console.error("Failed to update item type:", error);
throw error;
}
}
export async function createItemType(shopId, name, selectedImage) {
try {
const formData = new FormData();
@@ -136,7 +163,7 @@ export async function updateItemType(shopId, itemTypeId, newName) {
Authorization: `Bearer ${getAuthToken()}`,
},
body: JSON.stringify({ newName }),
},
}
);
if (!response.ok) {
@@ -160,7 +187,7 @@ export async function deleteItemType(shopId, itemTypeId) {
headers: {
Authorization: `Bearer ${getAuthToken()}`,
},
},
}
);
if (!response.ok) {

View File

@@ -103,10 +103,10 @@ export async function getTable(shopId, tableNo) {
}
}
export async function getTableByCode(tableCode) {
export async function getTableByCode(shopId, tableCode) {
try {
const response = await fetch(
`${API_BASE_URL}/table/get-table-by-code/${tableCode}`,
`${API_BASE_URL}/table/get-table-by-code/${shopId}/${tableCode}`,
{
method: "GET",
headers: {

View File

@@ -52,7 +52,6 @@ export async function declineTransaction(transactionId) {
export async function cancelTransaction(transactionId) {
try {
console.log(transactionId);
const token = getLocalStorage("auth");
const response = await fetch(
`${API_BASE_URL}/transaction/cancel-transaction/${transactionId}`,
@@ -65,6 +64,7 @@ export async function cancelTransaction(transactionId) {
}
);
console.log(response);
if (!response.ok) {
return false;
}