import { Elysia, t } from "elysia"; /** * 🧩 Domain: Layanan (Citizen Service) * This module handles basic CRUD-like operations for various public services (layanan). * Routes include listing available services, creating a KTP request, and checking status. */ // Define a clean data structure for layanan list const layananList = [ "KTP", "Kartu Keluarga", "Surat Keterangan Domisili", "Surat Pengantar Nikah", "Akta Kelahiran", "Akta Kematian", "Surat Pindah Penduduk", "Surat Keterangan Usaha", "Surat Keterangan Tidak Mampu", "Surat Keterangan Waris", "Surat Perizinan Usaha Kecil", ]; /** * Example: Simple in-memory store for demonstration * In production, replace with a real database (e.g., Prisma ORM) */ interface LayananRecord { id: string; jenis: "ktp" | "kk"; nama: string; deskripsi: string; status: "on progress" | "completed" | "rejected"; } const layananStore: Record = {}; /** * Helper: Generate unique IDs (temporary substitute for UUID) */ const generateId = () => `srv_${Date.now().toString(36)}_${Math.random().toString(36).substring(2, 8)}`; /** * LayananRoute: Handles citizen service endpoints */ const LayananRoute = new Elysia({ prefix: "/layanan", tags: ["layanan"], }) // 🔹 GET /layanan/list — Return list of all available services .get( "/list", () => ({ success: true, data: layananList, }), { detail: { summary: "List Layanan", description: "Returns the list of all available public services.", }, } ) // 🔹 POST /layanan/create-ktp — Create a new KTP or KK request .post( "/create-ktp", ({ body }) => { const id = generateId(); const record: LayananRecord = { id, jenis: body.jenis, nama: body.nama.trim(), deskripsi: body.deskripsi.trim(), status: "on progress", }; layananStore[id] = record; return { success: true, message: "Layanan berhasil dibuat.", data: record, }; }, { body: t.Object({ jenis: t.Union([t.Literal("ktp"), t.Literal("kk")]), nama: t.String({ minLength: 3, description: "Nama pemohon layanan" }), deskripsi: t.String({ minLength: 5, description: "Deskripsi singkat permohonan layanan", }), }), detail: { summary: "Create Layanan KTP/KK", description: "Create a new service request for KTP or KK.", }, } ) // 🔹 POST /layanan/status-ktp — Check status of a KTP/KK request .post( "/status-ktp", ({ body }) => { const record = layananStore[body.uniqid]; if (!record) { return { success: false, message: "Layanan tidak ditemukan atau ID tidak valid.", }; } return { success: true, message: "Status layanan berhasil diambil.", data: { id: record.id, nama: record.nama, jenis: record.jenis, status: record.status, }, }; }, { body: t.Object({ uniqid: t.String({ description: "Unique ID layanan" }), }), detail: { summary: "Cek Status KTP", description: "Retrieve the current status of a KTP/KK request by unique ID.", }, } ); export default LayananRoute;