fixes to app
This commit is contained in:
@@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user