tambahan
This commit is contained in:
@@ -1,75 +1,138 @@
|
|||||||
import Elysia, { t } from "elysia";
|
import { Elysia, t } from "elysia";
|
||||||
|
|
||||||
const layanan = `
|
/**
|
||||||
KTP
|
* 🧩 Domain: Layanan (Citizen Service)
|
||||||
Kartu Keluarga
|
* This module handles basic CRUD-like operations for various public services (layanan).
|
||||||
surat keterangan domisili
|
* Routes include listing available services, creating a KTP request, and checking status.
|
||||||
surat pengantar nikah
|
*/
|
||||||
akta kelahiran
|
|
||||||
akta kematian
|
|
||||||
surat pindah penduduk
|
|
||||||
surat keterangan usaha
|
|
||||||
surat keterangan tidak mampu
|
|
||||||
surat keterangan waris
|
|
||||||
surat perizinan usaha kecil
|
|
||||||
`
|
|
||||||
|
|
||||||
|
// 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({
|
const LayananRoute = new Elysia({
|
||||||
prefix: "layanan",
|
prefix: "/layanan",
|
||||||
tags: ["layanan"],
|
tags: ["layanan"],
|
||||||
})
|
})
|
||||||
.get("/list", () => {
|
// 🔹 GET /layanan/list — Return list of all available services
|
||||||
return {
|
.get(
|
||||||
|
"/list",
|
||||||
|
() => ({
|
||||||
success: true,
|
success: true,
|
||||||
data: layanan.split("\n")
|
data: layananList,
|
||||||
}
|
}),
|
||||||
}, {
|
{
|
||||||
detail: {
|
detail: {
|
||||||
summary: "list",
|
summary: "List Layanan",
|
||||||
description: "list layanan yang ada",
|
description: "Returns the list of all available public services.",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
})
|
)
|
||||||
.post("create-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",
|
||||||
|
};
|
||||||
|
|
||||||
|
layananStore[id] = record;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
data: ""
|
message: "Layanan berhasil dibuat.",
|
||||||
}
|
data: record,
|
||||||
}, {
|
};
|
||||||
|
},
|
||||||
|
{
|
||||||
body: t.Object({
|
body: t.Object({
|
||||||
jenis: t.Union([
|
jenis: t.Union([t.Literal("ktp"), t.Literal("kk")]),
|
||||||
t.Literal("ktp"),
|
nama: t.String({ minLength: 3, description: "Nama pemohon layanan" }),
|
||||||
t.Literal("kk"),
|
deskripsi: t.String({
|
||||||
]),
|
minLength: 5,
|
||||||
nama: t.String(),
|
description: "Deskripsi singkat permohonan layanan",
|
||||||
deskripsi: t.String(),
|
}),
|
||||||
}),
|
}),
|
||||||
detail: {
|
detail: {
|
||||||
summary: "create",
|
summary: "Create Layanan KTP/KK",
|
||||||
description: "create layanan",
|
description: "Create a new service request for KTP or KK.",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
})
|
)
|
||||||
.post("/status-ktp", ({ body }) => {
|
|
||||||
const { uniqid } = body
|
|
||||||
|
|
||||||
if (!uniqid) {
|
// 🔹 POST /layanan/status-ktp — Check status of a KTP/KK request
|
||||||
|
.post(
|
||||||
|
"/status-ktp",
|
||||||
|
({ body }) => {
|
||||||
|
const record = layananStore[body.uniqid];
|
||||||
|
|
||||||
|
if (!record) {
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
message: "uniqid is required"
|
message: "Layanan tidak ditemukan atau ID tidak valid.",
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
data: "on progress"
|
message: "Status layanan berhasil diambil.",
|
||||||
}
|
data: {
|
||||||
}, {
|
id: record.id,
|
||||||
|
nama: record.nama,
|
||||||
|
jenis: record.jenis,
|
||||||
|
status: record.status,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
{
|
||||||
body: t.Object({
|
body: t.Object({
|
||||||
uniqid: t.String(),
|
uniqid: t.String({ description: "Unique ID layanan" }),
|
||||||
}),
|
}),
|
||||||
detail: {
|
detail: {
|
||||||
summary: "status-ktp",
|
summary: "Cek Status KTP",
|
||||||
description: "status ktp",
|
description: "Retrieve the current status of a KTP/KK request by unique ID.",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
})
|
);
|
||||||
|
|
||||||
|
export default LayananRoute;
|
||||||
export default LayananRoute
|
|
||||||
|
|||||||
Reference in New Issue
Block a user