feat : update discussion
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user