FIX UI & API Menu Lingkungan Submenu Gotong Royong
This commit is contained in:
@@ -191,7 +191,9 @@ const kegiatanDesa = proxy({
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
kegiatanDesa.edit.loading = true;
|
kegiatanDesa.edit.loading = true;
|
||||||
const response = await fetch(`/api/lingkungan/kegiatandesa/${this.id}`, {
|
const response = await fetch(
|
||||||
|
`/api/lingkungan/kegiatandesa/${this.id}`,
|
||||||
|
{
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -200,7 +202,8 @@ const kegiatanDesa = proxy({
|
|||||||
judul: this.form.judul,
|
judul: this.form.judul,
|
||||||
deskripsiSingkat: this.form.deskripsiSingkat,
|
deskripsiSingkat: this.form.deskripsiSingkat,
|
||||||
deskripsiLengkap: this.form.deskripsiLengkap,
|
deskripsiLengkap: this.form.deskripsiLengkap,
|
||||||
tanggal: typeof this.form.tanggal === "string"
|
tanggal:
|
||||||
|
typeof this.form.tanggal === "string"
|
||||||
? this.form.tanggal
|
? this.form.tanggal
|
||||||
: this.form.tanggal.toISOString(),
|
: this.form.tanggal.toISOString(),
|
||||||
lokasi: this.form.lokasi,
|
lokasi: this.form.lokasi,
|
||||||
@@ -208,7 +211,8 @@ const kegiatanDesa = proxy({
|
|||||||
imageId: this.form.imageId,
|
imageId: this.form.imageId,
|
||||||
kategoriKegiatanId: this.form.kategoriKegiatanId,
|
kategoriKegiatanId: this.form.kategoriKegiatanId,
|
||||||
}),
|
}),
|
||||||
});
|
}
|
||||||
|
);
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const errorData = await response.json().catch(() => ({}));
|
const errorData = await response.json().catch(() => ({}));
|
||||||
throw new Error(
|
throw new Error(
|
||||||
@@ -226,7 +230,9 @@ const kegiatanDesa = proxy({
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error updating kegiatan desa:", error);
|
console.error("Error updating kegiatan desa:", error);
|
||||||
toast.error(
|
toast.error(
|
||||||
error instanceof Error ? error.message : "Gagal mengupdate kegiatan desa"
|
error instanceof Error
|
||||||
|
? error.message
|
||||||
|
: "Gagal mengupdate kegiatan desa"
|
||||||
);
|
);
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
@@ -263,9 +269,9 @@ const kategoriKegiatan = proxy({
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
kategoriKegiatan.create.loading = true;
|
kategoriKegiatan.create.loading = true;
|
||||||
const res = await ApiFetch.api.lingkungan.kegiatandesa.kategorikegiatan["create"].post(
|
const res = await ApiFetch.api.lingkungan.kategorikegiatan[
|
||||||
kategoriKegiatan.create.form
|
"create"
|
||||||
);
|
].post(kategoriKegiatan.create.form);
|
||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
kategoriKegiatan.findMany.load();
|
kategoriKegiatan.findMany.load();
|
||||||
return toast.success("Data berhasil ditambahkan");
|
return toast.success("Data berhasil ditambahkan");
|
||||||
@@ -285,7 +291,9 @@ const kategoriKegiatan = proxy({
|
|||||||
nama: string;
|
nama: string;
|
||||||
}> | null,
|
}> | null,
|
||||||
async load() {
|
async load() {
|
||||||
const res = await ApiFetch.api.lingkungan.kegiatandesa.kategorikegiatan["find-many"].get();
|
const res = await ApiFetch.api.lingkungan.kategorikegiatan[
|
||||||
|
"find-many"
|
||||||
|
].get();
|
||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
kategoriKegiatan.findMany.data = res.data?.data ?? [];
|
kategoriKegiatan.findMany.data = res.data?.data ?? [];
|
||||||
}
|
}
|
||||||
@@ -297,7 +305,9 @@ const kategoriKegiatan = proxy({
|
|||||||
}> | null,
|
}> | null,
|
||||||
async load(id: string) {
|
async load(id: string) {
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`/api/lingkungan/kegiatanDesa/kategorikegiatan/${id}`);
|
const res = await fetch(
|
||||||
|
`/api/lingkungan/kategorikegiatan/${id}`
|
||||||
|
);
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
kategoriKegiatan.findUnique.data = data.data ?? null;
|
kategoriKegiatan.findUnique.data = data.data ?? null;
|
||||||
@@ -319,12 +329,15 @@ const kategoriKegiatan = proxy({
|
|||||||
try {
|
try {
|
||||||
kategoriKegiatan.delete.loading = true;
|
kategoriKegiatan.delete.loading = true;
|
||||||
|
|
||||||
const response = await fetch(`/api/lingkungan/kegiatandesa/kategorikegiatan/del/${id}`, {
|
const response = await fetch(
|
||||||
|
`/api/lingkungan/kategorikegiatan/del/${id}`,
|
||||||
|
{
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
const result = await response.json();
|
const result = await response.json();
|
||||||
|
|
||||||
@@ -354,12 +367,15 @@ const kategoriKegiatan = proxy({
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`/api/lingkungan/kegiatandesa/kategorikegiatan/${id}`, {
|
const response = await fetch(
|
||||||
|
`/api/lingkungan/kategorikegiatan/${id}`,
|
||||||
|
{
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
});
|
}
|
||||||
|
);
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(`HTTP error! status: ${response.status}`);
|
throw new Error(`HTTP error! status: ${response.status}`);
|
||||||
}
|
}
|
||||||
@@ -396,7 +412,7 @@ const kategoriKegiatan = proxy({
|
|||||||
try {
|
try {
|
||||||
kategoriKegiatan.edit.loading = true;
|
kategoriKegiatan.edit.loading = true;
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`/api/lingkungan/kegiatandesa/kategorikegiatan/${kategoriKegiatan.edit.id}`,
|
`/api/lingkungan/kategorikegiatan/${kategoriKegiatan.edit.id}`,
|
||||||
{
|
{
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
headers: {
|
headers: {
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import KegiatanDesaDelete from "./del";
|
|||||||
import KegiatanDesaFindMany from "./findMany";
|
import KegiatanDesaFindMany from "./findMany";
|
||||||
import KegiatanDesaFindUnique from "./findUnique";
|
import KegiatanDesaFindUnique from "./findUnique";
|
||||||
import KegiatanDesaUpdate from "./updt";
|
import KegiatanDesaUpdate from "./updt";
|
||||||
import KategoriKegiatan from "./kategori-kegiatan";
|
|
||||||
|
|
||||||
const KegiatanDesa = new Elysia({
|
const KegiatanDesa = new Elysia({
|
||||||
prefix: "/kegiatandesa",
|
prefix: "/kegiatandesa",
|
||||||
@@ -44,11 +43,6 @@ const KegiatanDesa = new Elysia({
|
|||||||
kategoriKegiatanId: t.Optional(t.String()),
|
kategoriKegiatanId: t.Optional(t.String()),
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
// ✅ Kategori kegiatan routes (nested)
|
|
||||||
.use(KategoriKegiatan)
|
|
||||||
|
|
||||||
// ✅ Delete
|
// ✅ Delete
|
||||||
.delete("/del/:id", KegiatanDesaDelete);
|
.delete("/del/:id", KegiatanDesaDelete);
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ const kategoriKegiatanDelete = async (context: Context) => {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
message: "Success delete kategori kegiatan",
|
message: "Success delete kategori produk",
|
||||||
data: kategoriKegiatan,
|
data: kategoriKegiatan,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ const KategoriKegiatan = new Elysia({
|
|||||||
})
|
})
|
||||||
.put("/:id", kategoriKegiatanUpdate, {
|
.put("/:id", kategoriKegiatanUpdate, {
|
||||||
body: t.Object({
|
body: t.Object({
|
||||||
id: t.String(),
|
|
||||||
nama: t.String(),
|
nama: t.String(),
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import DataLingkunganDesa from "./data-lingkungan-desa";
|
|||||||
import EdukasiLingkungan from "./edukasi-lingkungan";
|
import EdukasiLingkungan from "./edukasi-lingkungan";
|
||||||
import KonservasiAdatBali from "./konservasi-adat-bali";
|
import KonservasiAdatBali from "./konservasi-adat-bali";
|
||||||
import KegiatanDesa from "./gotong-royong";
|
import KegiatanDesa from "./gotong-royong";
|
||||||
|
import KategoriKegiatan from "./gotong-royong/kategori-kegiatan";
|
||||||
|
|
||||||
const Lingkungan = new Elysia({
|
const Lingkungan = new Elysia({
|
||||||
prefix: "/api/lingkungan",
|
prefix: "/api/lingkungan",
|
||||||
@@ -17,6 +18,7 @@ const Lingkungan = new Elysia({
|
|||||||
.use(EdukasiLingkungan)
|
.use(EdukasiLingkungan)
|
||||||
.use(KonservasiAdatBali)
|
.use(KonservasiAdatBali)
|
||||||
.use(KegiatanDesa)
|
.use(KegiatanDesa)
|
||||||
|
.use(KategoriKegiatan)
|
||||||
|
|
||||||
|
|
||||||
export default Lingkungan;
|
export default Lingkungan;
|
||||||
|
|||||||
Reference in New Issue
Block a user