Files
sistem-desa-mandiri/src/module/discussion_general/lib/api_discussion_general.ts
amel 11b4e31d29 rev: diskusi umum
Deskripsi:
- memberi komentar
- edit diskusi
- hapus diskusi
- status aktif diskusi
- tambah anggota diskusi
- hapus anggota diskusi

No Issues
2025-01-08 17:22:12 +08:00

91 lines
3.0 KiB
TypeScript

import { IFormMemberDisscussionGeneral } from "./type_discussion_general";
export const funGetAllDiscussionGeneral = async (path?: string) => {
const response = await fetch(`/api/discussion-general${(path) ? path : ''}`, { next: { tags: ['discussion-general'] } });
return await response.json().catch(() => null);
}
export const funCreateDiscussionGeneral = async (data: { idGroup: string, title: string, desc: string, member: IFormMemberDisscussionGeneral[] }) => {
const response = await fetch(`/api/discussion-general`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
});
return await response.json().catch(() => null);
}
export const funGetOneDiscussionGeneral = async (id: string, path: string) => {
const response = await fetch(`/api/discussion-general/${id}${(path) ? path : ''}`, { next: { tags: ['discussion-general'] } });
return await response.json().catch(() => null);
}
export const funCreateComentDiscussionGeneral = async (path: string, data: { desc: string }) => {
const response = await fetch(`/api/discussion-general/${path}/comment`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
});
return await response.json().catch(() => null);
}
export const funEditStatusDiscussionGeneral = async (path: string, data: { status: number }) => {
const response = await fetch(`/api/discussion-general/${path}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
});
return await response.json().catch(() => null);
}
export const funEditDiscussionGeneral = async (path: string, data: { title: string, desc: string }) => {
const response = await fetch(`/api/discussion-general/${path}`, {
method: "PUT",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
});
return await response.json().catch(() => null);
}
export const funDeleteDiscussionGeneral = async (path: string) => {
const response = await fetch(`/api/discussion-general/${path}`, {
method: "DELETE",
});
return await response.json().catch(() => null);
}
export const funAddMemberDiscussionGeneral = async (path: string, data: { member: IFormMemberDisscussionGeneral[] }) => {
const response = await fetch(`/api/discussion-general/${path}/member`, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(data)
})
return await response.json().catch(() => null)
}
export const funDelMemberDiscussionGeneral = async (path: string, data: { idUser: string }) => {
const response = await fetch(`/api/discussion-general/${path}/member`, {
method: "DELETE",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(data)
})
return await response.json().catch(() => null)
}