fixes to app

This commit is contained in:
Patryk
2025-06-08 20:18:38 +02:00
parent dbf07cea0a
commit bcce392c9b
13 changed files with 1450 additions and 375 deletions

View File

@@ -14,9 +14,11 @@ export async function listNotices() {
headers: headers,
});
const data = await response.json();
if (!response.ok) {
throw new Error(response.toString());
}
// console.info("Notices fetched successfully:", data);
return data;
}
@@ -68,8 +70,12 @@ export async function getImageByNoticeId(noticeId) {
}
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}`);
const listResponse = await axios.get(`${API_URL}/images/list/${noticeId}`, {
headers,
});
if (listResponse.data && listResponse.data.length > 0) {
return listResponse.data.map(
@@ -127,3 +133,23 @@ export const uploadImage = async (noticeId, imageUri) => {
throw error;
}
};
export const deleteNotice = async (noticeId) => {
const { token } = useAuthStore.getState();
const headers = token ? { Authorization: `Bearer ${token}` } : {};
try {
const response = await axios.delete(
`${API_URL}/notices/delete/${noticeId}`,
{ headers }
);
return response.data;
} catch (error) {
console.error(
"Error deleting notice:",
error.response?.data,
error.response?.status
);
throw error;
}
};