feat : update member

This commit is contained in:
lukman
2024-08-09 17:27:34 +08:00
parent 5b4b780af5
commit 8b97a6f27d
19 changed files with 427 additions and 15 deletions

View File

@@ -0,0 +1,64 @@
import { IEditDataMember, IFormMember, IStatusmember } from "./type_member";
export const funGetAllmember = async (path?: string) => {
const response = await fetch(`/api/member${(path) ? path : ''}`, { next: { tags: ['member'] } });
return await response.json().catch(() => null);
}
export const funGetOneMember = async (path: string) => {
const response = await fetch(`/api/member/${path}`);
return await response.json().catch(() => null);
}
export const funCreateMember = async (data: IFormMember) => {
if (data.name.length < 3)
return { success: false, message: 'Minimal 3 karakter' }
if (data.email.length < 3)
return { success: false, message: 'Minimal 3 karakter' }
if (data.phone.length < 10)
return { success: false, message: 'Minimal 10 karakter' }
if (data.nik.length == 16)
return { success: false, message: 'NIK harus 16 karakter' }
const response = await fetch("/api/member", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
});
return await response.json().catch(() => null);
}
export const funEditStatusMember = async (path: string, data: IStatusmember) => {
const response = await fetch(`/api/member/${path}`, {
method: "DELETE",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
});
return await response.json().catch(() => null);
}
export const funEditMember = async (path: string, data: IEditDataMember) => {
if (data.name.length < 3)
return { success: false, message: 'Minimal 3 karakter' }
const response = await fetch(`/api/member/${path}`, {
method: "PUT",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
});
return await response.json().catch(() => null);
}

View File

@@ -0,0 +1,49 @@
export interface IListMember {
id: string,
isActive: boolean
nik: string,
name: string,
phone: string,
email: string,
gender: string,
group: string,
position: string,
}
export interface IFormMember {
nik: string;
name: string;
phone: string;
email: string;
gender: string;
idGroup: string;
idPosition: string;
idUserRole: string;
}
export interface IStatusmember {
isActive: boolean;
}
// EDIT MEMBER
export interface IEditDataMember {
id: string;
nik: string;
name: string;
phone: string;
email: string;
gender: string;
idGroup: string;
idPosition: string;
idUserRole: string;
}
export interface IDataPositionMember {
id: string;
name: string;
};
export interface IDataROleMember {
id: string;
name: string;
}