tambahan
This commit is contained in:
@@ -1,75 +1,138 @@
|
||||
import Elysia, { t } from "elysia";
|
||||
import { Elysia, t } from "elysia";
|
||||
|
||||
const layanan = `
|
||||
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
|
||||
`
|
||||
/**
|
||||
* 🧩 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<string, LayananRecord> = {};
|
||||
|
||||
/**
|
||||
* 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"],
|
||||
prefix: "/layanan",
|
||||
tags: ["layanan"],
|
||||
})
|
||||
.get("/list", () => {
|
||||
return {
|
||||
success: true,
|
||||
data: layanan.split("\n")
|
||||
}
|
||||
}, {
|
||||
detail: {
|
||||
summary: "list",
|
||||
description: "list layanan yang ada",
|
||||
}
|
||||
})
|
||||
.post("create-ktp", () => {
|
||||
return {
|
||||
success: true,
|
||||
data: ""
|
||||
}
|
||||
}, {
|
||||
body: t.Object({
|
||||
jenis: t.Union([
|
||||
t.Literal("ktp"),
|
||||
t.Literal("kk"),
|
||||
]),
|
||||
nama: t.String(),
|
||||
deskripsi: t.String(),
|
||||
}),
|
||||
detail: {
|
||||
summary: "create",
|
||||
description: "create layanan",
|
||||
}
|
||||
})
|
||||
.post("/status-ktp", ({ body }) => {
|
||||
const { uniqid } = body
|
||||
// 🔹 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.",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
if (!uniqid) {
|
||||
return {
|
||||
success: false,
|
||||
message: "uniqid is required"
|
||||
}
|
||||
}
|
||||
return {
|
||||
success: true,
|
||||
data: "on progress"
|
||||
}
|
||||
}, {
|
||||
body: t.Object({
|
||||
uniqid: t.String(),
|
||||
}),
|
||||
detail: {
|
||||
summary: "status-ktp",
|
||||
description: "status ktp",
|
||||
}
|
||||
})
|
||||
|
||||
// 🔹 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",
|
||||
};
|
||||
|
||||
export default LayananRoute
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user