crazy gpt
This commit is contained in:
@@ -1,6 +1,63 @@
|
||||
import API_BASE_URL from "../config.js";
|
||||
import { getLocalStorage } from "./localStorageHelpers";
|
||||
|
||||
export async function createTable(shopId, newTable) {
|
||||
try {
|
||||
const token = getLocalStorage("auth");
|
||||
|
||||
// Construct the URL endpoint for creating a new table
|
||||
const response = await fetch(`${API_BASE_URL}/table/create/${shopId}`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
newTable: newTable,
|
||||
}), // Include the new table data in the body
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.text(); // Get error details from the response
|
||||
throw new Error(`Error: ${error}`);
|
||||
}
|
||||
|
||||
const table = await response.json(); // Assuming the response is the created table
|
||||
return table;
|
||||
} catch (error) {
|
||||
console.error("Error:", error);
|
||||
return false; // or handle the error as needed
|
||||
}
|
||||
}
|
||||
|
||||
export async function updateTable(shopId, table) {
|
||||
try {
|
||||
console.log(table);
|
||||
const token = getLocalStorage("auth");
|
||||
const response = await fetch(
|
||||
`${API_BASE_URL}/table/set-table/${shopId}/${table.tableId}`,
|
||||
{
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
table: table,
|
||||
}),
|
||||
}
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const tables = await response.json();
|
||||
return tables;
|
||||
} catch (error) {
|
||||
console.error("Error:", error);
|
||||
}
|
||||
}
|
||||
export async function getTables(shopId) {
|
||||
try {
|
||||
const token = getLocalStorage("auth");
|
||||
|
||||
Reference in New Issue
Block a user