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);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ export interface IDataDiscussion {
|
||||
id: string
|
||||
title: string
|
||||
desc: string
|
||||
status: boolean
|
||||
status: number
|
||||
createdAt: string
|
||||
user_name: string
|
||||
total_komentar: number
|
||||
@@ -11,4 +11,45 @@ export interface IDataDiscussion {
|
||||
export interface IFormDiscussion {
|
||||
desc: string,
|
||||
idDivision: string
|
||||
}
|
||||
|
||||
export interface IStatusDiscussion {
|
||||
status: number
|
||||
}
|
||||
|
||||
|
||||
export interface IDetailDiscussion {
|
||||
id: string
|
||||
title: any
|
||||
desc: string
|
||||
status: number
|
||||
createdAt: string
|
||||
DivisionDisscussionComment: IAllComents[]
|
||||
username: string
|
||||
totalComments: number
|
||||
}
|
||||
|
||||
export interface IAllComents {
|
||||
id: string
|
||||
comment: string
|
||||
createdAt: string
|
||||
User: User
|
||||
username: string
|
||||
}
|
||||
|
||||
export interface User {
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface IDeleteDicussion {
|
||||
id: string
|
||||
}
|
||||
|
||||
export interface IEditDiscussion {
|
||||
desc: string
|
||||
}
|
||||
|
||||
export interface ICreateComent {
|
||||
comment: string
|
||||
idDiscussion: string
|
||||
}
|
||||
Reference in New Issue
Block a user