feat : update discussion

This commit is contained in:
lukman
2024-08-14 15:38:04 +08:00
parent fcf54d1924
commit f341200c0d
18 changed files with 521 additions and 186 deletions

View File

@@ -1,4 +1,4 @@
import { IFormDiscussion } from "./type_discussion";
import { ICreateComent, IEditDiscussion, IFormDiscussion, IStatusDiscussion } from "./type_discussion";
export const funGetAllDiscussion = async (path?: string) => {
const response = await fetch(`/api/discussion${(path) ? path : ''}`, { next: { tags: ['discussion'] } });
@@ -23,4 +23,50 @@ export const funCreateDiscussion = async (data: IFormDiscussion) => {
export const funGetDiscussionById = async (path: string) => {
const response = await fetch(`/api/discussion/${path}`);
return await response.json().catch(() => null);
}
}
export const funEditStatusDiscussion = async (path: string, data: IStatusDiscussion) => {
console.log('masuk sini')
const response = await fetch(`/api/discussion/${path}`, {
method: "DELETE",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
});
return await response.json().catch(() => null);
}
export const funDeleteDiscussion = async (path: string) => {
const response = await fetch(`/api/discussion/${path}`, {
method: "PUT",
});
return await response.json().catch(() => null);
}
export const funEditDiscussion = async (path: string, data: IEditDiscussion) => {
if (data.desc == "")
return { success: false, message: 'Diskusi tidak boleh kosong' }
const response = await fetch(`/api/discussion/${path}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
});
return await response.json().catch(() => null);
}
export const funCreateComent = async (path: string, data: ICreateComent) => {
const response = await fetch(`/api/discussion/${path}/comment`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
});
return await response.json().catch(() => null);
}