This commit is contained in:
zadit
2025-03-15 18:59:44 +07:00
parent 43ad59a1f8
commit a64b999a05
30 changed files with 1818 additions and 391 deletions

View File

@@ -2,7 +2,7 @@ import API_BASE_URL from "../config.js";
import { getLocalStorage, updateLocalStorage } from "./localStorageHelpers";
import { getItemsByCafeId } from "../helpers/cartHelpers.js";
export async function confirmTransaction(transactionId) {
export async function confirmTransaction(transactionId, notAcceptedItems) {
try {
const token = getLocalStorage("auth");
const response = await fetch(
@@ -13,6 +13,9 @@ export async function confirmTransaction(transactionId) {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
},
body: JSON.stringify({
notAcceptedItems
}),
}
);
if (!response.ok) {
@@ -363,6 +366,99 @@ export const handlePaymentFromGuestDevice = async (
}
};
export const handleCloseBillFromGuestDevice = async (
transactionId,
orderMethod,
socketId
) => {
try {
const token = getLocalStorage("auth");
const response = await fetch(
API_BASE_URL + "/transaction/closeBillFromGuestDevice/" + transactionId,
{
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
},
body: JSON.stringify({
socketId,
orderMethod
}),
}
);
if (response.ok) {
// Handle success response
console.log("Transaction successful!");
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 handleExtendFromGuestDevice = async (
shopId,
transactionId,
notes,
socketId
) => {
try {
const token = getLocalStorage("auth");
const items = getItemsByCafeId(shopId);
const structuredItems = {
items: items.map((item) => ({
itemId: item.itemId,
qty: item.qty,
price: item.price
})),
};
console.log(items);
const response = await fetch(
API_BASE_URL + "/transaction/extentFromGuestDevice/" + transactionId,
{
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
},
body: JSON.stringify({
transactions: structuredItems,
notes: notes,
socketId,
}),
}
);
if (response.ok) {
// Handle success response
console.log("Transaction successful!");
const data = await response.json();
if (data.newUser) updateLocalStorage("auth", data.auth);
// 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;
}
};
// Function to retrieve the authentication token from localStorage
function getAuthToken() {
return localStorage.getItem("auth");
@@ -383,13 +479,6 @@ const getHeaders = (method = "GET") => {
headers,
};
};
export const getFavourite = async (cafeId) => {
const response = await fetch(
`${API_BASE_URL}/transaction/get-favourite/${cafeId}`,
getHeaders()
);
return response.json();
};
export const getReports = async (cafeId, filter) => {
const response = await fetch(
@@ -417,12 +506,3 @@ export const getAnalytics = async (filter, selectedCafeId) => {
const response = await fetch(url, getHeaders('POST'));
return response.json();
};
export const getIncome = async (cafeId) => {
const response = await fetch(
`${API_BASE_URL}/transaction/get-income/${cafeId}`,
getHeaders()
);
return response.json();
};