upd: announcement
Deskripsi: - tambah - edit - detail No Issues
This commit is contained in:
@@ -1,16 +1,22 @@
|
||||
import { ICreateData } from "./type_announcement";
|
||||
import { ICreateData, IFormCreateAnnouncement } from "./type_announcement";
|
||||
|
||||
export const funGetAllAnnouncement = async (path?: string) => {
|
||||
const response = await fetch(`/api/announcement${(path) ? path : ''}`, { next: { tags: ['announcement'] } });
|
||||
return await response.json().catch(() => null);
|
||||
}
|
||||
}
|
||||
|
||||
export const funGetAnnouncementById = async (path: string) => {
|
||||
const response = await fetch(`/api/announcement/${path}`);
|
||||
return await response.json().catch(() => null);
|
||||
}
|
||||
|
||||
export const funCreateAnnouncement = async (data: ICreateData) => {
|
||||
export const funCreateAnnouncement = async (data: IFormCreateAnnouncement) => {
|
||||
if (data.title == "" || data.desc == "")
|
||||
return { success: false, message: 'Silahkan lengkapi form tambah pengumuman' }
|
||||
|
||||
if (data.groups.length == 0)
|
||||
return { success: false, message: 'Silahkan pilih divisi penerima pengumuman' }
|
||||
|
||||
const response = await fetch("/api/announcement", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
@@ -19,4 +25,31 @@ export const funCreateAnnouncement = async (data: ICreateData) => {
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
return await response.json().catch(() => null);
|
||||
}
|
||||
|
||||
export const funDeleteAnnouncement = async (path: string) => {
|
||||
const response = await fetch(`/api/announcement/${path}`, {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
return await response.json().catch(() => null);
|
||||
};
|
||||
|
||||
export const funEditAnnouncement = async (path: string, data: IFormCreateAnnouncement) => {
|
||||
if (data.title == "" || data.desc == "")
|
||||
return { success: false, message: 'Silahkan lengkapi form edit pengumuman' }
|
||||
|
||||
if (data.groups.length == 0)
|
||||
return { success: false, message: 'Silahkan pilih divisi penerima pengumuman' }
|
||||
|
||||
const response = await fetch(`/api/announcement/${path}`, {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
return await response.json().catch(() => null);
|
||||
}
|
||||
Reference in New Issue
Block a user