Fix Admin Submenu Posyandu, Menu Kesehatan, dan Sinkronisasi UI & API Admin - User Submenu Posyandu

This commit is contained in:
2025-08-14 11:48:57 +08:00
parent c99416c7f8
commit 5e137ba658
13 changed files with 273 additions and 157 deletions

View File

@@ -8,6 +8,7 @@ type FormCreate = Prisma.PosyanduGetPayload<{
nomor: true;
deskripsi: true;
imageId: true;
jadwalPelayanan: true;
};
}>;
export default async function posyanduCreate(context: Context) {
@@ -19,6 +20,7 @@ export default async function posyanduCreate(context: Context) {
nomor: body.nomor,
deskripsi: body.deskripsi,
imageId: body.imageId,
jadwalPelayanan: body.jadwalPelayanan,
}
})
return {

View File

@@ -1,26 +1,59 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
// /api/berita/findManyPaginated.ts
import prisma from "@/lib/prisma";
import { Context } from "elysia";
export default async function posyanduFindMany() {
try {
const data = await prisma.posyandu.findMany({
where: {
isActive: true,
},
async function posyanduFindMany(context: Context) {
// Ambil parameter dari query
const page = Number(context.query.page) || 1;
const limit = Number(context.query.limit) || 10;
const search = (context.query.search as string) || '';
const skip = (page - 1) * limit;
// Buat where clause
const where: any = { isActive: true };
// Tambahkan pencarian (jika ada)
if (search) {
where.OR = [
{ name: { contains: search, mode: 'insensitive' } },
{ deskripsi: { contains: search, mode: 'insensitive' } },
{ nomor: { contains: search, mode: 'insensitive' } },
{ jadwalPelayanan: { contains: search, mode: 'insensitive' } }
];
}
try {
// Ambil data dan total count secara paralel
const [data, total] = await Promise.all([
prisma.posyandu.findMany({
where,
include: {
image: true,
}
})
image: true,
},
skip,
take: limit,
orderBy: { createdAt: 'desc' },
}),
prisma.posyandu.count({ where }),
]);
return {
success: true,
message: "Success fetch posyandu",
data,
}
} catch (error) {
console.error("Find many error:", error);
success: true,
message: "Berhasil ambil posyandu dengan pagination",
data,
page,
limit,
total,
totalPages: Math.ceil(total / limit),
};
} catch (e) {
console.error("Error di posyanduFindMany paginated:", e);
return {
success: false,
message: "Failed fetch posyandu",
}
success: false,
message: "Gagal mengambil data posyandu",
};
}
}
}
export default posyanduFindMany;

View File

@@ -15,6 +15,7 @@ const Posyandu = new Elysia({
nomor: t.String(),
deskripsi: t.String(),
imageId: t.String(),
jadwalPelayanan: t.String(),
})
})
.get("/find-many", posyanduFindMany)
@@ -35,6 +36,7 @@ const Posyandu = new Elysia({
nomor: t.String(),
deskripsi: t.String(),
imageId: t.String(),
jadwalPelayanan: t.String(),
})
}
)

View File

@@ -11,6 +11,7 @@ type FormUpdate = Prisma.PosyanduGetPayload<{
nomor: true;
deskripsi: true;
imageId: true;
jadwalPelayanan: true;
}
}>
@@ -24,6 +25,7 @@ export default async function posyanduUpdate(context: Context) {
nomor,
deskripsi,
imageId,
jadwalPelayanan,
} = body;
if(!id) {
@@ -79,6 +81,7 @@ export default async function posyanduUpdate(context: Context) {
nomor,
deskripsi,
imageId,
jadwalPelayanan,
}
})