QC User & Admin Responsive : Menu Landing Page - Desa
This commit is contained in:
@@ -27,7 +27,7 @@ async function kategoriBeritaFindMany(context: Context) {
|
||||
where,
|
||||
skip,
|
||||
take: limit,
|
||||
orderBy: { createdAt: 'desc' },
|
||||
orderBy: { createdAt: 'asc' },
|
||||
}),
|
||||
prisma.kategoriBerita.count({ where }),
|
||||
]);
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Context } from "elysia";
|
||||
|
||||
export default async function permohonanInformasiPublikFindUnique(context: Context) {
|
||||
const url = new URL(context.request.url);
|
||||
const pathSegments = url.pathname.split('/');
|
||||
const id = pathSegments[pathSegments.length - 1];
|
||||
|
||||
if (!id) {
|
||||
return {
|
||||
success: false,
|
||||
message: "ID is required",
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if (typeof id !== 'string') {
|
||||
return {
|
||||
success: false,
|
||||
message: "ID is required",
|
||||
}
|
||||
}
|
||||
|
||||
const data = await prisma.permohonanInformasiPublik.findUnique({
|
||||
where: { id },
|
||||
include: {
|
||||
jenisInformasiDiminta: true,
|
||||
caraMemperolehInformasi: true,
|
||||
caraMemperolehSalinanInformasi: true,
|
||||
}
|
||||
});
|
||||
|
||||
if (!data) {
|
||||
return {
|
||||
success: false,
|
||||
message: "Permohonan informasi publik tidak ditemukan",
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "Success find permohonan informasi publik",
|
||||
data,
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Find by ID error:", error);
|
||||
return {
|
||||
success: false,
|
||||
message: "Gagal mengambil permohonan informasi publik: " + (error instanceof Error ? error.message : 'Unknown error'),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import permohonanInformasiPublikFindMany from "./find-many";
|
||||
import jenisInformasiFindMany from "./jenisInformasi";
|
||||
import memperolehInformasiFindMany from "./memperolehInformasi";
|
||||
import salinanInformasiFindMany from "./salinanInformasi";
|
||||
import permohonanInformasiPublikFindUnique from "./findUnique";
|
||||
|
||||
const PermohonanInformasiPublik = new Elysia({
|
||||
prefix: "/permohonaninformasipublik",
|
||||
@@ -12,6 +13,10 @@ const PermohonanInformasiPublik = new Elysia({
|
||||
.get("/jenisInformasi/find-many", jenisInformasiFindMany)
|
||||
.get("/memperolehInformasi/find-many", memperolehInformasiFindMany)
|
||||
.get("/salinanInformasi/find-many", salinanInformasiFindMany)
|
||||
.get("/:id", async (context) => {
|
||||
const response = await permohonanInformasiPublikFindUnique(context);
|
||||
return response;
|
||||
})
|
||||
.get("/find-many", permohonanInformasiPublikFindMany)
|
||||
.post("/create", permohonanInformasiPublikCreate, {
|
||||
body: t.Object({
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Context } from "elysia";
|
||||
|
||||
export default async function permohonanKeberatanInformasiPublikFindUnique(context: Context) {
|
||||
const url = new URL(context.request.url);
|
||||
const pathSegments = url.pathname.split('/');
|
||||
const id = pathSegments[pathSegments.length - 1];
|
||||
|
||||
if (!id) {
|
||||
return {
|
||||
success: false,
|
||||
message: "ID is required",
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if (typeof id !== 'string') {
|
||||
return {
|
||||
success: false,
|
||||
message: "ID is required",
|
||||
}
|
||||
}
|
||||
|
||||
const data = await prisma.formulirPermohonanKeberatan.findUnique({
|
||||
where: { id },
|
||||
});
|
||||
|
||||
if (!data) {
|
||||
return {
|
||||
success: false,
|
||||
message: "Permohonan keberatan informasi publik tidak ditemukan",
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "Success find permohonan keberatan informasi publik",
|
||||
data,
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Find by ID error:", error);
|
||||
return {
|
||||
success: false,
|
||||
message: "Gagal mengambil permohonan keberatan informasi publik: " + (error instanceof Error ? error.message : 'Unknown error'),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,14 @@
|
||||
import Elysia, { t } from "elysia";
|
||||
import permohonanKeberatanInformasiPublikCreate from "./create";
|
||||
import permohonanKeberatanInformasiPublikFindMany from "./find-many";
|
||||
import permohonanKeberatanInformasiPublikFindUnique from "./findUnique";
|
||||
|
||||
const PermohonanKeberatanInformasiPublik = new Elysia({
|
||||
prefix: "/permohonankeberataninformasipublik",
|
||||
tags: ["PPID/Permohonan Keberatan Informasi Publik"],
|
||||
})
|
||||
.get("/find-many", permohonanKeberatanInformasiPublikFindMany)
|
||||
.get("/:id", permohonanKeberatanInformasiPublikFindUnique)
|
||||
.post("/create", permohonanKeberatanInformasiPublikCreate, {
|
||||
body: t.Object({
|
||||
name: t.String(),
|
||||
|
||||
@@ -13,17 +13,13 @@ export default async function pegawaiDelete(context: Context) {
|
||||
}
|
||||
|
||||
try {
|
||||
const deleted = await prisma.pegawaiPPID.update({
|
||||
const deleted = await prisma.pegawaiPPID.delete({
|
||||
where: { id },
|
||||
data: {
|
||||
isActive: false, // soft delete
|
||||
updatedAt: new Date(),
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "Pegawai berhasil di-nonaktifkan",
|
||||
message: "Pegawai berhasil dihapus",
|
||||
data: deleted,
|
||||
};
|
||||
} catch (error: any) {
|
||||
|
||||
@@ -2,8 +2,9 @@ import Elysia, { t } from "elysia";
|
||||
import pegawaiFindMany from "./findMany";
|
||||
import pegawaiFindUnique from "./findUnique";
|
||||
import pegawaiCreate from "./create";
|
||||
import pegawaiDelete from "./del";
|
||||
import pegawaiNonActive from "./nonActive";
|
||||
import pegawaiUpdate from "./updt";
|
||||
import pegawaiDelete from "./del";
|
||||
|
||||
|
||||
const Pegawai = new Elysia({
|
||||
@@ -58,6 +59,7 @@ const Pegawai = new Elysia({
|
||||
)
|
||||
|
||||
// ✅ Delete
|
||||
.delete("/non-active/:id", pegawaiNonActive)
|
||||
.delete("/del/:id", pegawaiDelete);
|
||||
|
||||
export default Pegawai;
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Context } from "elysia";
|
||||
|
||||
export default async function pegawaiNonActive(context: Context) {
|
||||
const { id } = context.params as { id: string };
|
||||
|
||||
if (!id) {
|
||||
return {
|
||||
success: false,
|
||||
message: "ID pegawai tidak ditemukan",
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
const deleted = await prisma.pegawaiPPID.update({
|
||||
where: { id },
|
||||
data: {
|
||||
isActive: false, // soft delete
|
||||
updatedAt: new Date(),
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "Pegawai berhasil di-nonaktifkan",
|
||||
data: deleted,
|
||||
};
|
||||
} catch (error: any) {
|
||||
console.error("Error nonaktifkan pegawai:", error);
|
||||
return {
|
||||
success: false,
|
||||
message: "Gagal nonaktifkan pegawai",
|
||||
error: error.message,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
// /api/posisi-organisasi/findManyAll.ts
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Context } from "elysia";
|
||||
|
||||
async function posisiOrganisasiFindManyAll(context: Context) {
|
||||
const search = (context.query.search as string) || "";
|
||||
|
||||
// filter default
|
||||
const where: any = { isActive: true };
|
||||
|
||||
if (search) {
|
||||
where.OR = [
|
||||
{ nama: { contains: search, mode: "insensitive" } },
|
||||
{ deskripsi: { contains: search, mode: "insensitive" } },
|
||||
];
|
||||
}
|
||||
|
||||
try {
|
||||
const data = await prisma.posisiOrganisasiPPID.findMany({
|
||||
where,
|
||||
orderBy: { hierarki: "asc" },
|
||||
});
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "Berhasil mengambil semua data posisi organisasi",
|
||||
data: data.map((item: any) => ({
|
||||
id: item.id,
|
||||
nama: item.nama,
|
||||
deskripsi: item.deskripsi,
|
||||
hierarki: item.hierarki,
|
||||
})),
|
||||
total: data.length,
|
||||
};
|
||||
} catch (e) {
|
||||
console.error("Find many all error:", e);
|
||||
return {
|
||||
success: false,
|
||||
message: "Gagal mengambil data posisi organisasi",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export default posisiOrganisasiFindManyAll;
|
||||
@@ -4,6 +4,7 @@ import posisiOrganisasiFindUnique from "./findUnique";
|
||||
import posisiOrganisasiCreate from "./create";
|
||||
import posisiOrganisasiUpdate from "./updt";
|
||||
import posisiOrganisasiDelete from "./del";
|
||||
import posisiOrganisasiFindManyAll from "./findManyAll";
|
||||
|
||||
const PosisiOrganisasi = new Elysia({
|
||||
prefix: "/posisiorganisasi",
|
||||
@@ -11,6 +12,7 @@ const PosisiOrganisasi = new Elysia({
|
||||
})
|
||||
|
||||
.get("/find-many", posisiOrganisasiFindMany)
|
||||
.get("/find-many-all", posisiOrganisasiFindManyAll)
|
||||
.get("/:id", async (context) => {
|
||||
const response = await posisiOrganisasiFindUnique(context);
|
||||
return response;
|
||||
|
||||
Reference in New Issue
Block a user