upd: new group
Deskripsi: - pembaruan api group NO Issues
This commit is contained in:
48
src/module/group/lib/api_group.ts
Normal file
48
src/module/group/lib/api_group.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { IFormGroup, IStatusGroup } from "./type_group";
|
||||
|
||||
export const funGetAllGroup = async (path?: string) => {
|
||||
const response = await fetch(`/api/group${(path) ? path : ''}`, { next: { tags: ['group'] } });
|
||||
return await response.json().catch(() => null);
|
||||
};
|
||||
|
||||
export const funGetGroupById = async (path: string) => {
|
||||
const response = await fetch(`/api/group/${path}`);
|
||||
return await response.json().catch(() => null);
|
||||
};
|
||||
|
||||
export const funCreateGroup = async (data: IFormGroup) => {
|
||||
if (data.name.length < 3)
|
||||
return { success: false, message: 'Minimal 3 karakter' }
|
||||
|
||||
const response = await fetch("/api/group", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
return await response.json().catch(() => null);
|
||||
};
|
||||
|
||||
export const funEditStatusGroup = async (path: string, data: IStatusGroup) => {
|
||||
const response = await fetch(`/api/group/${path}`, {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
return await response.json().catch(() => null);
|
||||
};
|
||||
|
||||
export const funEditGroup = async (path: string, data: IFormGroup) => {
|
||||
const response = await fetch(`/api/group/${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