Files
ArtisanConnectFrontend/ArtisanConnect/api/order.jsx
Andrii Solianyk 8f72f28566 Order zwracał 403, bo nie było headerów
Zdjęcia nie były centerowane względem szerokości
2025-06-10 11:24:08 +02:00

78 lines
1.9 KiB
JavaScript

import axios from "axios";
import { useAuthStore } from "@/store/authStore";
const API_URL = "https://hopp.zikor.pl/api/v1/orders";
export async function createOrder(noticeId, orderType) {
const { token } = useAuthStore.getState();
const headers = token ? { Authorization: `Bearer ${token}` } : {};
const clientId = 1;
try {
const response = await axios.post(
`${API_URL}/add`,
{ clientId: clientId, noticeId: noticeId, orderType: orderType },
{
headers: headers,
}
);
return response.data;
} catch (error) {
console.log("Error", error.response?.data, error.response?.status);
return null;
}
}
export async function createPayment(orderId) {
const { token } = useAuthStore.getState();
const headers = token ? { Authorization: `Bearer ${token}` } : {};
try {
const response = await axios.post(
`${API_URL}/token?orderId=${orderId}`,
{},
{
headers: headers,
}
);
return response.data;
} catch (error) {
console.log("Error", error.response?.data, error.response?.status);
return null;
}
}
export async function getOrder(orderId) {
const { token } = useAuthStore.getState();
const headers = token ? { Authorization: `Bearer ${token}` } : {};
try {
const response = await axios.get(`${API_URL}/get/${orderId}`, { headers: headers });
return response.data;
} catch (error) {
console.error(
"Error fetching order:",
error.response?.data,
error.response?.status
);
throw error;
}
}
export async function listOrders() {
const { token } = useAuthStore.getState();
const headers = token ? { Authorization: `Bearer ${token}` } : {};
try {
const response = await axios.get(`${API_URL}/get/all`, { headers: headers });
return response.data;
} catch (error) {
console.error(
"Error fetching orders:",
error.response?.data,
error.response?.status
);
throw error;
}
}