latest update 27 jul 24
This commit is contained in:
29
src/helpers/cafeHelpers.js
Normal file
29
src/helpers/cafeHelpers.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import API_BASE_URL from "../config.js";
|
||||
|
||||
function getAuthToken() {
|
||||
return localStorage.getItem("auth");
|
||||
}
|
||||
|
||||
export async function getOwnedCafes(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()}`,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error("Failed to fetch cart details");
|
||||
}
|
||||
|
||||
const cafes = await response.json();
|
||||
return cafes;
|
||||
} catch (error) {
|
||||
console.error("Error:", error);
|
||||
}
|
||||
}
|
||||
93
src/helpers/cartHelpers.js
Normal file
93
src/helpers/cartHelpers.js
Normal file
@@ -0,0 +1,93 @@
|
||||
import { getLocalStorage, updateLocalStorage } from './localStorageHelpers';
|
||||
|
||||
// Get quantity from localStorage based on cafeId and itemId
|
||||
export const getItemQtyFromCart = (cafeId, itemId) => {
|
||||
const cart = JSON.parse(getLocalStorage('cart')) || [];
|
||||
const cafeItem = cart.find(cafeItem => cafeItem.cafeId === cafeId);
|
||||
if (cafeItem) {
|
||||
const item = cafeItem.items.find(item => item.itemId === itemId);
|
||||
return item ? item.qty : 0;
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
|
||||
export const getItemsByCafeId = (cafeId) => {
|
||||
const cart = JSON.parse(getLocalStorage('cart')) || [];
|
||||
const cafeItem = cart.find(cafeItem => cafeItem.cafeId === cafeId);
|
||||
return cafeItem ? cafeItem.items : [];
|
||||
};
|
||||
|
||||
// Update quantity in localStorage for a specific cafeId and itemId
|
||||
export const updateItemQtyInCart = (cafeId, itemId, qty) => {
|
||||
let cart = JSON.parse(getLocalStorage('cart')) || [];
|
||||
const cafeIndex = cart.findIndex(cafeItem => cafeItem.cafeId === cafeId);
|
||||
|
||||
if (cafeIndex > -1) {
|
||||
const itemIndex = cart[cafeIndex].items.findIndex(item => item.itemId === itemId);
|
||||
if (itemIndex > -1) {
|
||||
if (qty > 0) {
|
||||
cart[cafeIndex].items[itemIndex].qty = qty; // Update qty if item exists
|
||||
} else {
|
||||
cart[cafeIndex].items.splice(itemIndex, 1); // Remove item if qty is 0
|
||||
}
|
||||
} else if (qty > 0) {
|
||||
cart[cafeIndex].items.push({ itemId, qty }); // Add new item
|
||||
}
|
||||
} else if (qty > 0) {
|
||||
cart.push({ cafeId, items: [{ itemId, qty }] }); // Add new cafeId and item
|
||||
}
|
||||
|
||||
updateLocalStorage('cart', JSON.stringify(cart));
|
||||
};
|
||||
|
||||
// Remove item from localStorage based on cafeId and itemId
|
||||
export const removeItemFromCart = (cafeId, itemId) => {
|
||||
let items = JSON.parse(getLocalStorage('cart')) || [];
|
||||
const cafeIndex = items.findIndex(cafeItem => cafeItem.cafeId === cafeId);
|
||||
if (cafeIndex > -1) {
|
||||
items[cafeIndex].items = items[cafeIndex].items.filter(item => item.itemId !== itemId);
|
||||
if (items[cafeIndex].items.length === 0) {
|
||||
items.splice(cafeIndex, 1); // Remove cafeId if no items left
|
||||
}
|
||||
|
||||
updateLocalStorage('cart', JSON.stringify(items));
|
||||
}
|
||||
};
|
||||
|
||||
// Function to calculate total items count for a specific cafeId from localStorage
|
||||
export const calculateTotals = (cafeId) => {
|
||||
// Get cart items from localStorage
|
||||
const cart = JSON.parse(getLocalStorage('cart')) || [];
|
||||
const cafeCart = cart.find(cafe => cafe.cafeId === cafeId);
|
||||
|
||||
if (!cafeCart) {
|
||||
return { totalCount: 0, totalPrice: 0 }; // Return 0 if no items for the specified cafeId
|
||||
}
|
||||
|
||||
const totalCount = cafeCart.items.reduce((total, item) => {
|
||||
return total + item.qty;
|
||||
}, 0);
|
||||
|
||||
// Assuming each item has a `price` property
|
||||
const totalPrice = cafeCart.items.reduce((total, item) => {
|
||||
return total + (item.qty * item.price);
|
||||
}, 0);
|
||||
|
||||
return { totalCount, totalPrice };
|
||||
};
|
||||
|
||||
// Function to calculate total price for a specific cafeId from localStorage
|
||||
export const calculateTotalPrice = (cafeId) => {
|
||||
// Get cart items from localStorage
|
||||
const cart = JSON.parse(getLocalStorage('cart')) || [];
|
||||
const cafeCart = cart.find(cafe => cafe.cafeId === cafeId);
|
||||
|
||||
const totalPrice = cafeCart.items.reduce((total, cafeItem) => {
|
||||
if (cafeItem.cafeId === cafeId) {
|
||||
return total + cafeItem.items.reduce((acc, item) => acc + (item.qty * item.price), 0);
|
||||
}
|
||||
return total;
|
||||
}, 0);
|
||||
|
||||
return totalPrice;
|
||||
};
|
||||
159
src/helpers/itemHelper.js
Normal file
159
src/helpers/itemHelper.js
Normal file
@@ -0,0 +1,159 @@
|
||||
import API_BASE_URL from '../config.js';
|
||||
import { getItemsByCafeId } from './cartHelpers.js';
|
||||
|
||||
export async function getItemTypesWithItems(shopId) {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE_URL}/item/get-cafe-items/` + shopId);
|
||||
|
||||
const data = await response.json();
|
||||
return { response, data: data.data }; // Return an object with response and data
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch item types with items:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export async function getItemType(shopId) {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE_URL}/item/getItemType/` + shopId);
|
||||
|
||||
const data = await response.json();
|
||||
return { response, data: data.data }; // Return an object with response and data
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch item types with items:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export async function getCartDetails(shopId) {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE_URL}/item/get-cart-details/` + shopId, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(getItemsByCafeId(shopId)),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to fetch cart details');
|
||||
}
|
||||
|
||||
const cartDetails = await response.json();
|
||||
console.log(cartDetails);
|
||||
return cartDetails;
|
||||
} catch (error) {
|
||||
console.error('Error:', error);
|
||||
}
|
||||
}
|
||||
|
||||
export function getImageUrl(notimageurl) {
|
||||
return API_BASE_URL + '/' + notimageurl;
|
||||
}
|
||||
|
||||
function getAuthToken() {
|
||||
return localStorage.getItem('auth');
|
||||
}
|
||||
|
||||
export async function createItem(shopId, name, price, qty, selectedImage, itemTypeId) {
|
||||
try {
|
||||
console.log(selectedImage)
|
||||
const formData = new FormData();
|
||||
formData.append('name', name);
|
||||
formData.append('price', price);
|
||||
formData.append('stock', qty);
|
||||
formData.append('image', selectedImage);
|
||||
formData.append('itemTypeId', itemTypeId);
|
||||
|
||||
const response = await fetch(`${API_BASE_URL}/item/create/${shopId}`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${getAuthToken()}`
|
||||
},
|
||||
body: formData
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorMessage = await response.text();
|
||||
throw new Error(`Error: ${errorMessage}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error('Failed to create item type:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export async function createItemType(shopId, name, selectedImage) {
|
||||
try {
|
||||
const formData = new FormData();
|
||||
formData.append('name', name);
|
||||
formData.append('image', selectedImage);
|
||||
|
||||
const response = await fetch(`${API_BASE_URL}/item/createType/${shopId}`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${getAuthToken()}`
|
||||
},
|
||||
body: formData
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorMessage = await response.text();
|
||||
throw new Error(`Error: ${errorMessage}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error('Failed to create item type:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export async function updateItemType(shopId, itemTypeId, newName) {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE_URL}/item/updateType/` + shopId + "/" + itemTypeId, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${getAuthToken()}`
|
||||
},
|
||||
body: JSON.stringify({ newName })
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Error: ${response.statusText}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error('Failed to update item type:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export async function deleteItemType(shopId, itemTypeId) {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE_URL}/item/deleteType/` + shopId + "/" + itemTypeId, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${getAuthToken()}`
|
||||
}
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Error: ${response.statusText}`);
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('Failed to delete item type:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
20
src/helpers/localStorageHelpers.js
Normal file
20
src/helpers/localStorageHelpers.js
Normal file
@@ -0,0 +1,20 @@
|
||||
// localStorageHelpers.js
|
||||
|
||||
// Get cart items from localStorage
|
||||
export const getLocalStorage = (storageName) => {
|
||||
return localStorage.getItem(storageName) || null;
|
||||
};
|
||||
|
||||
export const updateLocalStorage = (storageName, value) => {
|
||||
localStorage.setItem(storageName, value);
|
||||
|
||||
const event = new Event('localStorageUpdated');
|
||||
window.dispatchEvent(event);
|
||||
}
|
||||
|
||||
export const removeLocalStorage = (storageName,) => {
|
||||
localStorage.removeItem(storageName);
|
||||
|
||||
const event = new Event('localStorageUpdated');
|
||||
window.dispatchEvent(event);
|
||||
}
|
||||
50
src/helpers/navigationHelpers.js
Normal file
50
src/helpers/navigationHelpers.js
Normal file
@@ -0,0 +1,50 @@
|
||||
import { useNavigate } from "react-router-dom";
|
||||
|
||||
/**
|
||||
* Custom hook to provide navigation functions.
|
||||
* @param {string} params - The shop ID for constructing URLs.
|
||||
* @returns {Object} - Navigation functions.
|
||||
*/
|
||||
export const useNavigationHelpers = (params) => {
|
||||
const navigate = useNavigate();
|
||||
|
||||
const goToLogin = () => {
|
||||
if (params) navigate(`/login?next=${params}`);
|
||||
else navigate(`/login`);
|
||||
};
|
||||
|
||||
const goToShop = () => {
|
||||
navigate(`/${params}/`);
|
||||
};
|
||||
|
||||
const goToCart = () => {
|
||||
navigate(`/${params}/cart`);
|
||||
};
|
||||
|
||||
const goToInvoice = (orderType, tableNumber, email) => {
|
||||
if (orderType === "serve" && tableNumber) {
|
||||
navigate(
|
||||
`/${params}/invoice?orderType=${orderType}&tableNumber=${tableNumber}&email=${email}`,
|
||||
);
|
||||
} else {
|
||||
navigate(`/${params}/invoice?orderType=${orderType}}&email=${email}`);
|
||||
}
|
||||
};
|
||||
|
||||
const goToGuestSideLogin = () => {
|
||||
navigate(`/${params}/guest-side-login`);
|
||||
};
|
||||
|
||||
const goToAdminCafes = () => {
|
||||
navigate(`/`);
|
||||
};
|
||||
|
||||
return {
|
||||
goToLogin,
|
||||
goToShop,
|
||||
goToCart,
|
||||
goToInvoice,
|
||||
goToGuestSideLogin,
|
||||
goToAdminCafes,
|
||||
};
|
||||
};
|
||||
21
src/helpers/tableHelper.js
Normal file
21
src/helpers/tableHelper.js
Normal file
@@ -0,0 +1,21 @@
|
||||
import API_BASE_URL from '../config.js';
|
||||
|
||||
export async function getTable(shopId, tableNo) {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE_URL}/table/get-table/${shopId}?tableNo=${tableNo}`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const tableDetail = await response.json();
|
||||
return tableDetail;
|
||||
} catch (error) {
|
||||
console.error('Error:', error);
|
||||
}
|
||||
}
|
||||
163
src/helpers/transactionHelpers.js
Normal file
163
src/helpers/transactionHelpers.js
Normal file
@@ -0,0 +1,163 @@
|
||||
import API_BASE_URL from "../config.js";
|
||||
import { getLocalStorage } from "./localStorageHelpers";
|
||||
import { getItemsByCafeId } from "../helpers/cartHelpers.js";
|
||||
|
||||
export const handlePaymentFromClerk = async (
|
||||
shopId,
|
||||
user_email,
|
||||
payment_type,
|
||||
serving_type,
|
||||
tableNo,
|
||||
) => {
|
||||
try {
|
||||
const token = getLocalStorage("auth");
|
||||
const items = getItemsByCafeId(shopId);
|
||||
|
||||
const structuredItems = {
|
||||
items: items.map((item) => ({
|
||||
itemId: item.itemId,
|
||||
qty: item.qty,
|
||||
})),
|
||||
};
|
||||
|
||||
console.log(items);
|
||||
const response = await fetch(
|
||||
API_BASE_URL + "/transaction/fromClerk/" + shopId,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
user_email: user_email,
|
||||
payment_type,
|
||||
serving_type,
|
||||
tableNo,
|
||||
transactions: structuredItems,
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
if (response.ok) {
|
||||
// Handle success response
|
||||
console.log("Transaction successful!");
|
||||
// Optionally return response data or handle further actions upon success
|
||||
return true;
|
||||
} else {
|
||||
// Handle error response
|
||||
console.error("Transaction failed:", response.statusText);
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error sending transaction:", error);
|
||||
// Handle network or other errors
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
export const handlePaymentFromGuestSide = async (
|
||||
shopId,
|
||||
user_email,
|
||||
payment_type,
|
||||
serving_type,
|
||||
tableNo,
|
||||
) => {
|
||||
try {
|
||||
const token = getLocalStorage("authGuestSide");
|
||||
const items = getItemsByCafeId(shopId);
|
||||
|
||||
const structuredItems = {
|
||||
items: items.map((item) => ({
|
||||
itemId: item.itemId,
|
||||
qty: item.qty,
|
||||
})),
|
||||
};
|
||||
|
||||
console.log(items);
|
||||
const response = await fetch(
|
||||
API_BASE_URL + "/transaction/fromGuestSide/" + shopId,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
user_email: user_email,
|
||||
payment_type,
|
||||
serving_type,
|
||||
tableNo,
|
||||
transactions: structuredItems,
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
if (response.ok) {
|
||||
// Handle success response
|
||||
console.log("Transaction successful!");
|
||||
// Optionally return response data or handle further actions upon success
|
||||
return true;
|
||||
} else {
|
||||
// Handle error response
|
||||
console.error("Transaction failed:", response.statusText);
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error sending transaction:", error);
|
||||
// Handle network or other errors
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
export const handlePaymentFromGuestDevice = async (
|
||||
shopId,
|
||||
payment_type,
|
||||
serving_type,
|
||||
tableNo,
|
||||
) => {
|
||||
try {
|
||||
const token = getLocalStorage("auth");
|
||||
const items = getItemsByCafeId(shopId);
|
||||
|
||||
const structuredItems = {
|
||||
items: items.map((item) => ({
|
||||
itemId: item.itemId,
|
||||
qty: item.qty,
|
||||
})),
|
||||
};
|
||||
|
||||
console.log(items);
|
||||
const response = await fetch(
|
||||
API_BASE_URL + "/transaction/fromGuestDevice/" + shopId,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
payment_type,
|
||||
serving_type,
|
||||
tableNo,
|
||||
transactions: structuredItems,
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
if (response.ok) {
|
||||
// Handle success response
|
||||
console.log("Transaction successful!");
|
||||
// Optionally return response data or handle further actions upon success
|
||||
return true;
|
||||
} else {
|
||||
// Handle error response
|
||||
console.error("Transaction failed:", response.statusText);
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error sending transaction:", error);
|
||||
// Handle network or other errors
|
||||
return false;
|
||||
}
|
||||
};
|
||||
171
src/helpers/userHelpers.js
Normal file
171
src/helpers/userHelpers.js
Normal file
@@ -0,0 +1,171 @@
|
||||
import {
|
||||
getLocalStorage,
|
||||
updateLocalStorage,
|
||||
removeLocalStorage,
|
||||
} from "./localStorageHelpers";
|
||||
import API_BASE_URL from "../config.js";
|
||||
|
||||
export async function checkToken(socketId) {
|
||||
console.log(socketId);
|
||||
const token = getLocalStorage("auth");
|
||||
if (token) {
|
||||
try {
|
||||
const response = await fetch(API_BASE_URL + "/user/check-token", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
socketId,
|
||||
}),
|
||||
});
|
||||
if (response.status === 200) {
|
||||
const responseData = await response.json();
|
||||
|
||||
return { ok: true, user: responseData };
|
||||
} else {
|
||||
removeLocalStorage("auth");
|
||||
return { ok: false };
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error occurred while verifying token:", error.message);
|
||||
return { ok: false };
|
||||
}
|
||||
}
|
||||
return { ok: false };
|
||||
}
|
||||
|
||||
export async function getConnectedGuestSides() {
|
||||
const token = getLocalStorage("auth");
|
||||
if (token) {
|
||||
try {
|
||||
const response = await fetch(API_BASE_URL + "/getConnectedGuestsSides", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
if (response.status === 200) {
|
||||
const { message, sessionDatas } = await response.json();
|
||||
console.log(message);
|
||||
return { ok: true, sessionDatas };
|
||||
} else {
|
||||
updateLocalStorage("authGuestSide", "");
|
||||
return { ok: false };
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error occurred while verifying token:", error.message);
|
||||
return { ok: false };
|
||||
}
|
||||
}
|
||||
return { ok: false };
|
||||
}
|
||||
|
||||
export async function removeConnectedGuestSides(guestSideSessionId) {
|
||||
const token = getLocalStorage("auth");
|
||||
if (token) {
|
||||
try {
|
||||
const response = await fetch(
|
||||
API_BASE_URL + "/removeConnectedGuestsSides",
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
guestSideSessionId,
|
||||
}),
|
||||
},
|
||||
);
|
||||
if (response.status === 200) {
|
||||
const { message, guestSideList } = await response.json();
|
||||
console.log(message);
|
||||
return { ok: true, guestSideList };
|
||||
} else {
|
||||
return { ok: false };
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error occurred while verifying token:", error.message);
|
||||
return { ok: false };
|
||||
}
|
||||
}
|
||||
return { ok: false };
|
||||
}
|
||||
|
||||
export const loginUser = async (username, password) => {
|
||||
try {
|
||||
const response = await fetch(API_BASE_URL + `/user/login`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({ username, password }),
|
||||
});
|
||||
console.log(username, password);
|
||||
const responseData = await response.json();
|
||||
|
||||
if (response.ok) {
|
||||
return {
|
||||
success: true,
|
||||
token: responseData.token,
|
||||
cafeId: responseData.cafeId,
|
||||
};
|
||||
} else {
|
||||
return { success: false, token: null };
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error occurred while logging in:", error.message);
|
||||
return { success: false, token: null };
|
||||
}
|
||||
};
|
||||
|
||||
export const updateUser = async (formData) => {
|
||||
const token = getLocalStorage("auth");
|
||||
if (token) {
|
||||
try {
|
||||
const response = await fetch(API_BASE_URL + "/user/update-user", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
body: JSON.stringify(formData),
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
const data = await response.json();
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error("Error updating user:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//for super
|
||||
export const getAllCafeOwner = async (formData) => {
|
||||
const token = getLocalStorage("auth");
|
||||
if (token) {
|
||||
try {
|
||||
const response = await fetch(API_BASE_URL + "/user/get-admin", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
const data = await response.json();
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error("Error updating user:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user