Files
sistem-desa-mandiri/src/module/group/lib/api_group.ts
amel 4687b7382d upd: new group
Deskripsi:
- pembaruan api group

NO Issues
2024-08-07 17:39:21 +08:00

49 lines
1.4 KiB
TypeScript

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);
};