some fixes

This commit is contained in:
Patryk
2025-06-09 20:59:43 +02:00
parent 77c3a694f8
commit 27175ffa91
7 changed files with 221 additions and 197 deletions

View File

@@ -2,7 +2,7 @@ import axios from "axios";
import FormData from "form-data";
import { useAuthStore } from "@/store/authStore";
// const API_URL = "https://testowe.zikor.pl/api/v1";
// const API_URL = "https://hopp.zikor.pl/api/v1";
const API_URL = "https://hopp.zikor.pl/api/v1";
@@ -36,7 +36,9 @@ export async function createNotice(notice) {
const { token } = useAuthStore.getState();
const headers = token ? { Authorization: `Bearer ${token}` } : {};
try {
const response = await axios.post(`${API_URL}/notices/add`, notice, {headers: headers});
const response = await axios.post(`${API_URL}/notices/add`, notice, {
headers: headers,
});
if (response.data.noticeId !== null) {
for (const imageUri of notice.image) {
@@ -71,7 +73,9 @@ export async function getAllImagesByNoticeId(noticeId) {
const { token } = useAuthStore.getState();
const headers = token ? { Authorization: `Bearer ${token}` } : {};
try {
const listResponse = await axios.get(`${API_URL}/images/list/${noticeId}`, {headers: headers});
const listResponse = await axios.get(`${API_URL}/images/list/${noticeId}`, {
headers: headers,
});
if (listResponse.data && listResponse.data.length > 0) {
return listResponse.data.map((imageName) => ({

View File

@@ -1,6 +1,4 @@
import axios from "axios";
import FormData from "form-data";
import { useAuthStore } from "@/store/authStore";
const API_URL = "https://hopp.zikor.pl/api/v1/orders";
@@ -9,17 +7,16 @@ 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, noticeId, orderType },
{ clientId: clientId, noticeId: noticeId, orderType: orderType },
{
headers: {
"Content-Type": "application/json",
...headers,
},
headers: headers,
}
);
return response.data;
} catch (error) {
console.log("Error", error.response?.data, error.response?.status);
@@ -33,13 +30,10 @@ export async function createPayment(orderId) {
const clientId = 1;
try {
const response = await axios.post(
`${API_URL}/token`,
`${API_URL}/token?orderId=${orderId}`,
{},
{
headers: {
"Content-Type": "application/json",
...headers,
},
headers: headers,
}
);
return response.data;
@@ -49,13 +43,30 @@ export async function createPayment(orderId) {
}
}
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 });
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 });
return response.data; // to będzie tablica OrderWithPaymentsDTO
return response.data;
} catch (error) {
console.error(
"Error fetching orders:",

View File

@@ -35,4 +35,4 @@ export async function getWishlist() {
throw error;
}
}
``
``;