add stocking page

This commit is contained in:
zadit frontend
2024-08-03 07:29:36 +00:00
parent c4654ce64f
commit 5b4de33afb
21 changed files with 990 additions and 248 deletions

View File

@@ -0,0 +1,72 @@
import API_BASE_URL from "../config.js";
// Function to retrieve the authentication token from localStorage
function getAuthToken() {
return localStorage.getItem("auth");
}
// Helper function to get headers with authentication token
const getHeaders = (method = "GET") => {
const headers = {
Authorization: `Bearer ${getAuthToken()}`,
};
// No content-type header needed for FormData; fetch will handle it automatically
if (method !== "POST" && method !== "PUT") {
return { method, headers };
}
return {
method,
headers,
};
};
// Create a new material
export const createMaterial = async (cafeId, data) => {
console.log(cafeId);
const response = await fetch(`${API_BASE_URL}/material/create/${cafeId}`, {
...getHeaders("POST"),
body: data, // Assuming data is FormData with image
});
return response.json();
};
// Get all materials for a specific cafe
export const getMaterials = async (cafeId) => {
const response = await fetch(
`${API_BASE_URL}/material/get-materials/${cafeId}`,
getHeaders()
);
return response.json();
};
// Get a single material by its ID
export const getMaterialById = async (materialId) => {
const response = await fetch(
`${API_BASE_URL}/material/get-material/${materialId}`,
getHeaders()
);
return response.json();
};
// Update a material by its ID
export const updateMaterial = async (materialId, data) => {
const response = await fetch(
`${API_BASE_URL}/material/update-material/${materialId}`,
{
...getHeaders("PUT"),
body: data, // Assuming data is FormData with image
}
);
return response.json();
};
// Delete a material by its ID
export const deleteMaterial = async (materialId) => {
const response = await fetch(
`${API_BASE_URL}/material/delete-material/${materialId}`,
getHeaders("DELETE")
);
return response.json();
};

View File

@@ -0,0 +1,65 @@
import API_BASE_URL from "../config.js";
// Function to retrieve the authentication token from localStorage
function getAuthToken() {
return localStorage.getItem("auth");
}
// Helper function to get headers with authentication token
const getHeaders = (method = "GET", body = null) => {
const headers = {
Authorization: `Bearer ${getAuthToken()}`,
"Content-Type": "application/json",
};
return {
method,
headers,
body: body ? JSON.stringify(body) : null,
};
};
// Create a new material mutation
export const createMaterialMutation = async (materialId, data) => {
try {
const response = await fetch(
`${API_BASE_URL}/mutation/create/${materialId}`,
getHeaders("POST", data)
);
if (!response.ok) throw new Error("Failed to create material mutation.");
return await response.json();
} catch (error) {
console.error(error);
throw error;
}
};
// Get all material mutations for a specific cafe
export const getMaterialMutations = async (cafeId) => {
try {
const response = await fetch(
`${API_BASE_URL}/mutation/get-material-mutations/${cafeId}`,
getHeaders()
);
if (!response.ok) throw new Error("Failed to retrieve material mutations.");
return await response.json();
} catch (error) {
console.error(error);
throw error;
}
};
// Get a single material mutation by its ID
export const getMaterialMutationById = async (mutationId) => {
try {
const response = await fetch(
`${API_BASE_URL}/mutation/get-material-mutation/${mutationId}`,
getHeaders()
);
if (!response.ok) throw new Error("Failed to retrieve material mutation.");
return await response.json();
} catch (error) {
console.error(error);
throw error;
}
};

View File

@@ -2,6 +2,29 @@ import API_BASE_URL from "../config.js";
import { getLocalStorage, updateLocalStorage } from "./localStorageHelpers";
import { getItemsByCafeId } from "../helpers/cartHelpers.js";
export async function confirmTransaction(transactionId) {
try {
const token = getLocalStorage("auth");
const response = await fetch(
`${API_BASE_URL}/transaction/confirm-transaction/${transactionId}`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
},
}
);
if (!response.ok) {
return false;
}
return true;
} catch (error) {
console.error("Error:", error);
}
}
export async function getTransactions(shopId, demand) {
try {
const token = getLocalStorage("auth");
@@ -140,7 +163,8 @@ export const handlePaymentFromGuestDevice = async (
shopId,
payment_type,
serving_type,
tableNo
tableNo,
socketId
) => {
try {
const token = getLocalStorage("auth");
@@ -167,6 +191,7 @@ export const handlePaymentFromGuestDevice = async (
serving_type,
tableNo,
transactions: structuredItems,
socketId,
}),
}
);