Kebutuhan Deploy

This commit is contained in:
2025-06-26 11:00:15 +08:00
parent 4683034cd7
commit 4f6cc66b7c
18 changed files with 219 additions and 173 deletions

View File

@@ -39,15 +39,15 @@ const grafikkepuasan = proxy({
const res = await ApiFetch.api.kesehatan.grafikkepuasan["create"].post(grafikkepuasan.create.form);
if (res.status === 200) {
const id = res.data?.data?.id;
if (id) {
const uuid = res.data?.data?.uuid;
if (uuid) {
toast.success("Success create");
grafikkepuasan.create.form = {
label: "",
jumlah: "",
};
grafikkepuasan.findMany.load();
return id;
return uuid;
}
}
toast.error("failed create");
@@ -77,9 +77,9 @@ const grafikkepuasan = proxy({
data: null as Prisma.GrafikKepuasanGetPayload<{
omit: { isActive: true }
}> | null,
async load(id: string) {
async load(uuid: string) {
try {
const res = await fetch(`/api/kesehatan/grafikkepuasan/${id}`);
const res = await fetch(`/api/kesehatan/grafikkepuasan/${uuid}`);
if (res.ok) {
const data = await res.json();
grafikkepuasan.findUnique.data = data.data ?? null;
@@ -94,14 +94,14 @@ const grafikkepuasan = proxy({
},
},
update: {
id: "",
uuid: "",
form: {...defaultForm},
loading: false,
async byId() {
},
async submit() {
const id = this.id;
if (!id) {
const uuid = this.uuid;
if (!uuid) {
toast.warn("ID tidak valid");
return null;
}
@@ -114,7 +114,7 @@ const grafikkepuasan = proxy({
}
try {
this.loading = true;
const response = await fetch(`/api/kesehatan/grafikkepuasan/${id}`, {
const response = await fetch(`/api/kesehatan/grafikkepuasan/${uuid}`, {
method: "PUT",
headers: {
"Content-Type": "application/json",
@@ -143,14 +143,14 @@ const grafikkepuasan = proxy({
},
delete: {
loading: false,
async byId(id: string) {
if (!id) {
async byId(uuid: string) {
if (!uuid) {
return toast.warn("ID tidak valid");
}
try {
grafikkepuasan.delete.loading = true;
const response = await fetch(`/api/kesehatan/grafikkepuasan/del/${id}`, {
const response = await fetch(`/api/kesehatan/grafikkepuasan/del/${uuid}`, {
method: "DELETE",
headers: {
"Content-Type": "application/json",

View File

@@ -34,28 +34,23 @@ const persentasekelahiran = proxy({
async create() {
const cek = templatePersentase.safeParse(persentasekelahiran.create.form);
if (!cek.success) {
const err = `[${cek.error.issues
.map((v) => `${v.path.join(".")}`)
.join("\n")}] required`;
const err = `[${cek.error.issues.map((v) => `${v.path.join(".")}`).join("\n")}] required`;
toast.error(err);
return null;
}
try {
persentasekelahiran.create.loading = true;
const res = await ApiFetch.api.kesehatan.persentasekelahiran["create"].post(persentasekelahiran.create.form);
const res = await ApiFetch.api.kesehatan.persentasekelahiran["create"].post(
persentasekelahiran.create.form
);
if (res.status === 200) {
const id = res.data?.data?.id;
if (id) {
const uuid = res.data?.data?.uuid;
if (uuid) {
toast.success("Success create");
persentasekelahiran.create.form = {
tahun: "",
kematianKasar: "",
kelahiranKasar: "",
kematianBayi: "",
};
persentasekelahiran.create.form = { ...defaultForm };
persentasekelahiran.findMany.load();
return id;
return uuid;
}
}
toast.error("failed create");
@@ -68,26 +63,26 @@ const persentasekelahiran = proxy({
}
},
},
findMany: {
data: null as
| Prisma.DataKematian_KelahiranGetPayload<{ omit: { isActive: true } }>[]
| null,
data: null as Prisma.DataKematian_KelahiranGetPayload<{
omit: { isActive: true };
}>[] | null,
async load() {
const res = await ApiFetch.api.kesehatan.persentasekelahiran[
"find-many"
].get();
const res = await ApiFetch.api.kesehatan.persentasekelahiran["find-many"].get();
if (res.status === 200) {
persentasekelahiran.findMany.data = res.data?.data ?? [];
}
},
},
findUnique: {
data: null as Prisma.DataKematian_KelahiranGetPayload<{
omit: { isActive: true };
}> | null,
async load(id: string) {
async load(uuid: string) {
try {
const res = await fetch(`/api/kesehatan/persentasekelahiran/${id}`);
const res = await fetch(`/api/kesehatan/persentasekelahiran/${uuid}`);
if (res.ok) {
const data = await res.json();
persentasekelahiran.findUnique.data = data.data ?? null;
@@ -101,82 +96,86 @@ const persentasekelahiran = proxy({
}
},
},
update: {
id: "",
form: { ...defaultForm },
loading: false,
async byId() {},
async submit() {
const id = this.id;
if (!id) {
toast.warn("ID tidak valid");
return null;
update: {
uuid: "",
form: { ...defaultForm },
loading: false,
async submit() {
const uuid = this.uuid;
if (!uuid) {
toast.warn("UUID tidak valid");
return null;
}
const formData = {
tahun: this.form.tahun,
kematianKasar: this.form.kematianKasar,
kelahiranKasar: this.form.kelahiranKasar,
kematianBayi: this.form.kematianBayi,
};
const cek = templatePersentase.safeParse(formData);
if (!cek.success) {
const err = `[${cek.error.issues
.map((v) => `${v.path.join(".")}`)
.join("\n")}] required`;
toast.error(err);
return null;
}
try {
this.loading = true;
const res = await fetch(`/api/kesehatan/persentasekelahiran/${uuid}`, {
method: "PUT",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(formData),
});
const result = await res.json();
if (!res.ok || !result?.success) {
throw new Error(result?.message || "Gagal update data");
}
const cek = templatePersentase.safeParse(persentasekelahiran.update.form);
if (!cek.success) {
const err = `[${cek.error.issues
.map((v) => `${v.path.join(".")}`)
.join("\n")}] required`;
return toast.error(err);
}
try {
this.loading = true;
const response = await fetch(`/api/kesehatan/persentasekelahiran/${id}`, {
method: "PUT",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(this.form),
});
const result = await response.json();
if (!response.ok || !result?.success) {
throw new Error(result?.message || "Gagal update data");
}
toast.success("Berhasil update data!");
// ✅ Optional: refresh list kalau kamu langsung ke halaman list
await persentasekelahiran.findMany.load();
return result.data;
} catch (error) {
console.error("Error update data:", error);
toast.error("Gagal update data persentase kelahiran");
} finally {
this.loading = false;
}
},
toast.success("Berhasil update data!");
await persentasekelahiran.findMany.load();
return result.data;
} catch (error) {
console.error("Update error:", error);
toast.error("Gagal update data persentase kelahiran");
throw error;
} finally {
this.loading = false;
}
},
},
delete: {
loading: false,
async byId(id: string) {
if (!id) return toast.warn("ID tidak valid");
async byId(uuid: string) {
if (!uuid) return toast.warn("UUID tidak valid");
try {
persentasekelahiran.delete.loading = true;
const response = await fetch(
`/api/kesehatan/persentasekelahiran/del/${id}`,
{
method: "DELETE",
headers: {
"Content-Type": "application/json",
},
}
);
const response = await fetch(`/api/kesehatan/persentasekelahiran/del/${uuid}`, {
method: "DELETE",
headers: {
"Content-Type": "application/json",
},
});
const result = await response.json();
if (response.ok && result?.success) {
toast.success(
result.message || "Persentase kelahiran berhasil dihapus"
);
await persentasekelahiran.findMany.load(); // refresh list
toast.success(result.message || "Persentase kelahiran berhasil dihapus");
await persentasekelahiran.findMany.load();
} else {
toast.error(
result?.message || "Gagal menghapus persentase kelahiran"
);
toast.error(result?.message || "Gagal menghapus persentase kelahiran");
}
} catch (error) {
console.error("Gagal delete:", error);