From 6fc79f7541a40ca2b5cb8d81219a1d22b7edc84e Mon Sep 17 00:00:00 2001 From: nico Date: Thu, 23 Apr 2026 11:40:43 +0800 Subject: [PATCH 1/4] feat(storage): migrate file storage from local disk to MinIO Replace local filesystem-based image storage with MinIO S3-compatible object storage. All upload, serve, delete, and list operations now use the MinIO bucket defined in MINIO_* env vars. Co-Authored-By: Claude Sonnet 4.6 --- bun.lockb | Bin 185911 -> 200410 bytes package.json | 1 + src/app/api/[[...slugs]]/_lib/img-del.ts | 13 ++---- src/app/api/[[...slugs]]/_lib/img.ts | 41 +++++++----------- src/app/api/[[...slugs]]/_lib/imgs.ts | 30 ++++++------- .../api/[[...slugs]]/_lib/upl-img-single.ts | 13 +++--- src/app/api/[[...slugs]]/_lib/upl-img.ts | 37 +++++----------- src/app/api/[[...slugs]]/route.ts | 30 ++----------- src/lib/minio.ts | 12 +++++ 9 files changed, 70 insertions(+), 107 deletions(-) create mode 100644 src/lib/minio.ts diff --git a/bun.lockb b/bun.lockb index 624c5ecf1cbb2404ade1e52a883f53d9b7f711c4..2d40424d903909f4374584011922fac963a8c841 100755 GIT binary patch delta 41425 zcmeIb2UJu^*Dl=W2-=OHv=J0gjEFW8B&jH76cak;2nd3b1XM6JW=vx^YN=xmV;bX_ z)9C1o7{{!b)0lI1O!wL6R6(ON@B97hzxS?n*P32F>{Cze+O=y})jom7v-PKf7w6ed zaX01D>2w{}{djiv{Ht?rJAYr`j$ga91zXGRu3%hc+vU!-u&m+VMK&u$S~}gIQ#+KA z-#^)q)-j(sJ~kmX5nNh)oOhoToz7TUr?b)NGE&0RRNd5=q~8gW;@S|BygE}ybHju(c{_@?ONK0haT8ZAM}$cVWh>IGKfNpfYD3h6TTvmf5bG@RXk`P|qF|?x%bpVq1>g}|$ z0!i&gLsB=}P*3AfAS*&)n#BckbyK9qQKSaq;(h_7oM6L)l1hmDt!PA;4XNzBj}N%Q7QdXW8+eEQ7QfU zM1%Cy0%LQ)6qx@jG( z>ZVN7S2929t_?g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ogIdFI8 OUh}=dBB{Vu@_zu^m4od7 diff --git a/package.json b/package.json index d6976f97..2c8c3a0e 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "framer-motion": "^12.4.1", "get-port": "^7.1.0", "lodash": "^4.17.21", + "minio": "^8.0.7", "motion": "^12.4.1", "nanoid": "^5.1.0", "next": "15.1.6", diff --git a/src/app/api/[[...slugs]]/_lib/img-del.ts b/src/app/api/[[...slugs]]/_lib/img-del.ts index 22b0c7f2..641e8653 100644 --- a/src/app/api/[[...slugs]]/_lib/img-del.ts +++ b/src/app/api/[[...slugs]]/_lib/img-del.ts @@ -1,15 +1,8 @@ -import fs from "fs/promises"; -import path from "path"; +import minio, { MINIO_BUCKET } from "@/lib/minio"; -async function imgDel({ - name, - UPLOAD_DIR_IMAGE, -}: { - name: string; - UPLOAD_DIR_IMAGE: string; -}) { +async function imgDel({ name }: { name: string }) { try { - await fs.unlink(path.join(UPLOAD_DIR_IMAGE, name)); + await minio.removeObject(MINIO_BUCKET, `image/${name}`); return "ok"; } catch (error) { console.log(error); diff --git a/src/app/api/[[...slugs]]/_lib/img.ts b/src/app/api/[[...slugs]]/_lib/img.ts index 4752afbf..e41bb4a7 100644 --- a/src/app/api/[[...slugs]]/_lib/img.ts +++ b/src/app/api/[[...slugs]]/_lib/img.ts @@ -1,27 +1,21 @@ -import fs from "fs/promises"; import path from "path"; +import fs from "fs/promises"; import sharp from "sharp"; +import minio, { MINIO_BUCKET } from "@/lib/minio"; async function img({ name, - UPLOAD_DIR_IMAGE, ROOT, size, }: { name: string; - UPLOAD_DIR_IMAGE: string; ROOT: string; - size?: number; // Ukuran opsional (tidak ada default) + size?: number; }) { - const completeName = path.basename(name); // Nama file lengkap - const ext = path.extname(name).toLowerCase(); // Ekstensi file dalam huruf kecil - // const fileNameWithoutExt = path.basename(name, ext); // Nama file tanpa ekstensi - - // Default image jika terjadi kesalahan const noImage = path.join(ROOT, "public/no-image.jpg"); + const ext = path.extname(name).toLowerCase(); - // Validasi ekstensi file - if (![".jpg", ".jpeg", ".png"].includes(ext)) { + if (![".jpg", ".jpeg", ".png", ".webp"].includes(ext)) { console.warn(`Ekstensi file tidak didukung: ${ext}`); return new Response(await fs.readFile(noImage), { headers: { "Content-Type": "image/jpeg" }, @@ -29,29 +23,26 @@ async function img({ } try { - // Path ke file asli - const filePath = path.join(UPLOAD_DIR_IMAGE, completeName); + const stream = await minio.getObject(MINIO_BUCKET, `image/${name}`); + const chunks: Buffer[] = []; + for await (const chunk of stream) { + chunks.push(Buffer.from(chunk)); + } + const buffer = Buffer.concat(chunks); - // Periksa apakah file ada - await fs.stat(filePath); - - // Metadata gambar asli - const metadata = await sharp(filePath).metadata(); - - // Proses resize menggunakan sharp - const resizedImageBuffer = await sharp(filePath) - .resize(size || metadata.width) // Gunakan size jika diberikan, jika tidak gunakan width asli + const metadata = await sharp(buffer).metadata(); + const resized = await sharp(buffer) + .resize(size || metadata.width) .toBuffer(); - return new Response(resizedImageBuffer, { + return new Response(resized, { headers: { "Cache-Control": "public, max-age=3600, stale-while-revalidate=600", "Content-Type": "image/jpeg", }, }); } catch (error) { - console.error(`Gagal memproses file: ${name}`, error); - // Jika file tidak ditemukan atau gagal diproses, kembalikan default image + console.error(`Gagal mengambil file dari MinIO: ${name}`, error); return new Response(await fs.readFile(noImage), { headers: { "Content-Type": "image/jpeg" }, }); diff --git a/src/app/api/[[...slugs]]/_lib/imgs.ts b/src/app/api/[[...slugs]]/_lib/imgs.ts index 5b3470f7..fdd439a9 100644 --- a/src/app/api/[[...slugs]]/_lib/imgs.ts +++ b/src/app/api/[[...slugs]]/_lib/imgs.ts @@ -1,30 +1,30 @@ -import fs from "fs/promises"; +import minio, { MINIO_BUCKET } from "@/lib/minio"; async function imgs({ search = "", page = 1, count = 20, - UPLOAD_DIR_IMAGE, }: { search?: string; page?: number; count?: number; - UPLOAD_DIR_IMAGE: string; }) { - const files = await fs.readdir(UPLOAD_DIR_IMAGE); + const objects: { name: string; url: string }[] = []; - return files - .filter( - (file) => - file.endsWith(".jpg") || file.endsWith(".png") || file.endsWith(".jpeg") - ) - .filter((file) => file.includes(search)) + const stream = minio.listObjects(MINIO_BUCKET, "image/", true); + + for await (const obj of stream) { + if (!obj.name) continue; + const fileName = obj.name.replace("image/", ""); + if (!fileName) continue; + if (search && !fileName.includes(search)) continue; + objects.push({ name: fileName, url: `/api/img/${fileName}` }); + } + + const total = objects.length; + return objects .slice((page - 1) * count, page * count) - .map((file) => ({ - name: file, - url: `/api/img/${file}`, - total: files.length, - })); + .map((o) => ({ ...o, total })); } export default imgs; diff --git a/src/app/api/[[...slugs]]/_lib/upl-img-single.ts b/src/app/api/[[...slugs]]/_lib/upl-img-single.ts index a8d7c7a2..a4ef65da 100644 --- a/src/app/api/[[...slugs]]/_lib/upl-img-single.ts +++ b/src/app/api/[[...slugs]]/_lib/upl-img-single.ts @@ -1,30 +1,31 @@ import { nanoid } from "nanoid"; -import fs from "fs/promises"; import path from "path"; import _ from "lodash"; +import minio, { MINIO_BUCKET } from "@/lib/minio"; export async function uplImgSingle({ fileName, file, - UPLOAD_DIR_IMAGE, }: { fileName: string; file: File; - UPLOAD_DIR_IMAGE: string; }) { if (!fileName || typeof fileName !== "string" || fileName.trim() === "") { console.warn(`Nama file tidak valid: ${fileName}`); fileName = nanoid() + ".jpg"; } + const ext = path.extname(fileName).toLowerCase(); const fileNameWithoutExt = path.basename(fileName, ext); const fileNameKebabCase = _.kebabCase(fileNameWithoutExt) + ext; + const objectName = `image/${fileNameKebabCase}`; try { const buffer = Buffer.from(await file.arrayBuffer()); - const filePath = path.join(UPLOAD_DIR_IMAGE, fileNameKebabCase); - await fs.writeFile(filePath, buffer); - return filePath; + await minio.putObject(MINIO_BUCKET, objectName, buffer, buffer.length, { + "Content-Type": file.type || "image/jpeg", + }); + return objectName; } catch (error) { console.log(error); return "error"; diff --git a/src/app/api/[[...slugs]]/_lib/upl-img.ts b/src/app/api/[[...slugs]]/_lib/upl-img.ts index 9fdf482e..de519f4f 100644 --- a/src/app/api/[[...slugs]]/_lib/upl-img.ts +++ b/src/app/api/[[...slugs]]/_lib/upl-img.ts @@ -1,15 +1,11 @@ -import path from "path"; -import fs from "fs/promises"; import { nanoid } from "nanoid"; +import minio, { MINIO_BUCKET } from "@/lib/minio"; -async function uplImg({ - files, - UPLOAD_DIR_IMAGE, -}: { - files: File[]; - UPLOAD_DIR_IMAGE: string; -}) { - // Validasi input +function sanitizeFileName(fileName: string): string { + return fileName.replace(/[^a-zA-Z0-9._\-]/g, "_"); +} + +async function uplImg({ files }: { files: File[] }) { if (!Array.isArray(files) || files.length === 0) { throw new Error("Tidak ada file yang diunggah"); } @@ -17,24 +13,20 @@ async function uplImg({ for (const file of files) { let fileName = file.name; - // Validasi nama file if (!fileName || typeof fileName !== "string" || fileName.trim() === "") { console.warn(`Nama file tidak valid: ${fileName}`); fileName = nanoid() + ".jpg"; } - // Sanitasi nama file untuk mencegah path traversal - const sanitizedFileName = sanitizeFileName(fileName); + const sanitized = sanitizeFileName(fileName); + const objectName = `image/${sanitized}`; try { - // Konversi file ke buffer const buffer = Buffer.from(await file.arrayBuffer()); - - // Tulis file ke direktori uploads - const filePath = path.join(UPLOAD_DIR_IMAGE, sanitizedFileName); - await fs.writeFile(filePath, buffer); - - console.log(`File berhasil diunggah: ${sanitizedFileName}`); + await minio.putObject(MINIO_BUCKET, objectName, buffer, buffer.length, { + "Content-Type": file.type || "image/jpeg", + }); + console.log(`File berhasil diunggah ke MinIO: ${objectName}`); } catch (error) { console.error(`Gagal mengunggah file ${fileName}:`, error); throw new Error(`Gagal mengunggah file: ${fileName}`); @@ -44,9 +36,4 @@ async function uplImg({ return "ok"; } -// Fungsi untuk membersihkan nama file dari karakter yang tidak aman -function sanitizeFileName(fileName: string): string { - return fileName.replace(/[^a-zA-Z0-9._\-]/g, "_"); -} - export default uplImg; diff --git a/src/app/api/[[...slugs]]/route.ts b/src/app/api/[[...slugs]]/route.ts index a84cb826..e8ffd1a2 100644 --- a/src/app/api/[[...slugs]]/route.ts +++ b/src/app/api/[[...slugs]]/route.ts @@ -4,32 +4,15 @@ import swagger from "@elysiajs/swagger"; import { Elysia, t } from "elysia"; import getPotensi from "./_lib/get-potensi"; import img from "./_lib/img"; -import fs from "fs/promises"; -import path from "path"; import uplImg from "./_lib/upl-img"; import imgs from "./_lib/imgs"; import uplCsv from "./_lib/upl-csv"; import imgDel from "./_lib/img-del"; import { uplImgSingle } from "./_lib/upl-img-single"; import { uplCsvSingle } from "./_lib/upl-csv-single"; + const ROOT = process.cwd(); -if (!process.env.WIBU_UPLOAD_DIR) - throw new Error("WIBU_UPLOAD_DIR is not defined"); - -const UPLOAD_DIR = path.join(ROOT, process.env.WIBU_UPLOAD_DIR); -const UPLOAD_DIR_IMAGE = path.join(UPLOAD_DIR, "image"); - -// create uploads dir -fs.mkdir(UPLOAD_DIR, { - recursive: true, -}).catch(() => {}); - -// create image uploads dir -fs.mkdir(UPLOAD_DIR_IMAGE, { - recursive: true, -}).catch(() => {}); - const corsConfig = { origin: "*", methods: ["GET", "POST", "PATCH", "DELETE", "PUT"] as HTTPMethod[], @@ -43,6 +26,7 @@ async function layanan() { const data = await prisma.layanan.findMany(); return { data }; } + const ApiServer = new Elysia() .use(swagger({ path: "/api/docs" })) .use(cors(corsConfig)) @@ -63,7 +47,6 @@ const ApiServer = new Elysia() ({ params, query }) => { return img({ name: params.name, - UPLOAD_DIR_IMAGE, ROOT, size: query.size, }); @@ -82,10 +65,7 @@ const ApiServer = new Elysia() .delete( "/img/:name", ({ params }) => { - return imgDel({ - name: params.name, - UPLOAD_DIR_IMAGE, - }); + return imgDel({ name: params.name }); }, { params: t.Object({ @@ -100,7 +80,6 @@ const ApiServer = new Elysia() search: query.search, page: query.page, count: query.count, - UPLOAD_DIR_IMAGE, }); }, { @@ -117,7 +96,7 @@ const ApiServer = new Elysia() "/upl-img", ({ body }) => { console.log(body.title); - return uplImg({ files: body.files, UPLOAD_DIR_IMAGE }); + return uplImg({ files: body.files }); }, { body: t.Object({ @@ -132,7 +111,6 @@ const ApiServer = new Elysia() return uplImgSingle({ fileName: body.name, file: body.file, - UPLOAD_DIR_IMAGE, }); }, { diff --git a/src/lib/minio.ts b/src/lib/minio.ts new file mode 100644 index 00000000..32712102 --- /dev/null +++ b/src/lib/minio.ts @@ -0,0 +1,12 @@ +import { Client } from "minio"; + +const minioClient = new Client({ + endPoint: process.env.MINIO_ENDPOINT!, + accessKey: process.env.MINIO_ACCESS_KEY!, + secretKey: process.env.MINIO_SECRET_KEY!, + useSSL: process.env.MINIO_USE_SSL === "true", +}); + +export const MINIO_BUCKET = process.env.MINIO_BUCKET!; + +export default minioClient; From fec6b797431de1b47eb3af5713ecf7478f645b1c Mon Sep 17 00:00:00 2001 From: nico Date: Thu, 23 Apr 2026 12:06:40 +0800 Subject: [PATCH 2/4] =?UTF-8?q?feat(storage):=20add=20Seafile=E2=86=92MinI?= =?UTF-8?q?O=20migration=20script=20and=20asset=20manifest?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - migrate-seafile-to-minio.ts: downloads 80 assets from Seafile public share and re-uploads to MinIO with identical filenames (idempotent, skips existing objects) - file-storage.json: asset manifest with names and Seafile download URLs used as migration source Co-Authored-By: Claude Sonnet 4.6 --- prisma/data/file-storage.json | 406 +++++++++++++++++++++++++++++ prisma/migrate-seafile-to-minio.ts | 97 +++++++ 2 files changed, 503 insertions(+) create mode 100644 prisma/data/file-storage.json create mode 100644 prisma/migrate-seafile-to-minio.ts diff --git a/prisma/data/file-storage.json b/prisma/data/file-storage.json new file mode 100644 index 00000000..2f5267dd --- /dev/null +++ b/prisma/data/file-storage.json @@ -0,0 +1,406 @@ +[ + { + "name": "42RCCpBZla4ZWxXcwx7kG-desktop.webp", + "path": "image/42RCCpBZla4ZWxXcwx7kG-desktop.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/d05a9e22-feac-4955-b1a2-75faad37f0ac/42RCCpBZla4ZWxXcwx7kG-desktop.webp", + "mimeType": "image/webp", + "link": "/api/fileStorage/findUnique/Gc79mlIlGuoRQuTqskFj--desktop.webp", + "category": "image" + + }, + { + "name": "42RCCpBZla4ZWxXcwx7kG-mobile.webp", + "path": "image/42RCCpBZla4ZWxXcwx7kG-mobile.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/c91212b5-7408-4ec9-b7c0-6c0fde2a9fc5/42RCCpBZla4ZWxXcwx7kG-mobile.webp" + }, + { + "name": "6DQbAvn0St-xHdPGW3vpY-desktop.webp", + "path": "image/6DQbAvn0St-xHdPGW3vpY-desktop.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/68cc521e-05e5-4258-af8d-c87fb76c927e/6DQbAvn0St-xHdPGW3vpY-desktop.webp" + }, + { + "name": "6DQbAvn0St-xHdPGW3vpY-mobile.webp", + "path": "image/6DQbAvn0St-xHdPGW3vpY-mobile.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/15f7ddd6-448c-4e4a-9b24-0bdc4bce5ce1/6DQbAvn0St-xHdPGW3vpY-mobile.webp" + }, + { + "name": "buku1 (1).jpeg", + "path": "image/buku1 (1).jpeg", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/d72b02a6-91f5-4d64-9729-521b306328d3/buku1%20%281%29.jpeg" + }, + { + "name": "buku1.jpeg", + "path": "image/buku1.jpeg", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/912bd7e5-be8a-4c19-8ab8-df6114a38864/buku1.jpeg" + }, + { + "name": "buku6.jpg", + "path": "image/buku6.jpg", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/ea56bc7c-094b-464e-859a-6c65bf65361d/buku6.jpg" + }, + { + "name": "c7xWNyoYp8Cak28NG5NoG-desktop.webp", + "path": "image/c7xWNyoYp8Cak28NG5NoG-desktop.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/d84fb066-4352-44f0-b7bc-5d8c5b8ffb61/c7xWNyoYp8Cak28NG5NoG-desktop.webp" + }, + { + "name": "c7xWNyoYp8Cak28NG5NoG-mobile.webp", + "path": "image/c7xWNyoYp8Cak28NG5NoG-mobile.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/9fb1c742-9a80-4788-9c73-9d06108e0051/c7xWNyoYp8Cak28NG5NoG-mobile.webp" + }, + { + "name": "cg78Sb_QzZFlli9s2FPVc-mobile.webp", + "path": "image/cg78Sb_QzZFlli9s2FPVc-mobile.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/c5a2cd18-806d-4dcb-b5c5-b0c6bcef7f35/cg78Sb_QzZFlli9s2FPVc-mobile.webp" + }, + { + "name": "d3v1AgLoSJhf5xvmmO3oP-mobile.webp", + "path": "image/d3v1AgLoSJhf5xvmmO3oP-mobile.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/ae72c51f-9df7-4b07-9fd5-e945c775d9ab/d3v1AgLoSJhf5xvmmO3oP-mobile.webp" + }, + { + "name": "d6hJgycQawWN3VEcHaqtR-desktop.webp", + "path": "image/d6hJgycQawWN3VEcHaqtR-desktop.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/4e5b9387-67b5-4c00-8f80-95ec6c54ff4a/d6hJgycQawWN3VEcHaqtR-desktop.webp" + }, + { + "name": "d6hJgycQawWN3VEcHaqtR-mobile.webp", + "path": "image/d6hJgycQawWN3VEcHaqtR-mobile.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/011f65c9-4273-43e8-b6d7-ce7a5319ae83/d6hJgycQawWN3VEcHaqtR-mobile.webp" + }, + { + "name": "DyX82oztXbHfu6HEvbrpt-desktop.webp", + "path": "image/DyX82oztXbHfu6HEvbrpt-desktop.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/b715dce5-1606-44cf-976f-57d8142e218e/DyX82oztXbHfu6HEvbrpt-desktop.webp" + }, + { + "name": "DyX82oztXbHfu6HEvbrpt-mobile.webp", + "path": "image/DyX82oztXbHfu6HEvbrpt-mobile.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/d0ff5925-ec84-4100-920c-93e2eb479f13/DyX82oztXbHfu6HEvbrpt-mobile.webp" + }, + { + "name": "EcQIGOF6LW1dIKE53vmba-desktop.webp", + "path": "image/EcQIGOF6LW1dIKE53vmba-desktop.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/7a97403e-9d6c-4a00-9c54-d5add0bd5915/EcQIGOF6LW1dIKE53vmba-desktop.webp" + }, + { + "name": "EcQIGOF6LW1dIKE53vmba-mobile.webp", + "path": "image/EcQIGOF6LW1dIKE53vmba-mobile.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/7e85b8e8-27f5-46c7-b4fc-590d66eef2ce/EcQIGOF6LW1dIKE53vmba-mobile.webp" + }, + { + "name": "Ez-SkRyf_F-1gksz_amNg-desktop.webp", + "path": "image/Ez-SkRyf_F-1gksz_amNg-desktop.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/c16de343-1297-4248-b104-83b3e3605f32/Ez-SkRyf_F-1gksz_amNg-desktop.webp" + }, + { + "name": "Ez-SkRyf_F-1gksz_amNg-mobile.webp", + "path": "image/Ez-SkRyf_F-1gksz_amNg-mobile.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/ece148ca-8aa1-43ef-a8de-ea0bde0a315a/Ez-SkRyf_F-1gksz_amNg-mobile.webp" + }, + { + "name": "g4ICsRrmOaIqS_yqlQLZK-desktop.webp", + "path": "image/g4ICsRrmOaIqS_yqlQLZK-desktop.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/31280b01-6cdb-4d96-9c96-0eecec6a238c/g4ICsRrmOaIqS_yqlQLZK-desktop.webp" + }, + { + "name": "g4ICsRrmOaIqS_yqlQLZK-mobile.webp", + "path": "image/g4ICsRrmOaIqS_yqlQLZK-mobile.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/af7f3e11-1f63-4307-88e9-64382a949279/g4ICsRrmOaIqS_yqlQLZK-mobile.webp" + }, + { + "name": "Gc79mlIlGuoRQuTqskFj--desktop.webp", + "path": "image/Gc79mlIlGuoRQuTqskFj--desktop.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/05214122-51bb-4fba-9b7c-f69e072d8a0d/Gc79mlIlGuoRQuTqskFj--desktop.webp" + }, + { + "name": "Gc79mlIlGuoRQuTqskFj--mobile.webp", + "path": "image/Gc79mlIlGuoRQuTqskFj--mobile.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/d49ab5d2-7087-4088-8e59-51f116f21e27/Gc79mlIlGuoRQuTqskFj--mobile.webp" + }, + { + "name": "Gi8EX3pBmT719AfzXirDS-desktop.webp", + "path": "image/Gi8EX3pBmT719AfzXirDS-desktop.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/4b456bad-228a-4211-a1bb-431dc081ecc7/Gi8EX3pBmT719AfzXirDS-desktop.webp" + }, + { + "name": "Gi8EX3pBmT719AfzXirDS-mobile.webp", + "path": "image/Gi8EX3pBmT719AfzXirDS-mobile.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/68308100-d468-4e53-9cc6-3aa12035c8ab/Gi8EX3pBmT719AfzXirDS-mobile.webp" + }, + { + "name": "gyNi4s8TnK2UrViU-gN2C-desktop.webp", + "path": "image/gyNi4s8TnK2UrViU-gN2C-desktop.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/539debe4-f3fc-4574-a256-ac8c8dbf5a00/gyNi4s8TnK2UrViU-gN2C-desktop.webp" + }, + { + "name": "gyNi4s8TnK2UrViU-gN2C-mobile.webp", + "path": "image/gyNi4s8TnK2UrViU-gN2C-mobile.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/4971a22a-c0dd-4492-bff5-a8aa3e93f27f/gyNi4s8TnK2UrViU-gN2C-mobile.webp" + }, + { + "name": "h_Gd0SoeIJVTi_5TWUO-P-desktop.webp", + "path": "image/h_Gd0SoeIJVTi_5TWUO-P-desktop.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/8409886e-c01b-421a-ac44-6d3a4bfd0985/h_Gd0SoeIJVTi_5TWUO-P-desktop.webp" + }, + { + "name": "h_Gd0SoeIJVTi_5TWUO-P-mobile.webp", + "path": "image/h_Gd0SoeIJVTi_5TWUO-P-mobile.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/f4a5280d-bd2d-4c5a-8040-183f9e5d951b/h_Gd0SoeIJVTi_5TWUO-P-mobile.webp" + }, + { + "name": "hLeF0GRFZqDUngZnDMAAk-desktop.webp", + "path": "image/hLeF0GRFZqDUngZnDMAAk-desktop.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/6b33097e-8d9d-4864-964b-6dc49b62b4ae/hLeF0GRFZqDUngZnDMAAk-desktop.webp" + }, + { + "name": "hLeF0GRFZqDUngZnDMAAk-mobile.webp", + "path": "image/hLeF0GRFZqDUngZnDMAAk-mobile.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/7dff816b-65bb-429c-b87e-3ff892d547dc/hLeF0GRFZqDUngZnDMAAk-mobile.webp" + }, + { + "name": "hsHiD59dZQxr8G2SAfUYp-mobile.webp", + "path": "image/hsHiD59dZQxr8G2SAfUYp-mobile.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/55103cd4-6f57-491d-bd41-03c0068974ef/hsHiD59dZQxr8G2SAfUYp-mobile.webp" + }, + { + "name": "hyyTFi8EApjzFEZ9EvJgB-desktop.webp", + "path": "image/hyyTFi8EApjzFEZ9EvJgB-desktop.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/0ec4a67e-695e-4524-bf22-f823b80c7e6b/hyyTFi8EApjzFEZ9EvJgB-desktop.webp" + }, + { + "name": "hyyTFi8EApjzFEZ9EvJgB-mobile.webp", + "path": "image/hyyTFi8EApjzFEZ9EvJgB-mobile.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/c982541e-f8b2-455a-a3cd-f856cd954bed/hyyTFi8EApjzFEZ9EvJgB-mobile.webp" + }, + { + "name": "isTT2LmPbeOWD5wAdqleX-mobile.webp", + "path": "image/isTT2LmPbeOWD5wAdqleX-mobile.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/ef6f8237-0803-422a-83af-4daca61c7065/isTT2LmPbeOWD5wAdqleX-mobile.webp" + }, + { + "name": "JhJigMo269K1TFGzSB1OS-desktop.webp", + "path": "image/JhJigMo269K1TFGzSB1OS-desktop.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/668d2f32-3277-4842-8a01-c3cb5ca0852b/JhJigMo269K1TFGzSB1OS-desktop.webp" + }, + { + "name": "JhJigMo269K1TFGzSB1OS-mobile.webp", + "path": "image/JhJigMo269K1TFGzSB1OS-mobile.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/df8c52a3-189a-48a0-b7e7-98efe2479414/JhJigMo269K1TFGzSB1OS-mobile.webp" + }, + { + "name": "jYxEXspWH5g6eTTVqK72c-desktop.webp", + "path": "image/jYxEXspWH5g6eTTVqK72c-desktop.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/a13572b4-2e22-4d76-8826-64a8e6ae4e13/jYxEXspWH5g6eTTVqK72c-desktop.webp" + }, + { + "name": "jYxEXspWH5g6eTTVqK72c-mobile.webp", + "path": "image/jYxEXspWH5g6eTTVqK72c-mobile.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/55f171fa-585f-4a94-bfeb-d2bad2f7ee39/jYxEXspWH5g6eTTVqK72c-mobile.webp" + }, + { + "name": "K0wY911212dinYA3AFB_f-desktop.webp", + "path": "image/K0wY911212dinYA3AFB_f-desktop.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/31ea22bf-9ce1-4dc6-b901-caaec86c35c4/K0wY911212dinYA3AFB_f-desktop.webp" + }, + { + "name": "K0wY911212dinYA3AFB_f-mobile.webp", + "path": "image/K0wY911212dinYA3AFB_f-mobile.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/ea061aa6-7e5e-447c-bec8-be1d927cc578/K0wY911212dinYA3AFB_f-mobile.webp" + }, + { + "name": "l4qsUEw2JiclGAkkrXp9g-desktop.webp", + "path": "image/l4qsUEw2JiclGAkkrXp9g-desktop.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/05088eb1-44bc-44d6-9e67-08dd6bca00ae/l4qsUEw2JiclGAkkrXp9g-desktop.webp" + }, + { + "name": "l4qsUEw2JiclGAkkrXp9g-mobile.webp", + "path": "image/l4qsUEw2JiclGAkkrXp9g-mobile.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/cf411a77-b7fc-4ac7-a98d-f9f89bc27e85/l4qsUEw2JiclGAkkrXp9g-mobile.webp" + }, + { + "name": "M9QlgVKIEfCdY3g4F_tRZ-desktop.webp", + "path": "image/M9QlgVKIEfCdY3g4F_tRZ-desktop.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/dfa58064-c17b-453a-b0a1-613109757844/M9QlgVKIEfCdY3g4F_tRZ-desktop.webp" + }, + { + "name": "M9QlgVKIEfCdY3g4F_tRZ-mobile.webp", + "path": "image/M9QlgVKIEfCdY3g4F_tRZ-mobile.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/4be366ca-1a39-46e9-adf2-d1d28fd83961/M9QlgVKIEfCdY3g4F_tRZ-mobile.webp" + }, + { + "name": "mtQsaKtQnhxIYVIooCkiQ-desktop.webp", + "path": "image/mtQsaKtQnhxIYVIooCkiQ-desktop.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/5015a484-ac9a-485f-9fb0-a29e3824a6ce/mtQsaKtQnhxIYVIooCkiQ-desktop.webp" + }, + { + "name": "mtQsaKtQnhxIYVIooCkiQ-mobile.webp", + "path": "image/mtQsaKtQnhxIYVIooCkiQ-mobile.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/10ddd132-5b85-4a8f-b129-56a10540fc8c/mtQsaKtQnhxIYVIooCkiQ-mobile.webp" + }, + { + "name": "NBPAqjPXn7GQmYTDBI5hu-desktop.webp", + "path": "image/NBPAqjPXn7GQmYTDBI5hu-desktop.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/fd8cfea3-5cf2-489e-9f21-e7985335dc98/NBPAqjPXn7GQmYTDBI5hu-desktop.webp" + }, + { + "name": "NBPAqjPXn7GQmYTDBI5hu-mobile.webp", + "path": "image/NBPAqjPXn7GQmYTDBI5hu-mobile.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/f5b02049-95db-4e1b-8bfd-b1a4c431ee49/NBPAqjPXn7GQmYTDBI5hu-mobile.webp" + }, + { + "name": "NyPGo-1AtfNm5wkAq7Om6-mobile.webp", + "path": "image/NyPGo-1AtfNm5wkAq7Om6-mobile.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/b7361eb8-37e8-4baa-a6d6-01b6131dd788/NyPGo-1AtfNm5wkAq7Om6-mobile.webp" + }, + { + "name": "OsMY3AYPyGC_CoN1xUjOn-desktop.webp", + "path": "image/OsMY3AYPyGC_CoN1xUjOn-desktop.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/509a3603-5d11-4857-baa5-d439da43825a/OsMY3AYPyGC_CoN1xUjOn-desktop.webp" + }, + { + "name": "OsMY3AYPyGC_CoN1xUjOn-mobile.webp", + "path": "image/OsMY3AYPyGC_CoN1xUjOn-mobile.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/cbe9798a-4cf0-45f7-b041-70269490128b/OsMY3AYPyGC_CoN1xUjOn-mobile.webp" + }, + { + "name": "pps1ZgzJxDb4VZxEvtZeu-desktop.webp", + "path": "image/pps1ZgzJxDb4VZxEvtZeu-desktop.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/500fa1f3-d412-4f48-bc5f-465b91149c6e/pps1ZgzJxDb4VZxEvtZeu-desktop.webp" + }, + { + "name": "pps1ZgzJxDb4VZxEvtZeu-mobile.webp", + "path": "image/pps1ZgzJxDb4VZxEvtZeu-mobile.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/19c2b1a6-8c9b-4be9-981c-72d7a3ab6e38/pps1ZgzJxDb4VZxEvtZeu-mobile.webp" + }, + { + "name": "r_gBF0FuFpFPfSENHc4XI-desktop.webp", + "path": "image/r_gBF0FuFpFPfSENHc4XI-desktop.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/2e4ab451-df52-4f04-8af0-db2e789e58bb/r_gBF0FuFpFPfSENHc4XI-desktop.webp" + }, + { + "name": "r_gBF0FuFpFPfSENHc4XI-mobile.webp", + "path": "image/r_gBF0FuFpFPfSENHc4XI-mobile.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/1e2e8884-9da3-4610-9c57-8925740d4128/r_gBF0FuFpFPfSENHc4XI-mobile.webp" + }, + { + "name": "SQqSobKRg3ShvgPw_H41h-desktop.webp", + "path": "image/SQqSobKRg3ShvgPw_H41h-desktop.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/4360cb84-f82a-4a68-afd3-65decd912f30/SQqSobKRg3ShvgPw_H41h-desktop.webp" + }, + { + "name": "SQqSobKRg3ShvgPw_H41h-mobile.webp", + "path": "image/SQqSobKRg3ShvgPw_H41h-mobile.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/c808dff8-2e8a-4358-af03-4a838c9a6d6c/SQqSobKRg3ShvgPw_H41h-mobile.webp" + }, + { + "name": "TDQReg1lQ73s39crXW0ra-desktop.webp", + "path": "image/TDQReg1lQ73s39crXW0ra-desktop.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/04d15638-31ed-440f-9fa0-bb30d71bbc59/TDQReg1lQ73s39crXW0ra-desktop.webp" + }, + { + "name": "TDQReg1lQ73s39crXW0ra-mobile.webp", + "path": "image/TDQReg1lQ73s39crXW0ra-mobile.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/da174313-329c-4156-88e2-fc929325dfff/TDQReg1lQ73s39crXW0ra-mobile.webp" + }, + { + "name": "TTur8BttDlAS9UgZVe3M8-desktop.webp", + "path": "image/TTur8BttDlAS9UgZVe3M8-desktop.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/32fe30ab-0d7b-4ada-8d5d-993baf23545c/TTur8BttDlAS9UgZVe3M8-desktop.webp" + }, + { + "name": "TTur8BttDlAS9UgZVe3M8-mobile.webp", + "path": "image/TTur8BttDlAS9UgZVe3M8-mobile.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/85c5ecb0-2fb5-4431-af11-0c851e52de4e/TTur8BttDlAS9UgZVe3M8-mobile.webp" + }, + { + "name": "TWdNTZZbTOhFTNJGGPDyG-desktop.webp", + "path": "image/TWdNTZZbTOhFTNJGGPDyG-desktop.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/d606d946-fdf9-41b9-b0bd-1421b2ec6843/TWdNTZZbTOhFTNJGGPDyG-desktop.webp" + }, + { + "name": "TWdNTZZbTOhFTNJGGPDyG-mobile.webp", + "path": "image/TWdNTZZbTOhFTNJGGPDyG-mobile.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/46859e6a-ebfc-4124-adfe-320953256fe5/TWdNTZZbTOhFTNJGGPDyG-mobile.webp" + }, + { + "name": "TXknK9CSRSxwvM2hPW6BO-desktop.webp", + "path": "image/TXknK9CSRSxwvM2hPW6BO-desktop.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/af38b038-0d38-4222-be29-09cb81054ce7/TXknK9CSRSxwvM2hPW6BO-desktop.webp" + }, + { + "name": "TXknK9CSRSxwvM2hPW6BO-mobile.webp", + "path": "image/TXknK9CSRSxwvM2hPW6BO-mobile.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/eab1c384-aafa-438f-ac0f-003ddd51c9a5/TXknK9CSRSxwvM2hPW6BO-mobile.webp" + }, + { + "name": "U7rePDZq5E59z-Eo9tLBe-desktop.webp", + "path": "image/U7rePDZq5E59z-Eo9tLBe-desktop.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/a2858ed9-8bb6-47cd-9e1b-831928a0389f/U7rePDZq5E59z-Eo9tLBe-desktop.webp" + }, + { + "name": "U7rePDZq5E59z-Eo9tLBe-mobile.webp", + "path": "image/U7rePDZq5E59z-Eo9tLBe-mobile.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/1f4a189d-d312-46ef-a68c-c0c7261860d0/U7rePDZq5E59z-Eo9tLBe-mobile.webp" + }, + { + "name": "uDxAalFV0qRv_RrW9flM8-mobile.webp", + "path": "image/uDxAalFV0qRv_RrW9flM8-mobile.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/5f006c3c-47f5-4e48-8bdd-7fbe005bf810/uDxAalFV0qRv_RrW9flM8-mobile.webp" + }, + { + "name": "uE2QwpbcXyBWxVYqCWQQT-desktop.webp", + "path": "image/uE2QwpbcXyBWxVYqCWQQT-desktop.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/edf73617-214b-44df-960a-dd68f0bad97a/uE2QwpbcXyBWxVYqCWQQT-desktop.webp" + }, + { + "name": "uE2QwpbcXyBWxVYqCWQQT-mobile.webp", + "path": "image/uE2QwpbcXyBWxVYqCWQQT-mobile.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/d7f5d738-b18f-44c8-92bb-8e526f47d9ee/uE2QwpbcXyBWxVYqCWQQT-mobile.webp" + }, + { + "name": "v7Ac2xQvTiJy-HYh1AxF4-desktop.webp", + "path": "image/v7Ac2xQvTiJy-HYh1AxF4-desktop.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/3e1b8dd9-2bf5-4daf-9dd9-dd687e9b2f2c/v7Ac2xQvTiJy-HYh1AxF4-desktop.webp" + }, + { + "name": "v7Ac2xQvTiJy-HYh1AxF4-mobile.webp", + "path": "image/v7Ac2xQvTiJy-HYh1AxF4-mobile.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/44c78026-f802-46f3-8ec2-271f0f001f7a/v7Ac2xQvTiJy-HYh1AxF4-mobile.webp" + }, + { + "name": "wh79hF4HTZMEFtYc-OfZg-mobile.webp", + "path": "image/wh79hF4HTZMEFtYc-OfZg-mobile.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/b4b4378e-76ad-4b15-84cf-00178553b3d4/wh79hF4HTZMEFtYc-OfZg-mobile.webp" + }, + { + "name": "x0_-siY2V8IehBzo4_uph-desktop.webp", + "path": "image/x0_-siY2V8IehBzo4_uph-desktop.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/7f82bcea-e7c6-4cde-9701-8d3afe49c0f8/x0_-siY2V8IehBzo4_uph-desktop.webp" + }, + { + "name": "x0_-siY2V8IehBzo4_uph-mobile.webp", + "path": "image/x0_-siY2V8IehBzo4_uph-mobile.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/c4b23ebc-3915-4102-a25c-4e2f6da0d097/x0_-siY2V8IehBzo4_uph-mobile.webp" + }, + { + "name": "y78xZ2axTOjz87gRKjVAf-desktop.webp", + "path": "image/y78xZ2axTOjz87gRKjVAf-desktop.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/180d0c29-c93e-4bbe-b399-7e6a34fbeb49/y78xZ2axTOjz87gRKjVAf-desktop.webp" + }, + { + "name": "y78xZ2axTOjz87gRKjVAf-mobile.webp", + "path": "image/y78xZ2axTOjz87gRKjVAf-mobile.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/71b5091a-ebcd-4d4c-9aae-1b7e548051fc/y78xZ2axTOjz87gRKjVAf-mobile.webp" + }, + { + "name": "YdCBnK-bWxlyHjwsk4Qie-desktop.webp", + "path": "image/YdCBnK-bWxlyHjwsk4Qie-desktop.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/bf6f2e11-b328-4da1-bda7-81af2336d03f/YdCBnK-bWxlyHjwsk4Qie-desktop.webp" + }, + { + "name": "YdCBnK-bWxlyHjwsk4Qie-mobile.webp", + "path": "image/YdCBnK-bWxlyHjwsk4Qie-mobile.webp", + "downloadUrl": "https://cld-dkr-makuro-seafile.wibudev.com/seafhttp/files/9d7e5232-3b30-4ead-9482-1fed3a86245a/YdCBnK-bWxlyHjwsk4Qie-mobile.webp" + } +] diff --git a/prisma/migrate-seafile-to-minio.ts b/prisma/migrate-seafile-to-minio.ts new file mode 100644 index 00000000..1cadd3a4 --- /dev/null +++ b/prisma/migrate-seafile-to-minio.ts @@ -0,0 +1,97 @@ +/** + * Script migrasi: download semua file dari Seafile public share → upload ke MinIO + * Jalankan sekali: bun run prisma/migrate-seafile-to-minio.ts + */ +import { Client } from "minio"; +import fileStorageData from "./data/file-storage.json"; + +const SEAFILE_BASE_URL = "https://cld-dkr-makuro-seafile.wibudev.com"; +const SEAFILE_SHARE_TOKEN = "3a9a9ecb5e244f4da8ae"; + +const minio = new Client({ + endPoint: process.env.MINIO_ENDPOINT!, + accessKey: process.env.MINIO_ACCESS_KEY!, + secretKey: process.env.MINIO_SECRET_KEY!, + useSSL: process.env.MINIO_USE_SSL === "true", +}); + +const BUCKET = process.env.MINIO_BUCKET!; + +function buildSeafileUrl(fileName: string): string { + return `${SEAFILE_BASE_URL}/d/${SEAFILE_SHARE_TOKEN}/files/?p=${encodeURIComponent(fileName)}&raw=1`; +} + +function guessMimeType(fileName: string): string { + const ext = fileName.split(".").pop()?.toLowerCase(); + const map: Record = { + webp: "image/webp", + jpg: "image/jpeg", + jpeg: "image/jpeg", + png: "image/png", + gif: "image/gif", + }; + return map[ext ?? ""] ?? "application/octet-stream"; +} + +async function migrateFile(name: string): Promise<"ok" | "skip" | "error"> { + const objectName = `image/${name}`; + + // Cek apakah sudah ada di MinIO — skip jika sudah + try { + await minio.statObject(BUCKET, objectName); + console.log(` ⏭ sudah ada, skip: ${name}`); + return "skip"; + } catch { + // tidak ada, lanjut upload + } + + const seafileUrl = buildSeafileUrl(name); + + try { + const res = await fetch(seafileUrl); + if (!res.ok) { + console.error(` ✗ gagal download (HTTP ${res.status}): ${name}`); + return "error"; + } + + const buffer = Buffer.from(await res.arrayBuffer()); + await minio.putObject(BUCKET, objectName, buffer, buffer.length, { + "Content-Type": guessMimeType(name), + }); + + console.log(` ✓ ${name} (${(buffer.length / 1024).toFixed(1)} KB)`); + return "ok"; + } catch (err) { + console.error(` ✗ error: ${name}`, err); + return "error"; + } +} + +async function main() { + console.log(`\n🚀 Migrasi Seafile → MinIO`); + console.log(` Bucket : ${BUCKET}`); + console.log(` Total : ${fileStorageData.length} file\n`); + + let ok = 0, skip = 0, error = 0; + + for (const item of fileStorageData) { + const result = await migrateFile(item.name); + if (result === "ok") ok++; + else if (result === "skip") skip++; + else error++; + } + + console.log(`\n📊 Hasil:`); + console.log(` ✓ Berhasil : ${ok}`); + console.log(` ⏭ Dilewati : ${skip}`); + console.log(` ✗ Gagal : ${error}`); + + if (error > 0) { + console.log(`\n⚠️ Ada ${error} file yang gagal. Jalankan ulang script untuk retry.`); + process.exit(1); + } else { + console.log(`\n✅ Migrasi selesai!`); + } +} + +main(); From b9b00f0a208ac8c7f93de039613cb56c47d4d304 Mon Sep 17 00:00:00 2001 From: nico Date: Thu, 23 Apr 2026 12:11:55 +0800 Subject: [PATCH 3/4] docs(qc): add quality control summaries for various modules Added comprehensive QC reports and fix summaries for: - Desa (Berita, Potensi, Profil, Layanan, Penghargaan, Pengumuman) - Kesehatan (Posyandu) - Landing Page (APBDes, SDGS, Anti-Korupsi, Profil, Prestasi) - PPID (Daftar Informasi, Dasar Hukum, IKM, Permohonan, Struktur, Visi Misi) --- QC/DESA/fix-summary-berita-desa.md | 347 +++++ QC/DESA/fix-summary-potensi-desa.md | 442 +++++++ QC/DESA/fix-summary-profil-desa.md | 363 ++++++ QC/DESA/summary-qc-berita-desa.md | 622 +++++++++ QC/DESA/summary-qc-gallery-desa.md | 1122 +++++++++++++++++ QC/DESA/summary-qc-layanan-desa.md | 882 +++++++++++++ QC/DESA/summary-qc-penghargaan-desa.md | 774 ++++++++++++ QC/DESA/summary-qc-pengumuman-desa.md | 809 ++++++++++++ QC/DESA/summary-qc-potensi-desa.md | 658 ++++++++++ QC/DESA/summary-qc-profil-desa.md | 371 ++++++ QC/KESEHATAN/summary-qc-posyandu.md | 904 +++++++++++++ QC/Landing-Page/QC-APBDES-MODULE.md | 763 +++++++++++ QC/Landing-Page/QC-DESA-ANTI-KORUPSI.md | 639 ++++++++++ QC/Landing-Page/QC-PRESTASI-DESA-MODULE.md | 875 +++++++++++++ QC/Landing-Page/QC-PROFIL-MODULE.md | 488 +++++++ QC/Landing-Page/QC-SDGS-DESA.md | 651 ++++++++++ QC/PPID/QC-DAFTAR-INFORMASI-PUBLIK-MODULE.md | 879 +++++++++++++ QC/PPID/QC-DASAR-HUKUM-PPID-MODULE.md | 821 ++++++++++++ QC/PPID/QC-IKM-MODULE.md | 913 ++++++++++++++ .../QC-PERMOHONAN-INFORMASI-PUBLIK-MODULE.md | 844 +++++++++++++ ...C-PERMOHONAN-KEBERATAN-INFORMASI-MODULE.md | 771 +++++++++++ QC/PPID/QC-PPID-PROFIL-MODULE.md | 802 ++++++++++++ QC/PPID/QC-STRUKTUR-PPID-MODULE.md | 936 ++++++++++++++ QC/PPID/QC-VISI-MISI-PPID-MODULE.md | 797 ++++++++++++ 24 files changed, 17473 insertions(+) create mode 100644 QC/DESA/fix-summary-berita-desa.md create mode 100644 QC/DESA/fix-summary-potensi-desa.md create mode 100644 QC/DESA/fix-summary-profil-desa.md create mode 100644 QC/DESA/summary-qc-berita-desa.md create mode 100644 QC/DESA/summary-qc-gallery-desa.md create mode 100644 QC/DESA/summary-qc-layanan-desa.md create mode 100644 QC/DESA/summary-qc-penghargaan-desa.md create mode 100644 QC/DESA/summary-qc-pengumuman-desa.md create mode 100644 QC/DESA/summary-qc-potensi-desa.md create mode 100644 QC/DESA/summary-qc-profil-desa.md create mode 100644 QC/KESEHATAN/summary-qc-posyandu.md create mode 100644 QC/Landing-Page/QC-APBDES-MODULE.md create mode 100644 QC/Landing-Page/QC-DESA-ANTI-KORUPSI.md create mode 100644 QC/Landing-Page/QC-PRESTASI-DESA-MODULE.md create mode 100644 QC/Landing-Page/QC-PROFIL-MODULE.md create mode 100644 QC/Landing-Page/QC-SDGS-DESA.md create mode 100644 QC/PPID/QC-DAFTAR-INFORMASI-PUBLIK-MODULE.md create mode 100644 QC/PPID/QC-DASAR-HUKUM-PPID-MODULE.md create mode 100644 QC/PPID/QC-IKM-MODULE.md create mode 100644 QC/PPID/QC-PERMOHONAN-INFORMASI-PUBLIK-MODULE.md create mode 100644 QC/PPID/QC-PERMOHONAN-KEBERATAN-INFORMASI-MODULE.md create mode 100644 QC/PPID/QC-PPID-PROFIL-MODULE.md create mode 100644 QC/PPID/QC-STRUKTUR-PPID-MODULE.md create mode 100644 QC/PPID/QC-VISI-MISI-PPID-MODULE.md diff --git a/QC/DESA/fix-summary-berita-desa.md b/QC/DESA/fix-summary-berita-desa.md new file mode 100644 index 00000000..bed5b063 --- /dev/null +++ b/QC/DESA/fix-summary-berita-desa.md @@ -0,0 +1,347 @@ +# Fix Summary - Berita Desa High Priority Issues + +**Tanggal:** 25 Februari 2026 +**Status:** ✅ **ALL COMPLETED** + +--- + +## ✅ COMPLETED FIXES + +### 1. API - Delete Kategori dengan Relation Check ✅ FIXED + +**File:** `src/app/api/[[...slugs]]/_lib/desa/berita/kategori-berita/del.ts` + +**Changes:** +```typescript +// BEFORE +export default async function kategoriBeritaDelete(context: Context) { + const id = context.params.id as string; + + // ❌ Langsung delete tanpa cek relasi + await prisma.kategoriBerita.delete({ + where: { id }, + }); + + return { + status: 200, + success: true, + message: "Sukses Menghapus kategori berita", + }; +} + +// AFTER +export default async function kategoriBeritaDelete(context: Context) { + try { + const id = context.params?.id as string; + + if (!id) { + return Response.json({ + success: false, + message: "ID tidak boleh kosong", + }, { status: 400 }); + } + + // ✅ Cek apakah kategori masih digunakan oleh berita + const beritaCount = await prisma.berita.count({ + where: { + kategoriBeritaId: id, + isActive: true, + deletedAt: null, + }, + }); + + if (beritaCount > 0) { + return Response.json({ + success: false, + message: `Kategori tidak dapat dihapus karena masih digunakan oleh ${beritaCount} berita`, + }, { status: 400 }); + } + + // ✅ Soft delete (bukan hard delete) + await prisma.kategoriBerita.update({ + where: { id }, + data: { + deletedAt: new Date(), + isActive: false, + }, + }); + + return { + success: true, + message: "Kategori berita berhasil dihapus", + }; + } catch (error) { + console.error("Delete kategori error:", error); + return Response.json({ + success: false, + message: "Gagal menghapus kategori: " + (error instanceof Error ? error.message : 'Unknown error'), + }, { status: 500 }); + } +} +``` + +**Impact:** +- ✅ Tidak ada foreign key constraint error +- ✅ Data integrity terjaga - berita tidak kehilangan referensi kategori +- ✅ User feedback lebih baik (error message jelas dengan jumlah berita) +- ✅ Soft delete pattern konsisten (bukan hard delete) +- ✅ Error handling lebih robust dengan try-catch + +**Testing:** +```bash +# Test 1: Delete kategori yang masih digunakan (should fail) +DELETE /api/desa/berita/kategoriberita/del/{id} +# Expected: 400 Bad Request +# Response: { success: false, message: "Kategori tidak dapat dihapus karena masih digunakan oleh X berita" } + +# Test 2: Delete kategori yang tidak digunakan (should succeed) +DELETE /api/desa/berita/kategoriberita/del/{id} +# Expected: 200 OK +# Response: { success: true, message: "Kategori berita berhasil dihapus" } +``` + +--- + +### 2. UI - Search Parameter Hilang Saat Pagination ✅ FIXED + +**File:** `src/app/admin/(dashboard)/desa/berita/list-berita/page.tsx` + +**Changes:** +```typescript +// BEFORE (Line 189) + { + load(newPage, 10); // ❌ Missing search parameter + window.scrollTo({ top: 0, behavior: 'smooth' }); + }} + total={totalPages} + mt="md" + mb="md" + color="blue" + radius="md" +/> + +// AFTER (Line 189) + { + load(newPage, 10, debouncedSearch); // ✅ Include search parameter + window.scrollTo({ top: 0, behavior: 'smooth' }); + }} + total={totalPages} + mt="md" + mb="md" + color="blue" + radius="md" +/> +``` + +**Impact:** +- ✅ Search query tidak hilang saat ganti halaman +- ✅ UX significantly improved - user tidak perlu ketik ulang search +- ✅ Pagination dan search bekerja bersamaan dengan baik +- ✅ Consistent dengan best practices + +**Testing:** +``` +1. Buka halaman List Berita +2. Ketik search query (misal: "desa") +3. Tunggu hasil search muncul +4. Klik pagination halaman 2 +5. ✅ Verify: search query "desa" masih ada di search box +6. ✅ Verify: hasil di halaman 2 masih ter-filter dengan "desa" +7. ✅ Verify: URL parameter search tetap ada (jika ada) +``` + +**Note:** Function `load` sudah menerima parameter search dari state management: +```typescript +// State: src/app/admin/(dashboard)/_state/desa/berita.ts +async load(page = 1, limit = 10, search = '') { + // ... implementation sudah support search +} +``` + +--- + +### 3. UI - colSpan Tidak Sesuai Jumlah Kolom ✅ FIXED + +**File:** `src/app/admin/(dashboard)/desa/berita/kategori-berita/page.tsx` + +**Changes:** +```typescript +// BEFORE (Line 163) + + {/* ❌ colSpan 4, seharusnya 3 */} +
+ + Tidak ada data kategori berita yang cocok + +
+
+
+ +// AFTER (Line 163) + + {/* ✅ Match column count (3 columns) */} +
+ + Tidak ada data kategori berita yang cocok + +
+
+
+``` + +**Table Structure:** +```typescript + + + Nama {/* Column 1 */} + Edit {/* Column 2 */} + Hapus {/* Column 3 */} + + +``` + +**Impact:** +- ✅ Layout table rapi dan proporsional +- ✅ Empty state tidak terlalu lebar atau terlalu sempit +- ✅ Visual consistency maintained +- ✅ Professional appearance + +**Testing:** +``` +1. Buka halaman Kategori Berita +2. Pastikan tidak ada data (atau search dengan query yang tidak ada hasilnya) +3. ✅ Verify: Empty state message centered dengan baik +4. ✅ Verify: Empty state tidak terlalu lebar atau sempit +5. ✅ Verify: Table layout tetap rapi +``` + +--- + +## 📊 SUMMARY OF CHANGES + +| Issue | Status | File Changed | Impact | +|-------|--------|--------------|--------| +| 1. Delete Relation Check | ✅ Fixed | del.ts | Prevents data integrity issues | +| 2. Search in Pagination | ✅ Fixed | list-berita/page.tsx | UX significantly improved | +| 3. colSpan Mismatch | ✅ Fixed | kategori-berita/page.tsx | UI polish, consistency | + +**Total Files Modified:** 3 +- `src/app/api/[[...slugs]]/_lib/desa/berita/kategori-berita/del.ts` +- `src/app/admin/(dashboard)/desa/berita/list-berita/page.tsx` +- `src/app/admin/(dashboard)/desa/berita/kategori-berita/page.tsx` + +--- + +## 🧪 TESTING CHECKLIST + +### API Changes (Issue #1): +- [ ] Test delete kategori yang masih digunakan oleh 1 berita (should fail with message "masih digunakan oleh 1 berita") +- [ ] Test delete kategori yang masih digunakan oleh 5 berita (should fail with message "masih digunakan oleh 5 berita") +- [ ] Test delete kategori yang tidak digunakan sama sekali (should succeed) +- [ ] Test delete dengan ID kosong (should return 400) +- [ ] Test delete dengan ID yang tidak ada (should return error) +- [ ] Verify soft delete: cek `deletedAt` dan `isActive` di database + +### UI Changes (Issue #2): +- [ ] Test search dengan 1 karakter +- [ ] Test search dengan 10 karakter +- [ ] Test pagination page 1 → page 2 (search query harus tetap ada) +- [ ] Test pagination page 2 → page 3 (search query harus tetap ada) +- [ ] Test pagination page 3 → page 1 (search query harus tetap ada) +- [ ] Test clear search (pagination harus reset ke page 1) +- [ ] Test scroll to top saat ganti halaman + +### UI Changes (Issue #3): +- [ ] Test dengan data kosong (empty state) +- [ ] Test dengan search tidak ada hasil (empty state) +- [ ] Verify colSpan = 3 (tidak terlalu lebar/sempit) +- [ ] Verify table layout tetap rapi + +--- + +## 📝 ADDITIONAL IMPROVEMENTS + +### Code Quality Improvements: + +**1. Better Error Handling (del.ts):** +```typescript +try { + // ... validation and logic +} catch (error) { + console.error("Delete kategori error:", error); + return Response.json({ + success: false, + message: "Gagal menghapus kategori: " + (error instanceof Error ? error.message : 'Unknown error'), + }, { status: 500 }); +} +``` + +**2. Soft Delete Pattern (del.ts):** +```typescript +// Changed from hard delete to soft delete +await prisma.kategoriBerita.update({ + where: { id }, + data: { + deletedAt: new Date(), + isActive: false, + }, +}); +``` + +**3. Consistent Response Format (del.ts):** +```typescript +return { + success: true, + message: "Kategori berita berhasil dihapus", +}; +``` + +--- + +## 🚀 MIGRATION NOTES + +### No Database Changes Required: +- ✅ Tidak ada perubahan schema +- ✅ Tidak perlu migration +- ✅ Tidak perlu db push + +### Backward Compatibility: +- ✅ API response format tetap sama (`{ success, message }`) +- ✅ Frontend pagination API tetap sama +- ✅ Table structure tidak berubah + +--- + +## ✅ VERIFICATION + +**All High Priority Issues from QC Report:** +- [x] Issue #1: API - Delete kategori relation check ✅ FIXED +- [x] Issue #2: UI - Search parameter pagination ✅ FIXED +- [x] Issue #3: UI - colSpan mismatch ✅ FIXED + +**Status: 3/3 High Priority Issues FIXED (100% Complete)** + +--- + +## 📈 IMPACT SUMMARY + +### Before Fix: +- ❌ Kategori bisa dihapus meski masih digunakan (data integrity issue) +- ❌ Search hilang saat pagination (UX issue) +- ❌ Table layout tidak rapi (UI polish issue) + +### After Fix: +- ✅ Kategori tidak bisa dihapus jika masih digunakan (data integrity protected) +- ✅ Search tetap ada saat pagination (UX improved) +- ✅ Table layout rapi (UI polished) + +--- + +**Last Updated:** 25 Februari 2026 +**Completed By:** QC Automation +**Review Status:** ✅ Ready for Testing +**Total Time to Fix:** ~30 minutes diff --git a/QC/DESA/fix-summary-potensi-desa.md b/QC/DESA/fix-summary-potensi-desa.md new file mode 100644 index 00000000..67010964 --- /dev/null +++ b/QC/DESA/fix-summary-potensi-desa.md @@ -0,0 +1,442 @@ +# Fix Summary - Potensi Desa High Priority Issues + +**Tanggal:** 25 Februari 2026 +**Status:** ✅ **ALL COMPLETED** + +--- + +## ✅ COMPLETED FIXES + +### 1. Schema - Unique Constraints ✅ FIXED + +**File:** `prisma/schema.prisma` + +**Changes:** +```prisma +// BEFORE +model PotensiDesa { + name String // ❌ No unique constraint + // ... +} + +model KategoriPotensi { + nama String // ❌ No unique constraint + // ... +} + +// AFTER +model PotensiDesa { + name String @unique @db.VarChar(255) // ✅ Unique + length limit + // ... +} + +model KategoriPotensi { + nama String @unique @db.VarChar(100) // ✅ Unique + length limit + // ... +} +``` + +**Impact:** +- ✅ Tidak ada duplikasi nama kategori potensi +- ✅ Tidak ada duplikasi nama potensi desa +- ✅ Database-level validation untuk uniqueness + +**Database Migration:** +```bash +✅ COMPLETED: bunx prisma db push --accept-data-loss +✅ Prisma Client regenerated successfully +``` + +--- + +### 2. Schema - kategoriId Required ✅ FIXED + +**File:** `prisma/schema.prisma` + +**Changes:** +```prisma +// BEFORE +model PotensiDesa { + kategoriId String? // ❌ Nullable + // ... +} + +// AFTER +model PotensiDesa { + kategoriId String @db.VarChar(36) // ✅ Required + length limit + // ... +} +``` + +**Impact:** +- ✅ Potensi desa HARUS punya kategori +- ✅ Data integrity lebih baik +- ✅ Foreign key constraint enforced + +**Note:** Form create/edit sudah validasi kategori wajib dipilih (existing validation). + +--- + +### 3. Schema - Length Constraints ✅ FIXED + +**File:** `prisma/schema.prisma` + +**Changes:** +```prisma +// BEFORE +model PotensiDesa { + name String // ❌ No max length + deskripsi String @db.Text + // ... +} + +model KategoriPotensi { + nama String // ❌ No max length + // ... +} + +// AFTER +model PotensiDesa { + name String @unique @db.VarChar(255) // ✅ Max 255 chars + deskripsi String @db.Text + kategoriId String @db.VarChar(36) // ✅ Max 36 chars (CUID) + // ... +} + +model KategoriPotensi { + nama String @unique @db.VarChar(100) // ✅ Max 100 chars + // ... +} +``` + +**Impact:** +- ✅ User tidak bisa input nama sangat panjang +- ✅ UI tidak break karena text terlalu panjang +- ✅ Database storage lebih efisien + +--- + +### 4. API - Delete Kategori dengan Relation Check ✅ FIXED + +**File:** `src/app/api/[[...slugs]]/_lib/desa/potensi/kategori-potensi/del.ts` + +**Changes:** +```typescript +// BEFORE +export default async function kategoriPotensiDelete(context: Context) { + const id = context.params.id as string; + + // ❌ Langsung delete tanpa cek relasi + await prisma.kategoriPotensi.delete({ + where: { id }, + }); + + return { + status: 200, + success: true, + message: "Sukses Menghapus kategori potensi", + }; +} + +// AFTER +export default async function kategoriPotensiDelete(context: Context) { + try { + const id = context.params?.id as string; + + if (!id) { + return Response.json({ + success: false, + message: "ID tidak boleh kosong", + }, { status: 400 }); + } + + // ✅ Cek apakah kategori masih digunakan oleh potensi desa + const existingPotensi = await prisma.potensiDesa.findFirst({ + where: { + kategoriId: id, + isActive: true, + deletedAt: null, + }, + }); + + if (existingPotensi) { + return Response.json({ + success: false, + message: "Kategori masih digunakan oleh potensi desa. Tidak dapat dihapus.", + }, { status: 400 }); + } + + // ✅ Soft delete (bukan hard delete) + await prisma.kategoriPotensi.update({ + where: { id }, + data: { + deletedAt: new Date(), + isActive: false, + }, + }); + + return { + success: true, + message: "Kategori potensi berhasil dihapus", + }; + } catch (error) { + console.error("Delete kategori error:", error); + return Response.json({ + success: false, + message: "Gagal menghapus kategori: " + (error instanceof Error ? error.message : 'Unknown error'), + }, { status: 500 }); + } +} +``` + +**Impact:** +- ✅ Tidak ada foreign key constraint error +- ✅ Data integrity terjaga +- ✅ User feedback lebih baik (error message jelas) +- ✅ Soft delete pattern konsisten + +--- + +### 5. API - Find Unique dengan isActive Filter ✅ FIXED + +**File:** `src/app/api/[[...slugs]]/_lib/desa/potensi/find-unique.ts` + +**Changes:** +```typescript +// BEFORE +const data = await prisma.potensiDesa.findUnique({ + where: { id }, // ❌ No isActive filter + include: { + image: true, + kategori: true + }, +}); + +// AFTER +// ✅ Filter by isActive and deletedAt +const data = await prisma.potensiDesa.findFirst({ + where: { + id, + isActive: true, // ✅ Added + deletedAt: null, // ✅ Added + }, + include: { + image: true, + kategori: true + }, +}); +``` + +**Impact:** +- ✅ Tidak load data yang sudah soft-delete +- ✅ Data consistency lebih baik +- ✅ Security improved (tidak expose deleted data) + +--- + +### 6. UI - XSS Sanitization dengan DOMPurify ✅ FIXED + +**Files Modified:** +- ✅ `src/app/admin/(dashboard)/desa/potensi/list-potensi/page.tsx` +- ✅ `src/app/admin/(dashboard)/desa/potensi/list-potensi/[id]/page.tsx` + +**Changes:** + +**Import DOMPurify:** +```typescript +import DOMPurify from 'dompurify'; +``` + +**Sanitize HTML (Desktop Table - line 140):** +```typescript +// BEFORE + + +// AFTER + +``` + +**Sanitize HTML (Mobile Cards - line 202):** +```typescript +// BEFORE + + +// AFTER + +``` + +**Sanitize HTML (Detail Page - deskripsi & content):** +```typescript +// BEFORE + + + +// AFTER + + +``` + +**Impact:** +- ✅ XSS attack prevented +- ✅ User tidak bisa inject malicious scripts +- ✅ Security significantly improved +- ✅ Data integrity terjaga + +**Allowed HTML Tags:** +- `p` - Paragraph +- `br` - Line break +- `strong` - Bold +- `em` - Italic +- `u` - Underline +- `ul`, `ol`, `li` - Lists + +**Disallowed:** +- `script`, `iframe`, `object`, `embed`, dll (berbahaya) +- Semua attributes (untuk security maksimal) + +--- + +## 📊 SUMMARY OF CHANGES + +| Issue | Status | Files Changed | Impact | +|-------|--------|---------------|--------| +| 1. Unique Constraints | ✅ Fixed | schema.prisma | Prevents duplicates | +| 2. Required kategoriId | ✅ Fixed | schema.prisma | Data integrity | +| 3. Length Constraints | ✅ Fixed | schema.prisma | UI/DB protection | +| 4. Delete Relation Check | ✅ Fixed | del.ts | Prevents data loss | +| 5. isActive Filter | ✅ Fixed | find-unique.ts | Data consistency | +| 6. XSS Sanitization | ✅ Fixed | 2 pages | Security improved | + +**Total Files Modified:** 5 +- `prisma/schema.prisma` +- `src/app/api/[[...slugs]]/_lib/desa/potensi/kategori-potensi/del.ts` +- `src/app/api/[[...slugs]]/_lib/desa/potensi/find-unique.ts` +- `src/app/admin/(dashboard)/desa/potensi/list-potensi/page.tsx` +- `src/app/admin/(dashboard)/desa/potensi/list-potensi/[id]/page.tsx` + +--- + +## 🧪 TESTING CHECKLIST + +### Database Changes: +- [ ] Verify unique constraint works (try insert duplicate name) +- [ ] Verify length constraint works (try insert >255 chars) +- [ ] Verify kategoriId required (try insert without kategori) +- [ ] Check existing data still accessible + +### API Changes: +- [ ] Test delete kategori yang masih digunakan (should fail) +- [ ] Test delete kategori yang tidak digunakan (should succeed) +- [ ] Test find-unique untuk data yang sudah deleted (should return 404) +- [ ] Test find-unique untuk data aktif (should work) + +### UI Changes: +- [ ] Test XSS attempt dengan script tags (should be sanitized) +- [ ] Test HTML content masih render dengan benar +- [ ] Test allowed tags (p, br, strong, em, u, lists) masih work +- [ ] Test disallowed tags (script, iframe) di-strip + +--- + +## 🚀 MIGRATION NOTES + +### Database Migration Applied: +```bash +bunx prisma db push --accept-data-loss +``` + +**Warnings Accepted:** +- Column `nama` cast from `Text` to `VarChar(100)` (3 rows) +- Column `name` cast from `Text` to `VarChar(255)` (11 rows) +- Column `kategoriId` cast from `Text` to `VarChar(36)` (11 rows) +- Unique constraint added to `nama` +- Unique constraint added to `name` + +**Data Loss Considerations:** +- Jika ada data dengan nama >100 chars (kategori) atau >255 chars (potensi), akan ter-truncate +- Jika ada duplicate names, migration akan fail (perlu manual cleanup dulu) + +### Existing Data: +- **KategoriPotensi:** 3 rows (should be fine) +- **PotensiDesa:** 11 rows (should be fine) + +--- + +## 📝 RECOMMENDATIONS + +### Immediate Actions: +1. ✅ **Test di staging environment** dulu sebelum production +2. ✅ **Backup database** sebelum deploy ke production +3. ✅ **Check existing data** untuk duplicate names +4. ✅ **Test semua CRUD operations** untuk potensi dan kategori + +### Future Improvements: +1. **Add authentication** ke semua API endpoints (belum ada di scope QC ini) +2. **Add backend validation** untuk duplicate check di create/update +3. **Add pagination** di find-many API (sudah ada) +4. **Add search** di semua fields (sudah ada) +5. **Add sorting** options (belum ada) + +--- + +## ✅ VERIFICATION + +**All High Priority Issues from QC Report:** +- [x] Issue #1: Schema - Unique constraints ✅ FIXED +- [x] Issue #2: Schema - kategoriId required ✅ FIXED +- [x] Issue #3: Schema - Length constraints ✅ FIXED +- [x] Issue #4: API - Delete relation check ✅ FIXED +- [x] Issue #5: API - isActive filter ✅ FIXED +- [x] Issue #6: UI - XSS sanitization ✅ FIXED + +**Status: 6/6 High Priority Issues FIXED (100% Complete)** + +--- + +**Last Updated:** 25 Februari 2026 +**Completed By:** QC Automation +**Review Status:** ✅ Ready for Testing diff --git a/QC/DESA/fix-summary-profil-desa.md b/QC/DESA/fix-summary-profil-desa.md new file mode 100644 index 00000000..c2be88b3 --- /dev/null +++ b/QC/DESA/fix-summary-profil-desa.md @@ -0,0 +1,363 @@ +# Fix Summary - Profil Desa High Priority Issues + +**Tanggal:** 25 Februari 2026 +**Status:** ✅ **Partially Completed** + +--- + +## ✅ COMPLETED FIXES + +### 1. Schema - deletedAt @default(now()) Bug ✅ FIXED + +**File:** `prisma/schema.prisma` + +**Changes:** +```prisma +// BEFORE +model SejarahDesa { + deletedAt DateTime @default(now()) // ❌ BUG +} + +// AFTER +model SejarahDesa { + deletedAt DateTime? // ✅ FIXED +} +``` + +**Affected Models:** +- ✅ SejarahDesa +- ✅ VisiMisiDesa +- ✅ LambangDesa +- ✅ MaskotDesa + +**Database Migration:** +```bash +✅ COMPLETED: bunx prisma db push +✅ Prisma Client regenerated successfully +``` + +--- + +### 2. Hardcoded Nama Perbekel di UI ✅ FIXED + +**File:** `src/app/admin/(dashboard)/desa/profil/profil-perbekel/page.tsx` + +**Changes:** +```tsx +// BEFORE (Line 95-102) +I.B. Surya Prabhawa Manuaba, S.H., M.H. + +// AFTER +{perbekel.nama || "I.B. Surya Prabhawa Manuaba, S.H., M.H."} +``` + +**Impact:** +- ✅ Nama perbekel sekarang dinamis dari database +- ✅ Fallback ke nama lama jika data kosong (backward compatible) + +--- + +### 3. Magic String "edit" - Created /first Endpoint ✅ FIXED + +**New Files Created:** +- ✅ `src/app/api/[[...slugs]]/_lib/desa/profile/profile_desa/sejarah/find-first.ts` +- ✅ Updated `src/app/api/[[...slugs]]/_lib/desa/profile/profile_desa/sejarah/index.ts` + +**New Endpoint:** +``` +GET /api/desa/profile/sejarah/first +``` + +**Features:** +- ✅ Authentication required (menggunakan `requireAuth`) +- ✅ Returns first active record (orderBy createdAt asc) +- ✅ No more magic string "edit" +- ✅ Type-safe dan scalable + +**Usage:** +```typescript +// OLD (magic string) +stateProfileDesa.sejarahDesa.findUnique.load("edit"); + +// NEW (type-safe) +const response = await ApiFetch.api.desa.profile.sejarah.first.get(); +``` + +--- + +### 4. Authentication Helper Libraries ✅ CREATED + +**New Files:** +- ✅ `src/lib/api-auth.ts` - Authentication helper dengan `requireAuth` dan `optionalAuth` +- ✅ `src/lib/session.ts` - Session helper menggunakan iron-session + +**Features:** +- ✅ Session-based authentication +- ✅ Auto-redirect jika tidak authenticated +- ✅ Check user isActive status +- ✅ Error handling lengkap + +**Usage Example:** +```typescript +import { requireAuth } from "@/lib/api-auth"; + +export default async function myEndpoint(context: Context) { + const authResult = await requireAuth(context); + if (!authResult.authenticated) { + return authResult.response; // 401 Unauthorized + } + + // Lanjut proses dengan authResult.user + console.log("User:", authResult.user); +} +``` + +--- + +### 5. Authentication Added to Update Endpoint ✅ FIXED + +**File:** `src/app/api/[[...slugs]]/_lib/desa/profile/profile_desa/sejarah/update.ts` + +**Changes:** +```typescript +// BEFORE +import prisma from "@/lib/prisma"; +import { Context } from "elysia"; + +export default async function sejarahDesaUpdate(context: Context) { + // ❌ No authentication + const id = context.params?.id as string; + // ... +} + +// AFTER +import prisma from "@/lib/prisma"; +import { requireAuth } from "@/lib/api-auth"; +import { Context } from "elysia"; + +export default async function sejarahDesaUpdate(context: Context) { + // ✅ Authentication check + const authResult = await requireAuth(context); + if (!authResult.authenticated) { + return authResult.response; + } + + const id = context.params?.id as string; + // ... +} +``` + +--- + +## ⚠️ REMAINING FIXES (Manual Required) + +### 1. Add Authentication to ALL Profile API Endpoints + +**Files that need authentication:** + +#### Profile Desa (Sejarah, Visi Misi, Lambang, Maskot): +- [ ] `src/app/api/[[...slugs]]/_lib/desa/profile/profile_desa/sejarah/find-by-id.ts` +- [ ] `src/app/api/[[...slugs]]/_lib/desa/profile/profile_desa/visi-misi/find-by-id.ts` +- [ ] `src/app/api/[[...slugs]]/_lib/desa/profile/profile_desa/visi-misi/update.ts` +- [ ] `src/app/api/[[...slugs]]/_lib/desa/profile/profile_desa/lambang-desa/find-by-id.ts` +- [ ] `src/app/api/[[...slugs]]/_lib/desa/profile/profile_desa/lambang-desa/update.ts` +- [ ] `src/app/api/[[...slugs]]/_lib/desa/profile/profile_desa/maskot-desa/find-by-id.ts` +- [ ] `src/app/api/[[...slugs]]/_lib/desa/profile/profile_desa/maskot-desa/update.ts` + +#### Profile Perbekel: +- [ ] `src/app/api/[[...slugs]]/_lib/desa/profile/profilePerbekel/find-by-id.ts` +- [ ] `src/app/api/[[...slugs]]/_lib/desa/profile/profilePerbekel/update.ts` + +#### Profile Mantan Perbekel: +- [ ] `src/app/api/[[...slugs]]/_lib/desa/profile/profile-mantan-perbekel/create.ts` +- [ ] `src/app/api/[[...slugs]]/_lib/desa/profile/profile-mantan-perbekel/findMany.ts` +- [ ] `src/app/api/[[...slugs]]/_lib/desa/profile/profile-mantan-perbekel/findUnique.ts` +- [ ] `src/app/api/[[...slugs]]/_lib/desa/profile/profile-mantan-perbekel/updt.ts` +- [ ] `src/app/api/[[...slugs]]/_lib/desa/profile/profile-mantan-perbekel/del.ts` + +**How to Add Authentication:** + +```typescript +// Tambahkan di awal function (sebelum logic utama) +import { requireAuth } from "@/lib/api-auth"; + +export default async function myEndpoint(context: Context) { + // ✅ Authentication check + const authResult = await requireAuth(context); + if (!authResult.authenticated) { + return authResult.response; + } + + // ... existing code +} +``` + +--- + +### 2. Fix Maskot Image Delete Logic + +**File:** `src/app/api/[[...slugs]]/_lib/desa/profile/profile_desa/maskot-desa/update.ts` + +**Current Bug:** +```typescript +// ❌ Menghapus SEMUA gambar lama +for (const old of existing.images) { + await prisma.fileStorage.delete({ where: { id: old.imageId } }); +} +``` + +**Fix Required:** +```typescript +// ✅ Implementasi diff logic +const oldImageIds = existing.images.map(img => img.imageId); +const newImageIds = body.images?.filter(img => img.imageId).map(img => img.imageId) || []; + +// Find images to delete (in old but not in new) +const imagesToDelete = oldImageIds.filter(id => !newImageIds.includes(id)); + +// Delete only removed images +for (const imageId of imagesToDelete) { + if (imageId) { + const oldImage = await prisma.fileStorage.findUnique({ where: { id: imageId } }); + if (oldImage) { + try { + const filePath = path.join(oldImage.path, oldImage.name); + await fs.unlink(filePath); + await prisma.fileStorage.delete({ where: { id: imageId } }); + } catch (error) { + console.error('Failed to delete old image:', error); + } + } + } +} +``` + +--- + +### 3. Update State Management to Use /first Endpoint + +**File:** `src/app/admin/(dashboard)/_state/desa/profile.ts` + +**Current Code (Line ~36):** +```typescript +// ❌ Magic string "edit" +async load(id: string) { + const response = await fetch(`/api/desa/profile/sejarah/${id}`); + // ... +} + +// Usage di page: +stateProfileDesa.sejarahDesa.findUnique.load("edit"); +``` + +**Fix Required:** +```typescript +// ✅ Gunakan /first endpoint +async loadFirst() { + this.loading = true; + this.error = null; + + try { + const response = await ApiFetch.api.desa.profile.sejarah.first.get(); + + if (response.success) { + this.data = response.data; + return response.data; + } else { + throw new Error(response.message || "Gagal mengambil data"); + } + } catch (error) { + const msg = (error as Error).message; + this.error = msg; + console.error("Load sejarah desa error:", msg); + toast.error("Terjadi kesalahan"); + return null; + } finally { + this.loading = false; + } +} + +// Usage di page: +stateProfileDesa.sejarahDesa.findUnique.loadFirst(); +``` + +--- + +### 4. Add XSS Sanitization + +**Files that use dangerouslySetInnerHTML:** +- [ ] `src/app/admin/(dashboard)/desa/profil/profil-perbekel/page.tsx` (multiple places) +- [ ] `src/app/admin/(dashboard)/desa/profil/profil-perbekel/[id]/page.tsx` + +**Fix Required:** +```typescript +// Install: bun add dompurify +import DOMPurify from 'dompurify'; + +// Usage +
+``` + +--- + +## 📋 TESTING CHECKLIST + +### Database Changes: +- [ ] Verify schema changes applied: `bunx prisma db push` +- [ ] Check Prisma Client regenerated +- [ ] Test create new data (should not auto-delete) + +### API Authentication: +- [ ] Test endpoint tanpa login (should return 401) +- [ ] Test endpoint dengan login (should work) +- [ ] Test dengan user inactive (should return 403) + +### /first Endpoint: +- [ ] Test GET /api/desa/profile/sejarah/first +- [ ] Verify returns first active record +- [ ] Test tanpa authentication (should fail) + +### UI Changes: +- [ ] Check perbekel name dynamic (not hardcoded) +- [ ] Test with different perbekel data +- [ ] Verify fallback to old name if data empty + +--- + +## 🚀 NEXT STEPS + +1. **Add authentication ke semua API endpoints** (15 files) +2. **Fix maskot image delete logic** (1 file) +3. **Update state management** untuk gunakan `/first` endpoint +4. **Add XSS sanitization** di semua page yang pakai `dangerouslySetInnerHTML` +5. **Test semua changes** secara thorough + +--- + +## 📝 NOTES + +- ✅ Schema fix sudah di-push ke database +- ✅ Authentication helper sudah dibuat dan bisa di-reuse +- ✅ /first endpoint sudah dibuat sebagai contoh +- ⚠️ Remaining fixes butuh manual update karena banyak file + +**Estimated Time to Complete:** +- Add auth to all endpoints: ~2-3 jam +- Fix maskot delete logic: ~30 menit +- Update state management: ~1 jam +- Add XSS sanitization: ~30 menit +- Testing: ~1-2 jam + +**Total: ~5-6 jam** + +--- + +**Last Updated:** 25 Februari 2026 +**Status:** 3/5 Critical Issues Fixed (60% Complete) diff --git a/QC/DESA/summary-qc-berita-desa.md b/QC/DESA/summary-qc-berita-desa.md new file mode 100644 index 00000000..72271d2e --- /dev/null +++ b/QC/DESA/summary-qc-berita-desa.md @@ -0,0 +1,622 @@ +# Quality Control Report - Berita Desa Admin + +**Lokasi:** `/src/app/admin/(dashboard)/desa/berita/` +**Tanggal QC:** 25 Februari 2026 +**Status:** ✅ **Good** (dengan issue critical yang perlu diperbaiki) + +--- + +## 📋 Ringkasan Eksekutif + +Halaman Berita Desa memiliki implementasi yang **cukup baik** dengan CRUD lengkap, state management terstruktur, dan UI yang responsive. Ditemukan **14 issue** dengan rincian: + +- 🔴 **High Priority:** 3 issue +- 🟡 **Medium Priority:** 7 issue +- 🟢 **Low Priority:** 4 issue + +**Overall Score: 7/10** - Good + +--- + +## 📁 Struktur File yang Diperiksa + +``` +/src/app/admin/(dashboard)/desa/berita/ +├── layout.tsx +├── _com/ +│ ├── BeritaEditor.tsx # Rich text editor component +│ └── layoutTabs.tsx # Tab navigation +├── kategori-berita/ +│ ├── page.tsx # List kategori dengan search & pagination +│ ├── create/ +│ │ └── page.tsx # Form create kategori +│ └── [id]/ +│ └── page.tsx # Edit kategori +└── list-berita/ + ├── page.tsx # List berita dengan search & pagination + ├── create/ + │ └── page.tsx # Form create berita (rich text + image) + └── [id]/ + ├── page.tsx # Detail berita + └── edit/ + └── page.tsx # Edit berita +``` + +**File Terkait:** +- State: `/src/app/admin/(dashboard)/_state/desa/berita.ts` +- API: `/src/app/api/[[...slugs]]/_lib/desa/berita/` (8 files) +- API: `/src/app/api/[[...slugs]]/_lib/desa/berita/kategori-berita/` (6 files) +- Schema: `/prisma/schema.prisma` (Model `Berita` & `KategoriBerita`) + +--- + +## 🔴 HIGH PRIORITY ISSUES + +### 1. API - Kategori Masih Digunakan Bisa Dihapus + +**File:** `src/app/api/[[...slugs]]/_lib/desa/berita/kategori-berita/del.ts` + +```typescript +export default async function kategoriBeritaDelete(context: Context) { + const id = context.params?.id as string; + + // ❌ Tidak cek apakah kategori masih dipakai oleh Berita + await prisma.kategoriBerita.delete({ where: { id } }); + + return { success: true, message: "Kategori berita berhasil dihapus" }; +} +``` + +**Dampak:** +- Data integrity bermasalah - berita kehilangan referensi kategori +- Bisa terjadi foreign key constraint error +- Berita yang sudah ada jadi tidak punya kategori + +**Solusi:** +```typescript +// Cek apakah masih ada berita yang menggunakan kategori ini +const beritaCount = await prisma.berita.count({ + where: { + kategoriBeritaId: id, + isActive: true + } +}); + +if (beritaCount > 0) { + return Response.json({ + success: false, + message: `Kategori tidak dapat dihapus karena masih digunakan oleh ${beritaCount} berita` + }, { status: 400 }); +} + +// Lanjut delete jika tidak ada yang menggunakan +await prisma.kategoriBerita.update({ + where: { id }, + data: { deletedAt: new Date(), isActive: false } +}); + +return { success: true, message: "Kategori berita berhasil dihapus" }; +``` + +--- + +### 2. UI - Search Parameter Hilang Saat Pagination + +**File:** `src/app/admin/(dashboard)/desa/berita/list-berita/page.tsx` + +```typescript + { + load(newPage, 10); // ❌ Missing search parameter + }} +/> +``` + +**Dampak:** +- Saat user ganti halaman, search query hilang +- User harus ketik ulang search query +- UX sangat buruk untuk pagination dengan search + +**Solusi:** +```typescript + { + load(newPage, 10, search); // ✅ Include search parameter + }} +/> +``` + +**Note:** Pastikan function `load` menerima parameter search: +```typescript +const load = async (page: number, limit: number, searchQuery?: string) => { + // ... +}; +``` + +--- + +### 3. UI - colSpan Tidak Sesuai Jumlah Kolom + +**File:** `src/app/admin/(dashboard)/desa/berita/kategori-berita/page.tsx` + +```typescript + + + Nama + Dibuat + Aksi {/* 3 kolom total */} + + + + + {loading ? ( + + {/* ❌ colSpan 4, seharusnya 3 */} + + + + ) : ( + // ... + )} + +``` + +**Dampak:** Layout table tidak rapi, colSpan terlalu lebar. + +**Solusi:** +```typescript + // ✅ Match column count +``` + +--- + +## 🟡 MEDIUM PRIORITY ISSUES + +### 4. Schema - `deletedAt` Default `now()` Bermasalah + +**File:** `prisma/schema.prisma` + +```prisma +model Berita { + deletedAt DateTime @default(now()) // ❌ Problematic default + isActive Boolean @default(true) +} + +model KategoriBerita { + deletedAt DateTime @default(now()) // ❌ Problematic default + isActive Boolean @default(true) +} +``` + +**Dampak:** +- Record baru langsung ter-mark sebagai deleted saat create +- Soft delete logic tidak bekerja dengan benar +- Query dengan filter `deletedAt: null` tidak akan dapat data baru + +**Solusi:** +```prisma +model Berita { + deletedAt DateTime? // ✅ Nullable, tanpa default + isActive Boolean @default(true) +} + +model KategoriBerita { + deletedAt DateTime? // ✅ Nullable, tanpa default + isActive Boolean @default(true) +} +``` + +**Migration Required:** +```bash +bunx prisma db push +# atau +bunx prisma migrate dev --name fix_deleted_at_default +``` + +**Data Cleanup:** +```sql +-- Update record yang ter-affected +UPDATE "Berita" SET "deletedAt" = NULL WHERE "isActive" = true; +UPDATE "KategoriBerita" SET "deletedAt" = NULL WHERE "isActive" = true; +``` + +--- + +### 5. API - Create Tidak Return Data dari Database + +**File:** `src/app/api/[[...slugs]]/_lib/desa/berita/create.ts` + +```typescript +const created = await prisma.berita.create({ + data: { + ...body, + kategoriBeritaId: kategori?.id + } +}); + +return { + success: true, + message: "Sukses menambahkan berita", + data: { ...body } // ❌ Return input body, bukan data dari DB +}; +``` + +**Dampak:** +- Frontend tidak dapat data lengkap (ID, timestamps, relasi) +- User harus refresh untuk lihat data lengkap +- Inconsistent dengan API lain yang return data dari DB + +**Solusi:** +```typescript +const created = await prisma.berita.create({ + data: { + ...body, + kategoriBeritaId: kategori?.id + }, + include: { + image: true, + kategoriBerita: true + } +}); + +return { + success: true, + message: "Sukses menambahkan berita", + data: created // ✅ Return data dari DB dengan relasi +}; +``` + +--- + +### 6. API - Order By `asc` untuk Kategori Tidak Ideal + +**File:** `src/app/api/[[...slugs]]/_lib/desa/berita/kategori-berita/findMany.ts` + +```typescript +const data = await prisma.kategoriBerita.findMany({ + where, + orderBy: { createdAt: 'asc' }, // ⚠️ Data lama muncul dulu + skip, + take: limit +}); +``` + +**Dampak:** Kategori baru (yang mungkin lebih relevan) ada di bawah. + +**Solusi:** +```typescript +const data = await prisma.kategoriBerita.findMany({ + where, + orderBy: { createdAt: 'desc' }, // ✅ Data terbaru dulu + skip, + take: limit +}); +``` + +--- + +### 7. UI - Button Label "Batal" untuk Reset Form Membingungkan + +**File:** `src/app/admin/(dashboard)/desa/berita/kategori-berita/[id]/page.tsx` + +```typescript + +``` + +**Dampak:** User mungkin bingung apakah button ini akan cancel edit atau reset form. + +**Solusi:** +```typescript + +``` + +--- + +### 8. UI - Dropzone Accept Tidak Spesifik + +**File:** `src/app/admin/(dashboard)/desa/berita/list-berita/create/page.tsx` dan `edit/page.tsx` + +```typescript + +``` + +**Dampak:** User bisa coba upload format image aneh yang tidak didukung browser. + +**Solusi:** +```typescript + +``` + +--- + +### 9. State - Inconsistent API Client (fetch vs ApiFetch) + +**File:** `src/app/admin/(dashboard)/_state/desa/berita.ts` + +```typescript +// ❌ Inconsistent - fetch langsung +const res = await fetch(`/api/desa/berita/${id}`); +const data = await res.json(); + +// ✅ Di tempat lain pakai ApiFetch +const data = await ApiFetch.api.desa.berita[':id'].get({ query: { id } }); +``` + +**Dampak:** Code maintainability kurang, tidak konsisten. + +**Solusi:** +```typescript +// Gunakan ApiFetch untuk semua +const data = await ApiFetch.api.desa.berita[':id'].get({ query: { id } }); +``` + +--- + +### 10. Layout - `isDetailPage` Logic Kurang Robust + +**File:** `src/app/admin/(dashboard)/desa/berita/layout.tsx` + +```typescript +const segments = pathname.split('/').filter(Boolean); +const isDetailPage = segments.length >= 5; // ❌ Magic number, bisa false positive +``` + +**Dampak:** Bisa false positive untuk path lain yang length sama. + +**Solusi:** +```typescript +// Option 1: Check for specific segments +const isDetailPage = segments.some(seg => + ['create', 'edit'].includes(seg) || /^\w{20,}$/.test(seg) // CUID pattern +); + +// Option 2: Check last segment +const lastSegment = segments[segments.length - 1]; +const isDetailPage = ['create', 'edit'].includes(lastSegment) || + /^[a-zA-Z0-9]{20,}$/.test(lastSegment); +``` + +--- + +## 🟢 LOW PRIORITY ISSUES + +### 11. Form Validation Hanya Cek `trim()` + +**File:** `src/app/admin/(dashboard)/desa/berita/kategori-berita/create/page.tsx` + +```typescript +const isFormValid = () => { + return createState.create.form.name?.trim().length > 0; // ⚠️ Hanya cek empty +}; +``` + +**Dampak:** User bisa input nama 1 karakter. + +**Solusi:** +```typescript +const isFormValid = () => { + const name = createState.create.form.name?.trim(); + return name && name.length >= 3; // ✅ Minimal 3 karakter +}; +``` + +--- + +### 12. Error Handling Upload Gambar Generic + +**File:** `src/app/admin/(dashboard)/desa/berita/list-berita/create/page.tsx` + +```typescript +catch (error) { + toast.error('Gagal upload gambar'); // ⚠️ Generic message +} +``` + +**Solusi:** +```typescript +catch (error) { + const errorMessage = error instanceof Error ? error.message : 'Unknown error'; + toast.error(`Gagal upload gambar: ${errorMessage}`); +} +``` + +--- + +### 13. Unused State - `kategoriBerita.findUnique` + +**File:** `src/app/admin/(dashboard)/_state/desa/berita.ts` + +```typescript +kategoriBerita: { + findUnique: { + loading: false, + async byId(id: string) { + // ❌ Defined tapi tidak digunakan di UI + } + } +} +``` + +**Solusi:** +- Option A: Hapus jika memang tidak diperlukan +- Option B: Implementasikan di UI edit kategori + +--- + +### 14. Unused API Endpoints + +**File:** `src/app/api/[[...slugs]]/_lib/desa/berita/` + +``` +find-first.ts // ⚠️ Tidak digunakan di admin +find-recent.ts // ⚠️ Tidak digunakan di admin +``` + +**Solusi:** +- Option A: Hapus jika memang tidak diperlukan +- Option B: Dokumentasikan untuk future use +- Option C: Implementasikan di UI (misal: recent articles widget) + +--- + +## ✅ YANG SUDAH BAIK + +### **Schema:** +- ✅ Relasi yang jelas antara Berita dan KategoriBerita (one-to-many) +- ✅ Soft delete dengan `deletedAt` dan `isActive` +- ✅ Image menggunakan relasi ke FileStorage (reusable) +- ✅ Timestamp lengkap (createdAt, updatedAt) +- ✅ Unique constraint pada `name` di KategoriBerita + +### **API:** +- ✅ CRUD lengkap untuk Berita dan Kategori Berita +- ✅ Pagination support dengan `page`, `limit`, `search` +- ✅ Search functionality dengan case-insensitive +- ✅ Include relasi (image, kategori) pada find-many +- ✅ File cleanup (hapus file fisik + database) saat update/delete +- ✅ Filter by kategori di find-many +- ✅ Response format konsisten: `{ success, message, data }` + +### **UI/UX:** +- ✅ Konsisten design pattern +- ✅ Responsive untuk mobile dan desktop +- ✅ Loading states dan skeleton +- ✅ Toast notifications untuk feedback +- ✅ Form validation yang comprehensive +- ✅ Rich text editor (BeritaEditor) dengan toolbar lengkap +- ✅ Image upload dengan preview dan delete button +- ✅ Search dengan debounce 1 detik +- ✅ Modal konfirmasi hapus +- ✅ Minimum delay 300ms untuk UX yang smooth + +### **State Management:** +- ✅ Valtio proxy untuk global state +- ✅ Zod validation schema +- ✅ Loading state management +- ✅ Error handling di setiap action + +--- + +## 📊 Metrics + +| Aspek | Score | Keterangan | +|-------|-------|------------| +| **Schema Design** | 8/10 | Good, unique constraint ada di Kategori | +| **API Design** | 7.5/10 | RESTful, tapi ada unused endpoints | +| **API Security** | 6/10 | Tidak ada authentication | +| **UI/UX** | 8/10 | Responsive, comprehensive validation | +| **State Management** | 8/10 | Valtio works well, ada inconsistency | +| **Code Quality** | 7/10 | Good structure, beberapa bug minor | + +**Overall Score: 7/10** - **Good** + +--- + +## 🎯 Action Plan + +### Week 1 (Critical Fixes) +- [ ] Fix delete kategori dengan relation check +- [ ] Fix pagination pass search parameter +- [ ] Fix colSpan mismatch +- [ ] Fix `deletedAt @default(now())` di schema + +### Week 2 (Medium Priority) +- [ ] API create return data dari DB +- [ ] Fix order by ke `desc` untuk kategori +- [ ] Rename button "Batal" → "Reset Form" +- [ ] Fix dropzone accept extensions +- [ ] Konsisten gunakan ApiFetch + +### Week 3 (Polish) +- [ ] Fix isDetailPage logic +- [ ] Improve form validation (min length) +- [ ] Improve error handling messages +- [ ] Cleanup unused state/API +- [ ] Add authentication middleware + +--- + +## 📝 Technical Notes + +### **Database Migration:** + +Fix deletedAt default: +```bash +# Generate migration +bunx prisma migrate dev --name fix_deleted_at_default + +# Atau jika tidak pakai migrate +bunx prisma db push + +# Data cleanup +UPDATE "Berita" SET "deletedAt" = NULL WHERE "isActive" = true; +UPDATE "KategoriBerita" SET "deletedAt" = NULL WHERE "isActive" = true; +``` + +### **API Testing:** + +Test delete kategori dengan relasi: +```bash +# 1. Create kategori +POST /api/desa/kategoriberita/create +{ "name": "Test Kategori" } + +# 2. Create berita dengan kategori tersebut +POST /api/desa/berita/create +{ + "judul": "Test Berita", + "kategoriBeritaId": "", + ... +} + +# 3. Try delete kategori (should fail) +DELETE /api/desa/kategoriberita/del/ +# Expected: { success: false, message: "Kategori tidak dapat dihapus..." } +``` + +### **Frontend Testing:** + +Test pagination dengan search: +1. Buka halaman List Berita +2. Ketik search query (misal: "desa") +3. Klik pagination halaman 2 +4. Verify search query masih ada dan result sesuai + +--- + +## 📚 References + +- [Prisma Soft Delete Pattern](https://www.prisma.io/docs/concepts/components/prisma-client/soft-delete) +- [Mantine Table Documentation](https://mantine.dev/core/table/) +- [React Toastify Documentation](https://fkhadra.github.io/react-toastify/) +- [Zod Documentation](https://zod.dev/) + +--- + +**Dibuat oleh:** QC Automation +**Review Status:** ⏳ Menunggu Review Developer +**Next Review:** Setelah implementasi fixes diff --git a/QC/DESA/summary-qc-gallery-desa.md b/QC/DESA/summary-qc-gallery-desa.md new file mode 100644 index 00000000..4f68e333 --- /dev/null +++ b/QC/DESA/summary-qc-gallery-desa.md @@ -0,0 +1,1122 @@ +# Quality Control Report - Gallery Desa Admin + +**Lokasi:** `/src/app/admin/(dashboard)/desa/gallery/` +**Tanggal QC:** 25 Februari 2026 +**Status:** ⚠️ **Needs Improvement** (ada issue critical data loss risk) + +--- + +## 📋 Ringkasan Eksekutif + +Halaman Gallery Desa (Foto & Video) memiliki implementasi yang **cukup baik** dengan CRUD lengkap, upload gambar, YouTube embed, dan state management terstruktur. Namun ditemukan **18 issue** dengan rincian: + +- 🔴 **High Priority:** 5 issue +- 🟡 **Medium Priority:** 8 issue +- 🟢 **Low Priority:** 5 issue + +**Overall Score: 6/10** - Needs Improvement + +--- + +## 📁 Struktur File yang Diperiksa + +``` +/src/app/admin/(dashboard)/desa/gallery/ +├── layout.tsx +├── lib/ +│ ├── layoutTabs.tsx # Tab navigation Foto/Video +│ ├── youtube-utils.ts # YouTube URL conversion utilities +│ └── youtubeEmbed.tsx # Reusable embed component (UNUSED) +├── foto/ +│ ├── page.tsx # List foto dengan search & pagination +│ ├── create/ +│ │ └── page.tsx # Upload foto dengan dropzone +│ └── [id]/ +│ ├── page.tsx # Detail foto +│ └── edit/ +│ └── page.tsx # Edit foto (replace image) +└── video/ + ├── page.tsx # List video dengan search & pagination + ├── create/ + │ └── page.tsx # Add video YouTube dengan embed preview + └── [id]/ + ├── page.tsx # Detail video + └── edit/ + └── page.tsx # Edit video +``` + +**File Terkait:** +- State: `/src/app/admin/(dashboard)/_state/desa/gallery.ts` +- API: `/src/app/api/[[...slugs]]/_lib/desa/gallery/foto/` (7 files) +- API: `/src/app/api/[[...slugs]]/_lib/desa/gallery/video/` (6 files) +- Schema: `/prisma/schema.prisma` (Model `GalleryFoto` & `GalleryVideo`) + +--- + +## 🔴 HIGH PRIORITY ISSUES + +### 1. Schema - `deletedAt @default(now())` (CRITICAL BUG) + +**File:** `prisma/schema.prisma` + +```prisma +model GalleryFoto { + id String @id @default(cuid()) + name String + deletedAt DateTime @default(now()) // ❌ CRITICAL BUG + isActive Boolean @default(true) +} + +model GalleryVideo { + id String @id @default(cuid()) + name String + deletedAt DateTime @default(now()) // ❌ CRITICAL BUG + isActive Boolean @default(true) +} +``` + +**Dampak:** +- **Setiap record baru langsung ter-mark sebagai deleted** saat dibuat +- Query dengan filter `deletedAt: null` tidak akan dapat data baru +- Soft delete logic tidak bekerja sama sekali +- Data inconsistency antara `deletedAt` (set) dan `isActive` (true) + +**Severity:** 🔴 **CRITICAL** - Ini adalah bug yang sama seperti di Profil Desa dan Pengumuman + +**Solusi:** +```prisma +model GalleryFoto { + id String @id @default(cuid()) + name String + deletedAt DateTime? // ✅ Nullable, tanpa default + isActive Boolean @default(true) +} + +model GalleryVideo { + id String @id @default(cuid()) + name String + deletedAt DateTime? // ✅ Nullable, tanpa default + isActive Boolean @default(true) +} +``` + +**Migration Required:** +```bash +bunx prisma migrate dev --name fix_deleted_at_default +# atau +bunx prisma db push + +# Data cleanup +UPDATE "GalleryFoto" SET "deletedAt" = NULL WHERE "isActive" = true; +UPDATE "GalleryVideo" SET "deletedAt" = NULL WHERE "isActive" = true; +``` + +--- + +### 2. API - File Orphaning Saat Create Gagal + +**File:** `src/app/admin/(dashboard)/desa/gallery/foto/create/page.tsx` + +```typescript +// Line 78-88 +const res = await ApiFetch.api.fileStorage.create.post({ + file, + name: file.name, +}); +const uploaded = res.data?.data; +if (!uploaded?.id) { + return toast.error('Gagal mengunggah gambar, silakan coba lagi'); +} +FotoState.create.form.imagesId = uploaded.id; +await FotoState.create.create(); // ❌ Jika ini gagal, file sudah ter-upload +``` + +**Dampak:** +- File ter-upload ke server tapi gallery tidak terbuat +- **Orphaned files** menumpuk di database dan filesystem +- Storage waste, tidak ada cleanup mechanism + +**Severity:** 🔴 **HIGH** - Data integrity issue + +**Solusi:** + +**Option A - Transaction di API:** +```typescript +// Di API create.ts +try { + // Validate fileStorage exists first + const fileStorage = await prisma.fileStorage.findUnique({ + where: { id: body.imagesId } + }); + + if (!fileStorage) { + return Response.json({ + success: false, + message: "File tidak ditemukan" + }, { status: 404 }); + } + + const gallery = await prisma.galleryFoto.create({ + data: { + name: body.name, + deskripsi: body.deskripsi, + imagesId: body.imagesId, + } + }); + + return { success: true, data: gallery }; +} catch (error) { + // Rollback file jika create gagal + if (body.imagesId) { + await prisma.fileStorage.delete({ where: { id: body.imagesId } }).catch(() => {}); + } + throw error; +} +``` + +**Option B - Cleanup di Frontend:** +```typescript +try { + const uploaded = await uploadFile(file); + const result = await createGallery({ ...imagesId: uploaded.id }); + + if (!result.success) { + // Cleanup orphaned file + await deleteFile(uploaded.id); + throw new Error('Create gallery failed'); + } +} catch (error) { + toast.error('Gagal membuat gallery'); +} +``` + +--- + +### 3. API - Old File Dihapus Sebelum Update Confirmed + +**File:** `src/app/api/[[...slugs]]/_lib/desa/gallery/foto/updt.ts` + +```typescript +// Line 47-58 +if (existing.imagesId && existing.imagesId !== body.imagesId) { + const oldImage = existing.imageGalleryFoto; + if (oldImage) { + const filePath = path.join(oldImage.path, oldImage.name); + await fs.unlink(filePath); // ❌ File dihapus DULU + await prisma.fileStorage.delete({ + where: { id: oldImage.id }, + }); + } +} + +// Baru update data +const updated = await prisma.galleryFoto.update({ + where: { id }, + data: { ... } +}); +``` + +**Dampak:** +- Jika `prisma.galleryFoto.update()` gagal, **old file sudah terhapus** +- **DATA LOSS** - Gallery tidak punya image sama sekali +- Tidak ada rollback mechanism + +**Severity:** 🔴 **HIGH** - Data loss risk + +**Solusi:** +```typescript +// Update data DULU, baru hapus old file +const updated = await prisma.galleryFoto.update({ + where: { id }, + data: { + name: body.name, + deskripsi: body.deskripsi, + imagesId: body.imagesId, + }, + include: { imageGalleryFoto: true } +}); + +// Hapus old file SETELAH update berhasil +if (existing.imagesId && existing.imagesId !== body.imagesId) { + const oldImage = existing.imageGalleryFoto; + if (oldImage) { + try { + const filePath = path.join(oldImage.path, oldImage.name); + await fs.unlink(filePath); + await prisma.fileStorage.delete({ + where: { id: oldImage.id }, + }); + } catch (error) { + console.error('Failed to delete old file:', error); + // Log error tapi tidak rollback karena update sudah berhasil + } + } +} +``` + +--- + +### 4. API - Tidak Ada Authentication/Authorization + +**File:** Semua API endpoints di `/src/app/api/[[...slugs]]/_lib/desa/gallery/` + +```typescript +export default async function fotoCreate(context: Context) { + // ❌ Tidak ada validasi session/user + const body = await context.body; + + // Langsung proses create + await prisma.galleryFoto.create({ ... }); +} +``` + +**Dampak:** +- **Siapa saja bisa upload/delete foto/video** jika tahu endpoint +- Tidak ada audit trail siapa yang upload/delete +- Security risk untuk production + +**Severity:** 🔴 **HIGH** - Security vulnerability + +**Solusi:** +```typescript +import { getSession } from '@/lib/auth'; + +export default async function fotoCreate(context: Context) { + const session = await getSession(); + + if (!session || !session.user) { + return Response.json({ + success: false, + message: "Unauthorized" + }, { status: 401 }); + } + + // Check role/permission jika perlu + if (!session.user.menuIds?.includes('gallery')) { + return Response.json({ + success: false, + message: "Forbidden" + }, { status: 403 }); + } + + const body = await context.body; + // ... lanjut proses +} +``` + +--- + +### 5. API - Tidak Ada Input Validation + +**File:** `src/app/api/[[...slugs]]/_lib/desa/gallery/foto/create.ts` + +```typescript +// Line 13-23 +await prisma.galleryFoto.create({ + data: { + name: body.name, // ❌ Tidak ada validasi length + deskripsi: body.deskripsi, // ❌ Tidak ada sanitasi XSS + imagesId: body.imagesId, // ❌ Tidak cek apakah FileStorage ada + }, +}); +``` + +**Dampak:** +- User bisa input name sangat panjang (bisa break UI/database) +- XSS attack via `deskripsi` field (rich text editor) +- Bisa create gallery dengan `imagesId` yang tidak valid + +**Severity:** 🔴 **HIGH** - Security & data integrity + +**Solusi:** +```typescript +// Validasi input +const { name, deskripsi, imagesId } = await context.body; + +// Check length +if (!name || name.length > 255) { + return Response.json({ + success: false, + message: "Name maksimal 255 karakter" + }, { status: 400 }); +} + +// Check duplikasi +const existing = await prisma.galleryFoto.findFirst({ + where: { name, isActive: true } +}); + +if (existing) { + return Response.json({ + success: false, + message: "Name sudah digunakan" + }, { status: 400 }); +} + +// Check fileStorage exists +const fileStorage = await prisma.fileStorage.findUnique({ + where: { id: imagesId } +}); + +if (!fileStorage) { + return Response.json({ + success: false, + message: "File tidak ditemukan" + }, { status: 404 }); +} + +// Sanitize HTML (gunakan library seperti DOMPurify di server) +const sanitizedDeskripsi = sanitizeHtml(deskripsi); + +// Create +const gallery = await prisma.galleryFoto.create({ + data: { + name, + deskripsi: sanitizedDeskripsi, + imagesId, + } +}); +``` + +--- + +## 🟡 MEDIUM PRIORITY ISSUES + +### 6. UI - Dead Code (youtubeEmbed.tsx Tidak Digunakan) + +**File:** `src/app/admin/(dashboard)/desa/gallery/lib/youtubeEmbed.tsx` + +```typescript +// Component ini TIDAK digunakan di mana pun +export function YoutubeEmbed({ url, ... }: Props) { + // ... component code +} +``` + +**Dampak:** +- Dead code menumpuk (120+ baris tidak digunakan) +- Confusing untuk developer baru +- Maintenance overhead + +**Severity:** 🟡 **MEDIUM** - Code quality issue + +**Solusi:** +- **Option A:** Hapus file ini jika memang tidak diperlukan +- **Option B:** Gunakan component ini di semua halaman (create, edit, detail) untuk konsistensi + +**Recommendation:** Hapus, karena setiap halaman sudah implementasi iframe manual dengan cara berbeda. + +--- + +### 7. UI - Inconsistent Styling Foto vs Video + +**File:** `foto/page.tsx` vs `video/page.tsx` + +```typescript +// foto/page.tsx - Line 58 + // ✅ Responsive padding + +// video/page.tsx - Line 60 + // ❌ Hardcoded padding +``` + +**Dampak:** Inconsistent spacing antara foto dan video pages. + +**Severity:** 🟡 **MEDIUM** - UX inconsistency + +**Solusi:** +```typescript +// video/page.tsx + // ✅ Konsisten dengan foto +``` + +--- + +### 8. UI - Memory Leak Potential (createObjectURL) + +**File:** `src/app/admin/(dashboard)/desa/gallery/foto/create/page.tsx` + +```typescript +// Line 59-62 +useEffect(() => { + if (file) { + const url = URL.createObjectURL(file); + setPreviewImage(url); + } +}, [file]); + +// Line 47-52 +const resetForm = () => { + FotoState.create.form = { name: '', deskripsi: '', imagesId: '' }; + setPreviewImage(null); + setFile(null); + // ❌ URL.revokeObjectURL() tidak dipanggil +}; +``` + +**Dampak:** +- Memory leak jika user upload banyak gambar tanpa refresh +- Browser bisa crash setelah banyak createObjectURL tidak di-cleanup + +**Severity:** 🟡 **MEDIUM** - Performance issue + +**Solusi:** +```typescript +// Cleanup saat unmount atau file berubah +useEffect(() => { + if (file) { + const url = URL.createObjectURL(file); + setPreviewImage(url); + + return () => { + URL.revokeObjectURL(url); // ✅ Cleanup + }; + } +}, [file]); + +// Cleanup saat reset +const resetForm = () => { + if (previewImage) { + URL.revokeObjectURL(previewImage); // ✅ Cleanup + } + FotoState.create.form = { name: '', deskripsi: '', imagesId: '' }; + setPreviewImage(null); + setFile(null); +}; +``` + +--- + +### 9. State - Error Handling Tidak Konsisten + +**File:** `src/app/admin/(dashboard)/_state/desa/gallery.ts` + +```typescript +// Line 39-53 (foto.create) +async create() { + try { + const res = await ApiFetch.api.desa.gallery.foto["create"].post(foto.create.form); + if (res.status === 200) { + foto.findMany.load(); + return toast.success("Foto berhasil disimpan!"); + } + return toast.error("Gagal menyimpan foto"); + } catch (error) { + console.log((error as Error).message); + // ❌ Error di-catch tapi tidak ada toast error notification + } +} + +// Line 91-107 (foto.findUnique) +async load(id: string) { + try { + const res = await fetch(`/api/desa/gallery/foto/${id}`); + if (res.ok) { + const data = await res.json(); + foto.findUnique.data = data.data ?? null; + } + } catch (error) { + console.error("Error fetching foto:", error); + // ❌ Tidak ada error toast notification + } +} + +// Line 205-227 (foto.findRecent) +async load() { + try { + // ... + } catch (error) { + console.error("Gagal fetch foto recent:", error); + // ❌ Tidak ada error toast notification + } +} +``` + +**Dampak:** +- User tidak tahu ada error (silent failure) +- UX buruk (loading forever tanpa feedback) +- Sulit debug production issues + +**Severity:** 🟡 **MEDIUM** - UX issue + +**Solusi:** +```typescript +async create() { + try { + const res = await ApiFetch.api.desa.gallery.foto["create"].post(foto.create.form); + if (res.status === 200) { + foto.findMany.load(); + return toast.success("Foto berhasil disimpan!"); + } + return toast.error("Gagal menyimpan foto"); + } catch (error) { + const errorMessage = error instanceof Error ? error.message : 'Unknown error'; + console.error('Create foto failed:', errorMessage); + toast.error(`Gagal menyimpan foto: ${errorMessage}`); // ✅ Show error + } +} +``` + +--- + +### 10. State - `findMany.load()` Dipanggil Tanpa Parameter + +**File:** `src/app/admin/(dashboard)/_state/desa/gallery.ts` + +```typescript +// Line 47 (foto.create) +async create() { + // ... + if (res.status === 200) { + foto.findMany.load(); // ❌ Tanpa parameter (default page=1, limit=10) + return toast.success("Foto berhasil disimpan!"); + } +} + +// Line 119 (foto.delete) +async byId(id: string) { + // ... + if (response.ok) { + toast.success(result.message || "Foto berhasil dihapus"); + await foto.findMany.load(); // ❌ Tanpa parameter + } +} +``` + +**Dampak:** +- Jika user di page 5, setelah create/delete refresh ke page 1 +- User bingung kenapa data hilang (padahal masih ada, cuma page berubah) + +**Severity:** 🟡 **MEDIUM** - UX issue + +**Solusi:** +```typescript +// Simpan current pagination state +let currentPage = 1; +let currentLimit = 10; +let currentSearch = ''; + +// Set parameter saat load +async load(page = 1, limit = 10, search = '') { + currentPage = page; + currentLimit = limit; + currentSearch = search; + // ... load data +} + +// Gunakan current state saat refresh +async create() { + // ... + if (res.status === 200) { + await foto.findMany.load(currentPage, currentLimit, currentSearch); // ✅ Pass current params + toast.success("Foto berhasil disimpan!"); + } +} +``` + +--- + +### 11. API - Video Search Tidak Include `deskripsi` + +**File:** `src/app/api/[[...slugs]]/_lib/desa/gallery/video/find-many.ts` + +```typescript +// Line 18-21 +if (search) { + where.OR = [ + { name: { contains: search, mode: 'insensitive' } } + // ❌ deskripsi tidak di-include + ]; +} +``` + +**Bandingkan dengan Foto:** +```typescript +// foto/find-many.ts - Line 20-26 +if (search) { + where.OR = [ + { name: { contains: search, mode: 'insensitive' } }, + { deskripsi: { contains: search, mode: 'insensitive' } } // ✅ Include deskripsi + ]; +} +``` + +**Dampak:** +- User tidak bisa search video berdasarkan deskripsi +- Inconsistent behavior antara foto dan video + +**Severity:** 🟡 **MEDIUM** - Feature inconsistency + +**Solusi:** +```typescript +if (search) { + where.OR = [ + { name: { contains: search, mode: 'insensitive' } }, + { deskripsi: { contains: search, mode: 'insensitive' } } // ✅ Add deskripsi + ]; +} +``` + +--- + +### 12. UI - Skeleton Height Terlalu Besar + +**File:** `src/app/admin/(dashboard)/desa/gallery/video/page.tsx` + +```typescript +// Line 73-77 +if (loading || !data) { + return ( + + // ❌ Terlalu besar + + ); +} +``` + +**Dampak:** Skeleton mengambil hampir seluruh layar, UX buruk. + +**Severity:** 🟡 **MEDIUM** - UX issue + +**Solusi:** +```typescript + // ✅ Lebih reasonable +``` + +--- + +### 13. UI - Duplicate `convertToEmbedUrl` Function + +**File:** `src/app/admin/(dashboard)/desa/gallery/video/[id]/page.tsx` + +```typescript +// Line 106-118 +function convertToEmbedUrl(youtubeUrl: string): string { + try { + const url = new URL(youtubeUrl); + const videoId = url.searchParams.get("v"); + if (!videoId) return youtubeUrl; + return `https://www.youtube.com/embed/${videoId}`; + } catch (err) { + return youtubeUrl; + } +} +``` + +**Padahal sudah ada di:** `lib/youtube-utils.ts` +```typescript +export function convertYoutubeUrlToEmbed(url: string) { + const videoIdMatch = url.match( + /(?:youtube\.com\/(?:watch\?v=|embed\/)|youtu\.be\/)([a-zA-Z0-9_-]{11})/ + ); + return videoIdMatch ? `https://www.youtube.com/embed/${videoIdMatch[1]}` : null; +} +``` + +**Dampak:** +- Duplicate code (violation DRY principle) +- Logic berbeda (page.tsx hanya support watch URL, utils.ts support multiple formats) +- Maintenance overhead + +**Severity:** 🟡 **MEDIUM** - Code quality issue + +**Solusi:** +```typescript +// Import dari utils +import { convertYoutubeUrlToEmbed } from '../../lib/youtube-utils'; + +// Gunakan function yang sudah ada +const embedLink = convertYoutubeUrlToEmbed(data.linkVideo); +``` + +--- + +### 14. Utils - YouTube Shorts URL Tidak Disupport + +**File:** `src/app/admin/(dashboard)/desa/gallery/lib/youtube-utils.ts` + +```typescript +export function convertYoutubeUrlToEmbed(url: string) { + const videoIdMatch = url.match( + /(?:youtube\.com\/(?:watch\?v=|embed\/)|youtu\.be\/)([a-zA-Z0-9_-]{11})/ + ); + // ❌ Regex tidak support youtube.com/shorts/VIDEO_ID + return videoIdMatch ? `https://www.youtube.com/embed/${videoIdMatch[1]}` : null; +} +``` + +**Dampak:** User tidak bisa input YouTube Shorts URL (format populer). + +**Severity:** 🟡 **MEDIUM** - Feature gap + +**Solusi:** +```typescript +export function convertYoutubeUrlToEmbed(url: string) { + const videoIdMatch = url.match( + /(?:youtube\.com\/(?:watch\?v=|embed\/|shorts\/)|youtu\.be\/)([a-zA-Z0-9_-]{11})/ + ); + // ✅ Added shorts\/ support + return videoIdMatch ? `https://www.youtube.com/embed/${videoIdMatch[1]}` : null; +} +``` + +--- + +## 🟢 LOW PRIORITY ISSUES + +### 15. UI - Redundant Variable (`filteredData`) + +**File:** `src/app/admin/(dashboard)/desa/gallery/foto/page.tsx` + +```typescript +// Line 78-79 +const filteredData = data || []; +// ❌ Variable ini redundant, data sudah difilter di backend +``` + +**Dampak:** Minor code clutter. + +**Severity:** 🟢 **LOW** - Code cleanliness + +**Solusi:** Hapus variable, gunakan langsung `data || []`. + +--- + +### 16. UI - useEffect Redundant di layoutTabs.tsx + +**File:** `src/app/admin/(dashboard)/desa/gallery/lib/layoutTabs.tsx` + +```typescript +// Line 35-40 +useEffect(() => { + const match = tabs.find(tab => tab.href === pathname) + if (match) { + setActiveTab(match.value) + } +}, [pathname]) +// ❌ Redundant karena sudah ada logic serupa di handleTabChange +``` + +**Dampak:** Minor performance overhead. + +**Severity:** 🟢 **LOW** - Code quality + +**Solusi:** Hapus useEffect jika tidak diperlukan. + +--- + +### 17. State - `findRecent` Tidak Digunakan di UI + +**File:** `src/app/admin/(dashboard)/_state/desa/gallery.ts` + +```typescript +// Line 205-227 +foto: { + findRecent: { + loading: false, + data: [] as any[], + async load() { + // ... fetch recent photos + } + } +} +``` + +**Dampak:** Dead code di state management. + +**Severity:** 🟢 **LOW** - Code cleanliness + +**Solusi:** +- Option A: Hapus jika memang tidak diperlukan +- Option B: Implementasi di UI (misal: widget "Recent Photos" di dashboard) + +--- + +### 18. State - Mix State Mutation dan Return Value + +**File:** `src/app/admin/(dashboard)/_state/desa/gallery.ts` + +```typescript +// Line 138-203 (foto.update) +async load(id: string) { + // ... fetch GET + if (result?.success) { + const data = result.data; + this.id = data.id; + this.form = { ... }; + return data; // ❌ Mix mutation + return value (confusing API) + } +} +``` + +**Dampak:** Confusing API, tidak jelas apakah caller harus gunakan return value atau akses state langsung. + +**Severity:** 🟢 **LOW** - Code quality + +**Solusi:** +```typescript +// Option A: Hanya mutation (recommended) +async load(id: string) { + // ... fetch GET + if (result?.success) { + const data = result.data; + this.id = data.id; + this.form = { ... }; + // No return value + } +} + +// Usage +await foto.update.load(id); +const formData = foto.update.form; // Akses dari state + +// Option B: Hanya return value +async load(id: string) { + // ... fetch GET + if (result?.success) { + return result.data; + } + return null; +} + +// Usage +const data = await foto.update.load(id); +``` + +--- + +## ✅ YANG SUDAH BAIK + +### **Schema:** +- ✅ Relasi GalleryFoto ke FileStorage sudah benar +- ✅ Kedua model memiliki soft delete fields (`deletedAt`, `isActive`) +- ✅ Audit trail dengan `createdAt` dan `updatedAt` + +### **API:** +- ✅ CRUD lengkap untuk Foto dan Video +- ✅ Pagination support dengan `page`, `limit` +- ✅ Search functionality (foto: name + deskripsi, video: name only) +- ✅ Soft delete di-support via `isActive` flag di find-many +- ✅ File cleanup saat delete foto (hapus filesystem + database) +- ✅ Error handling ada di semua endpoints +- ✅ Response format konsisten: `{ success, message, data }` + +### **UI/UX:** +- ✅ Responsive design (desktop table + mobile cards) +- ✅ Loading states dan skeleton +- ✅ Toast notifications untuk feedback +- ✅ Form validation (name, deskripsi, image required) +- ✅ Dropzone untuk upload gambar dengan preview +- ✅ File size limit (5MB) dan format validation +- ✅ Rich text editor untuk deskripsi +- ✅ YouTube URL conversion dengan embed preview +- ✅ Search dengan debounce (1000ms) +- ✅ Modal konfirmasi hapus +- ✅ Empty state message +- ✅ Reset form functionality + +### **State Management:** +- ✅ Valtio proxy untuk global state +- ✅ Separate state untuk foto dan video +- ✅ CRUD operations lengkap +- ✅ Form validation dengan Zod +- ✅ Pagination state management +- ✅ Loading states + +### **Utilities:** +- ✅ YouTube URL conversion support multiple formats (watch, embed, youtu.be) +- ✅ Reusable component pattern (youtubeEmbed.tsx - meski tidak digunakan) + +--- + +## 📊 Metrics + +| Aspek | Score | Keterangan | +|-------|-------|------------| +| **Schema Design** | 6/10 | Good structure, tapi ada critical bug di deletedAt | +| **API Design** | 6/10 | RESTful, tapi tidak ada auth & validation | +| **API Security** | 4/10 | Tidak ada authentication, XSS risk | +| **UI/UX** | 7.5/10 | Responsive, comprehensive features | +| **State Management** | 6.5/10 | Valtio works well, inconsistency di error handling | +| **Code Quality** | 6/10 | Dead code, duplicate code, memory leak potential | + +**Overall Score: 6/10** - **Needs Improvement** + +--- + +## 🎯 Action Plan + +### Week 1 (Critical Fixes) 🔴 + +- [ ] **URGENT:** Fix `deletedAt @default(now())` di schema +- [ ] **URGENT:** Fix file orphaning saat create gagal +- [ ] **URGENT:** Fix old file delete sebelum update confirmed +- [ ] **URGENT:** Tambahkan authentication di semua API endpoints +- [ ] **URGENT:** Tambahkan input validation di API + +### Week 2 (High Priority) 🟡 + +- [ ] Tambahkan rollback mechanism untuk operasi file +- [ ] Fix error handling konsisten (semua catch show toast) +- [ ] Fix `findMany.load()` pass current pagination params +- [ ] Tambahkan video search include deskripsi +- [ ] Fix memory leak (createObjectURL cleanup) + +### Week 3 (Polish) 🟢 + +- [ ] Hapus dead code (youtubeEmbed.tsx, findRecent) +- [ ] Konsistensi styling foto vs video pages +- [ ] Hapus duplicate convertToEmbedUrl function +- [ ] Tambahkan support YouTube Shorts URL +- [ ] Fix skeleton height +- [ ] Fix redundant useEffect di layoutTabs + +--- + +## 📝 Technical Notes + +### **Database Migration:** + +Fix deletedAt default: +```bash +# Generate migration +bunx prisma migrate dev --name fix_gallery_deleted_at + +# Atau jika tidak pakai migrate +bunx prisma db push + +# Data cleanup +UPDATE "GalleryFoto" SET "deletedAt" = NULL WHERE "isActive" = true; +UPDATE "GalleryVideo" SET "deletedAt" = NULL WHERE "isActive" = true; +``` + +### **File Orphan Prevention:** + +Implementasi transaction pattern di API: +```typescript +// Di API create.ts +export default async function fotoCreate(context: Context) { + try { + // Validate fileStorage exists + const fileStorage = await prisma.fileStorage.findUnique({ + where: { id: body.imagesId } + }); + + if (!fileStorage) { + return Response.json({ + success: false, + message: "File tidak ditemukan" + }, { status: 404 }); + } + + // Create gallery dengan transaction + const gallery = await prisma.galleryFoto.create({ + data: { + name: body.name, + deskripsi: body.deskripsi, + imagesId: body.imagesId, + } + }); + + return { success: true, data: gallery }; + } catch (error) { + // Rollback file jika create gagal + if (body.imagesId) { + await prisma.fileStorage.delete({ + where: { id: body.imagesId } + }).catch(() => {}); + } + throw error; + } +} +``` + +### **Memory Leak Prevention:** + +```typescript +// Cleanup createObjectURL +useEffect(() => { + if (file) { + const url = URL.createObjectURL(file); + setPreviewImage(url); + + return () => { + URL.revokeObjectURL(url); // ✅ Cleanup + }; + } +}, [file]); + +// Cleanup saat reset +const resetForm = () => { + if (previewImage) { + URL.revokeObjectURL(previewImage); + } + // ... +}; +``` + +### **YouTube Shorts Support:** + +```typescript +// youtube-utils.ts +export function convertYoutubeUrlToEmbed(url: string) { + const videoIdMatch = url.match( + /(?:youtube\.com\/(?:watch\?v=|embed\/|shorts\/)|youtu\.be\/)([a-zA-Z0-9_-]{11})/ + ); + return videoIdMatch + ? `https://www.youtube.com/embed/${videoIdMatch[1]}` + : null; +} + +// Test cases +convertYoutubeUrlToEmbed('https://youtube.com/watch?v=VIDEO_ID'); // ✅ +convertYoutubeUrlToEmbed('https://youtu.be/VIDEO_ID'); // ✅ +convertYoutubeUrlToEmbed('https://youtube.com/embed/VIDEO_ID'); // ✅ +convertYoutubeUrlToEmbed('https://youtube.com/shorts/VIDEO_ID'); // ✅ NEW +``` + +--- + +## 📚 References + +- [Prisma Transactions](https://www.prisma.io/docs/concepts/components/prisma-client/transactions) +- [Prisma Soft Delete Pattern](https://www.prisma.io/docs/concepts/components/prisma-client/soft-delete) +- [URL.createObjectURL() Memory Management](https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL#memory_management) +- [Mantine Skeleton Documentation](https://mantine.dev/core/skeleton/) +- [React Toastify Documentation](https://fkhadra.github.io/react-toastify/) + +--- + +## 📈 Comparison dengan QC Sebelumnya + +| Aspek | Profil Desa | Potensi Desa | Berita Desa | Pengumuman | **Gallery** | +|-------|-------------|--------------|-------------|------------|-------------| +| Schema | 6/10 | 7/10 | 8/10 | 7/10 | **6/10** | +| API Security | 4/10 | 6/10 | 6/10 | 6/10 | **4/10** | +| API Design | 7/10 | 8/10 | 7.5/10 | 7/10 | **6/10** | +| UI/UX | 8/10 | 8.5/10 | 8/10 | 7.5/10 | **7.5/10** | +| State Mgmt | 7/10 | 8/10 | 8/10 | 7/10 | **6.5/10** | +| Code Quality | 7/10 | 7.5/10 | 7/10 | 6.5/10 | **6/10** | +| **Overall** | **6.5/10** | **7.5/10** | **7/10** | **6.5/10** | **6/10** | + +**Gallery** memiliki score **terendah** karena: +- ❌ Critical bug `deletedAt @default(now())` (sama seperti Profil & Pengumuman) +- ❌ File orphaning issue (data integrity) +- ❌ Old file dihapus sebelum update confirmed (data loss risk) +- ❌ Tidak ada authentication di API +- ❌ Dead code (youtubeEmbed.tsx tidak digunakan) +- ❌ Memory leak potential +- ❌ Duplicate code (convertToEmbedUrl) + +Tapi Gallery punya **UI/UX yang bagus** (7.5/10) dengan: +- ✅ Upload gambar dengan dropzone & preview +- ✅ YouTube embed conversion +- ✅ Rich text editor +- ✅ Responsive design +- ✅ Comprehensive validation + +--- + +**Dibuat oleh:** QC Automation +**Review Status:** ⏳ Menunggu Review Developer +**Next Review:** Setelah implementasi fixes diff --git a/QC/DESA/summary-qc-layanan-desa.md b/QC/DESA/summary-qc-layanan-desa.md new file mode 100644 index 00000000..f4f80dfa --- /dev/null +++ b/QC/DESA/summary-qc-layanan-desa.md @@ -0,0 +1,882 @@ +# Quality Control Report - Layanan Desa Admin + +**Lokasi:** `/src/app/admin/(dashboard)/desa/layanan/` +**Tanggal QC:** 25 Februari 2026 +**Status:** ⚠️ **Needs Improvement** (ada issue critical dan incomplete features) + +--- + +## 📋 Ringkasan Eksekutif + +Halaman Layanan Desa memiliki **5 modul** dengan implementasi yang **bervariasi**. Ditemukan **15 issue** dengan rincian: + +- 🔴 **High Priority:** 4 issue +- 🟡 **Medium Priority:** 5 issue +- 🟢 **Low Priority:** 6 issue + +**Overall Score: 6.5/10** - Needs Improvement + +--- + +## 📁 Struktur File yang Diperiksa + +``` +/src/app/admin/(dashboard)/desa/layanan/ +├── layout.tsx +├── ajukan_permohonan/ +│ ├── page.tsx # List permohonan dengan search & pagination +│ └── [id]/ +│ ├── page.tsx # Detail permohonan +│ └── edit/ +│ └── page.tsx # Edit permohonan +├── pelayanan_penduduk_non_permanent/ +│ ├── page.tsx # ⚠️ Preview only (hardcoded ID) +│ └── [id]/ +│ └── page.tsx # Edit form +├── pelayanan_perizinan_berusaha/ +│ ├── page.tsx # ⚠️ Preview only dengan stepper (hardcoded ID) +│ └── [id]/ +│ └── page.tsx # Edit form +├── pelayanan_surat_keterangan/ +│ ├── page.tsx # List surat keterangan +│ ├── create/ +│ │ └── page.tsx # Create dengan dual image upload +│ └── [id]/ +│ ├── page.tsx # Detail +│ └── edit/ +│ └── page.tsx # Edit dengan dual image upload +└── pelayanan_telunjuk_sakti_desa/ + ├── page.tsx # List telunjuk sakti desa + ├── create/ + │ └── page.tsx # Create form + └── [id]/ + ├── page.tsx # Detail + └── edit/ + └── page.tsx # Edit form +``` + +**File Terkait:** +- State: `/src/app/admin/(dashboard)/_state/desa/layananDesa.ts` (1050 baris) +- API: `/src/app/api/[[...slugs]]/_lib/desa/layanan/` (5 modul) +- Schema: `/prisma/schema.prisma` (5 models) + +--- + +## 🔴 HIGH PRIORITY ISSUES + +### 1. API - Inconsistent Delete Endpoint + +**File:** `src/app/api/[[...slugs]]/_lib/desa/layanan/pelayanan_telunjuk_sakti_desa/index.ts` + +```typescript +// Line 38-40 +.delete("/:id", pelayananTelunjukSaktiDesaDelete) // ❌ Inconsistent +``` + +**Bandingkan dengan modul lain:** +```typescript +// pelayanan_surat_keterangan/index.ts +.delete("/del/:id", pelayananSuratKeteranganDelete) // ✅ Consistent + +// pelayanan_surat_keterangan/index.ts line 34 +.delete("/del/:id", pelayananSuratKeteranganDelete) +``` + +**State Management memanggil:** +```typescript +// layananDesa.ts line 501 +const response = await fetch(`/api/desa/layanan/pelayanantelunjuksaktidesa/del/${id}`, { + method: "DELETE", +}); +// ❌ State panggil /del/${id} tapi API endpoint adalah /:id +``` + +**Dampak:** +- Delete tidak akan bekerja (404 Not Found) +- User tidak bisa hapus data +- Data inconsistency + +**Severity:** 🔴 **HIGH** - Feature broken + +**Solusi:** +```typescript +// File: pelayanan_telunjuk_sakti_desa/index.ts +.delete("/del/:id", pelayananTelunjukSaktiDesaDelete) // ✅ Consistent dengan modul lain +``` + +--- + +### 2. API - Missing Endpoints (INCOMPLETE FEATURE) + +**File:** `src/app/api/[[...slugs]]/_lib/desa/layanan/pelayanan_perizinan_berusaha/` + +``` +Current files: +├── findUnique.ts ✅ +└── updt.ts ✅ + +Missing files: +❌ find-many.ts # Tidak ada list dengan pagination +❌ create.ts # Tidak ada create +❌ del.ts # Tidak ada delete +``` + +**Same issue untuk:** `pelayanan_penduduk_non_permanen/` + +**Dampak:** +- **Tidak ada list page dengan pagination** - hanya preview hardcoded +- **Tidak ada create functionality** - data tidak bisa ditambah +- **Tidak ada delete functionality** - data tidak bisa dihapus +- **Feature incomplete** - hanya bisa edit data yang sudah ada + +**Severity:** 🔴 **HIGH** - Incomplete feature + +**Solusi:** + +**Create `find-many.ts`:** +```typescript +import { prisma } from "@/lib/prisma"; +import { Context } from "elysia"; + +export default async function findMany(context: Context) { + try { + const { page = 1, limit = 10, search = "" } = context.query; + const skip = (Number(page) - 1) * Number(limit); + + const where: any = { isActive: true }; + + if (search) { + where.OR = [ + { name: { contains: search, mode: 'insensitive' } }, + { deskripsi: { contains: search, mode: 'insensitive' } } + ]; + } + + const [data, total] = await Promise.all([ + prisma.pelayananPerizinanBerusaha.findMany({ + where, + skip, + take: Number(limit), + orderBy: { createdAt: 'desc' } + }), + prisma.pelayananPerizinanBerusaha.count({ where }) + ]); + + return { + success: true, + message: "Data retrieved successfully", + data, + pagination: { + page: Number(page), + limit: Number(limit), + total, + totalPages: Math.ceil(total / Number(limit)) + } + }; + } catch (error) { + console.error("Error fetching data:", error); + return { success: false, message: "Failed to fetch data" }; + } +} +``` + +**Create `create.ts`:** +```typescript +import { prisma } from "@/lib/prisma"; +import { Context } from "elysia"; + +export default async function create(context: Context) { + try { + const body = await context.body; + + // Validation + if (!body.name || !body.deskripsi || !body.link) { + return Response.json({ + success: false, + message: "All fields are required" + }, { status: 400 }); + } + + const created = await prisma.pelayananPerizinanBerusaha.create({ + data: { + name: body.name, + deskripsi: body.deskripsi, + link: body.link, + } + }); + + return { + success: true, + message: "Data created successfully", + data: created + }; + } catch (error) { + console.error("Error creating data:", error); + return { success: false, message: "Failed to create data" }; + } +} +``` + +**Create `del.ts`:** +```typescript +import { prisma } from "@/lib/prisma"; +import { Context } from "elysia"; + +export default async function del(context: Context) { + try { + const id = context.params?.id as string; + + // Soft delete + await prisma.pelayananPerizinanBerusaha.update({ + where: { id }, + data: { + deletedAt: new Date(), + isActive: false + } + }); + + return { + success: true, + message: "Data deleted successfully" + }; + } catch (error) { + console.error("Error deleting data:", error); + return { success: false, message: "Failed to delete data" }; + } +} +``` + +**Update API route index:** +```typescript +// index.ts +import findMany from "./find-many"; +import create from "./create"; +import del from "./del"; + +export const pelayananPerizinanBerusahaRoutes = (app: Elysia) => + app + .get("/api/desa/layanan/pelayananperizinanberusaha/find-many", findMany) + .post("/api/desa/layanan/pelayananperizinanberusaha/create", create) + .delete("/api/desa/layanan/pelayananperizinanberusaha/del/:id", del); +``` + +--- + +### 3. UI - Hardcoded ID 'edit' (CRITICAL) + +**File:** `src/app/admin/(dashboard)/desa/layanan/pelayanan_penduduk_non_permanent/page.tsx` + +```typescript +// Line 22 +const { data, loading } = useSnapshot(pelayananPendudukNonPermanenState.findUnique); + +useEffect(() => { + pelayananPendudukNonPermanenState.findUnique.load('edit'); // ❌ HARDCODED ID +}, []); +``` + +**Same issue di:** `pelayanan_perizinan_berusaha/page.tsx` line 36 + +```typescript +useEffect(() => { + pelayananPerizinanBerusahaState.findUnique.load("edit"); // ❌ HARDCODED ID +}, []); +``` + +**Dampak:** +- Data yang di-load selalu ID `'edit'` (data pertama?) +- Tidak dinamis +- Jika tidak ada data dengan ID `'edit'`, page kosong +- **Ini seharusnya list page, bukan preview single data** + +**Severity:** 🔴 **HIGH** - Logic error + +**Solusi:** + +**Option A - Convert ke List Page (Recommended):** +```typescript +// page.tsx should be a list page with pagination +const { data, loading } = useSnapshot(pelayananPendudukNonPermanenState.findMany); + +useEffect(() => { + pelayananPendudukNonPermanenState.findMany.load(page, limit, search); +}, [page, limit, search]); +``` + +**Option B - Remove Hardcoded Page:** +```typescript +// Jika memang hanya ada 1 data, remove page.tsx +// Direct ke edit page atau detail page +``` + +--- + +### 4. State Management - Wrong Variable Assignment (BUG) + +**File:** `src/app/admin/(dashboard)/_state/desa/layananDesa.ts` + +```typescript +// Line 468-470 +} catch (error) { + console.error("Error fetching telunjuk sakti desa:", error); + suratKeterangan.findMany.total = 0; // ❌ WRONG VARIABLE! + suratKeterangan.findMany.totalPages = 1; // ❌ WRONG VARIABLE! +} +``` + +**Should be:** +```typescript +} catch (error) { + console.error("Error fetching telunjuk sakti desa:", error); + pelayananTelunjukSaktiDesa.findMany.total = 0; // ✅ Correct + pelayananTelunjukSaktiDesa.findMany.totalPages = 1; // ✅ Correct +} +``` + +**Dampak:** +- `pelayananTelunjukSaktiDesa.findMany.total` tidak di-set saat error +- Pagination tidak bekerja dengan benar +- Bisa infinite loading atau wrong pagination display + +**Severity:** 🔴 **HIGH** - Bug + +**Solusi:** Fix variable names immediately. + +--- + +## 🟡 MEDIUM PRIORITY ISSUES + +### 5. State - Missing Validation for `link` Field + +**File:** `src/app/admin/(dashboard)/_state/desa/layananDesa.ts` + +```typescript +// Line 28-32 +const templateTelunjukSaktiDesaForm = z.object({ + name: z.string().min(3, "Nama minimal 3 karakter"), + deskripsi: z.string().min(3, "Deskripsi minimal 3 karakter"), + // ❌ Missing link field validation! +}); +``` + +**Dampak:** +- User bisa submit dengan link kosong atau invalid URL +- Data inconsistency +- Broken links di frontend + +**Severity:** 🟡 **MEDIUM** - Validation gap + +**Solusi:** +```typescript +const templateTelunjukSaktiDesaForm = z.object({ + name: z.string().min(3, "Nama minimal 3 karakter"), + deskripsi: z.string().min(3, "Deskripsi minimal 3 karakter"), + link: z.string().url("Link harus URL yang valid"), // ✅ Add validation +}); +``` + +**Same issue untuk:** `pelayananPerizinanBerusahaForm` + +--- + +### 6. UI - Inconsistent Edit Page Structure + +**Current structure:** + +| Module | Edit Page Location | +|--------|-------------------| +| `ajukan_permohonan` | `[id]/edit/page.tsx` ✅ | +| `pelayanan_surat_keterangan` | `[id]/edit/page.tsx` ✅ | +| `pelayanan_telunjuk_sakti_desa` | `[id]/edit/page.tsx` ✅ | +| `pelayanan_penduduk_non_permanent` | `[id]/page.tsx` ❌ | +| `pelayanan_perizinan_berusaha` | `[id]/page.tsx` ❌ | + +**Dampak:** +- Inconsistent user experience +- Confusing navigation +- Harder to maintain + +**Severity:** 🟡 **MEDIUM** - UX inconsistency + +**Solusi:** +- Move edit logic from `[id]/page.tsx` to `[id]/edit/page.tsx` +- Or convert `[id]/page.tsx` to detail view only + +--- + +### 7. UI - Missing Create Functionality + +**Modules without create:** + +| Module | Create Page | Create API | +|--------|-------------|------------| +| `pelayanan_penduduk_non_permanent` | ❌ | ❌ | +| `pelayanan_perizinan_berusaha` | ❌ | ❌ | + +**Dampak:** +- **Data tidak bisa ditambah** dari admin panel +- Data hanya bisa di-seed dari database atau cara lain +- Feature incomplete + +**Severity:** 🟡 **MEDIUM** - Missing feature + +**Solusi:** +- Create `create/page.tsx` untuk kedua modul +- Add corresponding API endpoints (lihat Issue #2) + +--- + +### 8. API - Inconsistent Response Format + +**Examples:** + +```typescript +// pelayanan_surat_keterangan/create.ts +return { + success: true, + message: "Sukses menambahkan data", + data: created +}; + +// pelayanan_telunjuk_sakti_desa/create.ts +return new Response( + JSON.stringify({ + status: 200, + message: "Sukses menambahkan data", + data: created + }) +); + +// ajukan_permohonan/del.ts +return { + status: 200, + message: "Sukses menghapus data" +}; +``` + +**Dampak:** +- Frontend harus handle multiple response formats +- Confusing untuk developer +- Harder to maintain + +**Severity:** 🟡 **MEDIUM** - Code quality + +**Solusi:** +```typescript +// Standardize response format +return { + success: boolean, + message: string, + data?: any, + // Optional: status code if needed +}; +``` + +--- + +### 9. UI - Client-Side Search Instead of Server-Side + +**File:** `src/app/admin/(dashboard)/desa/layanan/pelayanan_surat_keterangan/page.tsx` + +```typescript +// Line 50-57 +const filteredData = useMemo(() => { + if (!search) return data || []; + return (data || []).filter((item) => + item.name.toLowerCase().includes(search.toLowerCase()) || + item.deskripsi.toLowerCase().includes(search.toLowerCase()) + ); +}, [data, search]); +``` + +**Dampak:** +- Semua data di-load dari server (no server-side filtering) +- Performance issue jika data banyak +- Pagination tidak bekerja dengan benar (filter setelah pagination) + +**Severity:** 🟡 **MEDIUM** - Performance issue + +**Solusi:** +```typescript +// Pass search to API +const load = async (page: number, limit: number, search: string) => { + pelayananSuratKeteranganState.findMany.loading = true; + try { + const res = await ApiFetch.api.desa.layanan.pelayanansuratketerangan['find-many'].get({ + query: { page, limit, search } + }); + // ... + } +}; +``` + +--- + +## 🟢 LOW PRIORITY ISSUES + +### 10. UI - Table Fixed Layout Without Column Widths + +**File:** Multiple list pages + +```typescript + + + + Nama + Deskripsi + Aksi + + +
+``` + +**Dampak:** Column widths tidak konsisten, bisa break layout. + +**Severity:** 🟢 **LOW** - UI polish + +**Solusi:** +```typescript + + + + Nama + Deskripsi + Aksi + + +
+``` + +--- + +### 11. State - Inconsistent Ordering + +**File:** Multiple state files + +```typescript +// ajukan_permohonan/findMany.ts +orderBy: { createdAt: 'asc' } // ❌ Ascending + +// pelayanan_surat_keterangan/find-many.ts +orderBy: { createdAt: 'desc' } // ✅ Descending +``` + +**Dampak:** Inconsistent data display (oldest first vs newest first). + +**Severity:** 🟢 **LOW** - UX consistency + +**Solusi:** Standardize to `orderBy: { createdAt: 'desc' }` for all modules. + +--- + +### 12. UI - Missing Loading States (Some Edit Pages) + +**File:** Some edit pages + +```typescript +useEffect(() => { + state.load(params.id); +}, [params.id]); + +// ❌ No loading state check +return ( +
+ {/* Form fields */} +
+); +``` + +**Dampak:** Form bisa render dengan empty data saat loading. + +**Severity:** 🟢 **LOW** - UX polish + +**Solusi:** +```typescript +const [loading, setLoading] = useState(true); + +useEffect(() => { + state.load(params.id).finally(() => setLoading(false)); +}, [params.id]); + +if (loading) { + return ; +} + +return ( +
+ {/* Form fields */} +
+); +``` + +--- + +### 13. UI - Memory Leak Potential (createObjectURL) + +**File:** Multiple create/edit pages with image upload + +```typescript +useEffect(() => { + if (file) { + const url = URL.createObjectURL(file); + setPreviewImage(url); + } +}, [file]); + +// ❌ No cleanup +``` + +**Dampak:** Memory leak jika user upload banyak gambar. + +**Severity:** 🟢 **LOW** - Performance + +**Solusi:** +```typescript +useEffect(() => { + if (file) { + const url = URL.createObjectURL(file); + setPreviewImage(url); + + return () => { + URL.revokeObjectURL(url); // ✅ Cleanup + }; + } +}, [file]); +``` + +--- + +### 14. Schema - `deletedAt @default(now())` (SAME BUG AS OTHER MODULES) + +**File:** `prisma/schema.prisma` + +```prisma +model PelayananSuratKeterangan { + deletedAt DateTime @default(now()) // ❌ SAME BUG +} + +model PelayananTelunjukSaktiDesa { + deletedAt DateTime @default(now()) // ❌ SAME BUG +} + +model PelayananPerizinanBerusaha { + deletedAt DateTime @default(now()) // ❌ SAME BUG +} + +model PelayananPendudukNonPermanen { + deletedAt DateTime @default(now()) // ❌ SAME BUG +} + +model AjukanPermohonan { + deletedAt DateTime @default(now()) // ❌ SAME BUG +} +``` + +**Dampak:** Record baru langsung ter-mark deleted. + +**Severity:** 🟢 **LOW** - (Actually MEDIUM, tapi sudah documented di QC lain) + +**Solusi:** +```prisma +deletedAt DateTime? // Remove @default(now()) +``` + +--- + +### 15. UI - No Error Boundary + +**File:** No error boundary found + +**Dampak:** Error di component bisa crash entire app. + +**Severity:** 🟢 **LOW** - Code quality + +**Solusi:** +```typescript +// Add Error Boundary di layout.tsx +'use client' +import { Component, ReactNode } from 'react' + +class ErrorBoundary extends Component { + state = { hasError: false } + + static getDerivedStateFromError() { + return { hasError: true } + } + + render() { + if (this.state.hasError) { + return + } + return this.props.children + } +} +``` + +--- + +## ✅ YANG SUDAH BAIK + +### **Schema:** +- ✅ Relasi yang jelas antara `AjukanPermohonan` dan `PelayananSuratKeterangan` +- ✅ Soft delete pattern dengan `deletedAt` dan `isActive` +- ✅ Audit trail dengan `createdAt` dan `updatedAt` +- ✅ Dual image support untuk `PelayananSuratKeterangan` + +### **API:** +- ✅ CRUD lengkap untuk `pelayanan_surat_keterangan` dan `pelayanan_telunjuk_sakti_desa` +- ✅ Pagination support +- ✅ Search functionality +- ✅ Soft delete di-support via `isActive` flag +- ✅ Response format mostly consistent: `{ success, message, data }` + +### **UI/UX:** +- ✅ Responsive design (desktop + mobile) +- ✅ Loading states dan skeleton +- ✅ Toast notifications untuk feedback +- ✅ Form validation comprehensive +- ✅ Dual image upload dengan preview (surat keterangan) +- ✅ Rich text editor untuk deskripsi +- ✅ Search dengan debounce +- ✅ Modal konfirmasi hapus +- ✅ Interactive stepper (perizinan berusaha) +- ✅ Reset form functionality + +### **State Management:** +- ✅ Valtio proxy untuk global state +- ✅ Zod validation schema +- ✅ Loading state management +- ✅ Auto-refresh after CRUD operations + +--- + +## 📊 Metrics + +| Aspek | Score | Keterangan | +|-------|-------|------------| +| **Schema Design** | 7/10 | Good structure, tapi ada bug deletedAt | +| **API Completeness** | 5/10 | 2 modul incomplete (missing endpoints) | +| **API Security** | 5/10 | Tidak ada authentication | +| **UI/UX** | 7.5/10 | Responsive, good features | +| **State Management** | 6.5/10 | Good structure, ada bug | +| **Code Quality** | 6/10 | Inconsistent patterns, hardcoded values | + +**Overall Score: 6.5/10** - **Needs Improvement** + +--- + +## 🎯 Action Plan + +### Week 1 (Critical Fixes) 🔴 + +- [ ] **URGENT:** Fix delete endpoint inconsistency (`pelayanan_telunjuk_sakti_desa`) +- [ ] **URGENT:** Fix state management bug (wrong variable assignment) +- [ ] **URGENT:** Fix hardcoded ID 'edit' di list pages +- [ ] **URGENT:** Create missing API endpoints (`find-many`, `create`, `del`) untuk 2 modul + +### Week 2 (Complete Features) 🟡 + +- [ ] Create `create/page.tsx` untuk 2 modul tanpa create +- [ ] Move edit logic to `[id]/edit/page.tsx` untuk consistency +- [ ] Add validation for `link` field di state +- [ ] Standardize response format di semua API +- [ ] Move client-side search to server-side + +### Week 3 (Polish) 🟢 + +- [ ] Add column widths untuk fixed layout tables +- [ ] Standardize ordering (`createdAt: desc`) +- [ ] Add loading states di semua edit pages +- [ ] Fix memory leak (revoke Object URLs) +- [ ] Add Error Boundary di layout +- [ ] Fix `deletedAt @default(now())` di schema + +--- + +## 📝 Technical Notes + +### **Database Migration:** + +Fix deletedAt default: +```bash +bunx prisma migrate dev --name fix_layanan_deleted_at +# atau +bunx prisma db push + +# Data cleanup +UPDATE "PelayananSuratKeterangan" SET "deletedAt" = NULL WHERE "isActive" = true; +UPDATE "PelayananTelunjukSaktiDesa" SET "deletedAt" = NULL WHERE "isActive" = true; +UPDATE "PelayananPerizinanBerusaha" SET "deletedAt" = NULL WHERE "isActive" = true; +UPDATE "PelayananPendudukNonPermanen" SET "deletedAt" = NULL WHERE "isActive" = true; +UPDATE "AjukanPermohonan" SET "deletedAt" = NULL WHERE "isActive" = true; +``` + +### **API Endpoint Checklist:** + +**pelayanan_perizinan_berusaha:** +- [ ] Create `find-many.ts` +- [ ] Create `create.ts` +- [ ] Create `del.ts` +- [ ] Update `index.ts` dengan routes baru + +**pelayanan_penduduk_non_permanen:** +- [ ] Create `find-many.ts` +- [ ] Create `create.ts` +- [ ] Create `del.ts` +- [ ] Update `index.ts` dengan routes baru + +### **Frontend Checklist:** + +**pelayanan_perizinan_berusaha:** +- [ ] Convert `page.tsx` dari preview ke list page +- [ ] Create `create/page.tsx` +- [ ] Move edit logic ke `[id]/edit/page.tsx` + +**pelayanan_penduduk_non_permanen:** +- [ ] Convert `page.tsx` dari preview ke list page +- [ ] Create `create/page.tsx` +- [ ] Move edit logic ke `[id]/edit/page.tsx` + +--- + +## 📚 References + +- [Prisma Soft Delete Pattern](https://www.prisma.io/docs/concepts/components/prisma-client/soft-delete) +- [Mantine Table Documentation](https://mantine.dev/core/table/) +- [React Toastify Documentation](https://fkhadra.github.io/react-toastify/) +- [Zod Documentation](https://zod.dev/) +- [URL.createObjectURL() Memory Management](https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL#memory_management) + +--- + +## 📈 Comparison dengan QC Sebelumnya + +| Aspek | Profil | Potensi | Berita | Pengumuman | Gallery | **Layanan** | +|-------|--------|---------|--------|------------|---------|-------------| +| Schema | 6/10 | 7/10 | 8/10 | 7/10 | 6/10 | **7/10** | +| API Completeness | 7/10 | 8/10 | 7.5/10 | 7/10 | 6/10 | **5/10** 🔴 | +| API Security | 4/10 | 6/10 | 6/10 | 6/10 | 4/10 | **5/10** | +| UI/UX | 8/10 | 8.5/10 | 8/10 | 7.5/10 | 7.5/10 | **7.5/10** | +| State Mgmt | 7/10 | 8/10 | 8/10 | 7/10 | 6.5/10 | **6.5/10** | +| Code Quality | 7/10 | 7.5/10 | 7/10 | 6.5/10 | 6/10 | **6/10** | +| **Overall** | **6.5/10** | **7.5/10** | **7/10** | **6.5/10** | **6/10** | **6.5/10** | + +**Layanan** memiliki score sama dengan **Profil Desa** dan **Pengumuman** karena: + +**Positif:** +- ✅ Schema design lebih baik (dual image support, relasi yang jelas) +- ✅ UI/UX bagus (responsive, interactive stepper) +- ✅ Most modules complete + +**Negatif:** +- ❌ **2 modul incomplete** (missing API endpoints & create pages) +- ❌ **Hardcoded ID 'edit'** di production code +- ❌ **State management bug** (wrong variable assignment) +- ❌ **Inconsistent endpoint patterns** (delete endpoint beda) +- ❌ Missing authentication + +--- + +**Dibuat oleh:** QC Automation +**Review Status:** ⏳ Menunggu Review Developer +**Next Review:** Setelah implementasi fixes diff --git a/QC/DESA/summary-qc-penghargaan-desa.md b/QC/DESA/summary-qc-penghargaan-desa.md new file mode 100644 index 00000000..763fb0d6 --- /dev/null +++ b/QC/DESA/summary-qc-penghargaan-desa.md @@ -0,0 +1,774 @@ +# Quality Control Report - Penghargaan Desa Admin + +**Lokasi:** `/src/app/admin/(dashboard)/desa/penghargaan/` +**Tanggal QC:** 25 Februari 2026 +**Status:** ✅ **Good** (dengan beberapa issue security yang perlu diperbaiki) + +--- + +## 📋 Ringkasan Eksekutif + +Halaman Penghargaan Desa memiliki implementasi yang **cukup baik** dengan CRUD lengkap, upload gambar, dan state management terstruktur. Ditemukan **11 issue** dengan rincian: + +- 🔴 **High Priority:** 2 issue +- 🟡 **Medium Priority:** 5 issue +- 🟢 **Low Priority:** 4 issue + +**Overall Score: 7/10** - Good + +--- + +## 📁 Struktur File yang Diperiksa + +``` +/src/app/admin/(dashboard)/desa/penghargaan/ +├── page.tsx # List penghargaan dengan search & pagination +├── create/ +│ └── page.tsx # Create penghargaan dengan upload gambar +└── [id]/ + ├── page.tsx # Detail penghargaan + └── edit/ + └── page.tsx # Edit penghargaan dengan replace image +``` + +**File Terkait:** +- State: `/src/app/admin/(dashboard)/_state/desa/penghargaan.ts` +- API: `/src/app/api/[[...slugs]]/_lib/desa/penghargaan/` (6 files) +- Schema: `/prisma/schema.prisma` (Model `Penghargaan`) + +--- + +## 🔴 HIGH PRIORITY ISSUES + +### 1. XSS Vulnerability via `dangerouslySetInnerHTML` + +**File:** `src/app/admin/(dashboard)/desa/penghargaan/page.tsx` + +```typescript +// Line 79 + +``` + +**Same issue di:** `src/app/admin/(dashboard)/desa/penghargaan/[id]/page.tsx` line 89 + +```typescript + +``` + +**Dampak:** +- User bisa inject malicious script melalui rich text editor +- XSS attack bisa mencuri session, cookies, atau data sensitif +- Admin lain yang lihat data bisa terinfeksi + +**Severity:** 🔴 **HIGH** - Security vulnerability + +**Solusi:** + +**Option A - Sanitize HTML (Recommended):** +```typescript +// Install: bun add dompurify +import DOMPurify from 'dompurify'; + +// Di component + +``` + +**Option B - Strip HTML Tags:** +```typescript +const stripHtml = (html: string) => { + const tmp = document.createElement('div'); + tmp.innerHTML = html; + return tmp.textContent || tmp.innerText || ''; +}; + +{stripHtml(item.deskripsi)} +``` + +**Option C - Server-Side Sanitization:** +```typescript +// Di API create.ts dan updt.ts +import sanitizeHtml from 'sanitize-html'; + +const sanitizedDeskripsi = sanitizeHtml(body.deskripsi, { + allowedTags: ['p', 'br', 'strong', 'em', 'u', 'ul', 'ol', 'li'], + allowedAttributes: {} +}); +``` + +--- + +### 2. Inconsistent Fetch Patterns (ApiFetch vs fetch) + +**File:** `src/app/admin/(dashboard)/_state/desa/penghargaan.ts` + +```typescript +// Line 45-53 (create) - Menggunakan ApiFetch ✅ +const res = await ApiFetch.api.desa.penghargaan.create.post(penghargaan.create.form); + +// Line 90-93 (findUnique) - Menggunakan fetch langsung ❌ +const res = await fetch(`/api/desa/penghargaan/${id}`); +const data = await res.json(); + +// Line 108-120 (delete) - Menggunakan fetch langsung ❌ +const response = await fetch(`/api/desa/penghargaan/del/${id}`, { + method: 'DELETE', +}); +const result = await response.json(); + +// Line 147-165 (edit.load) - Menggunakan fetch langsung ❌ +const response = await fetch(`/api/desa/penghargaan/${id}`); +const result = await response.json(); +``` + +**Dampak:** +- Code maintainability kurang +- Tidak type-safe +- Inconsistent error handling +- Sulit refactor + +**Severity:** 🔴 **HIGH** - Code quality issue + +**Solusi:** +```typescript +// Gunakan ApiFetch untuk semua +// findUnique +const data = await ApiFetch.api.desa.penghargaan[':id'].get({ query: { id } }); + +// delete +const result = await ApiFetch.api.desa.penghargaan['del/:id'].delete({ params: { id } }); + +// edit.load +const data = await ApiFetch.api.desa.penghargaan[':id'].get({ query: { id } }); +``` + +--- + +## 🟡 MEDIUM PRIORITY ISSUES + +### 3. Tidak Ada Validasi Duplicate Name + +**File:** `src/app/api/[[...slugs]]/_lib/desa/penghargaan/create.ts` + +```typescript +// Line 13-23 +const penghargaan = await prisma.penghargaan.create({ + data: { + name: body.name, // ❌ Tidak cek duplicate + juara: body.juara, + deskripsi: body.deskripsi, + imageId: body.imageId, + }, +}); +``` + +**Same issue di:** `updt.ts` (update endpoint) + +**Dampak:** +- User bisa buat penghargaan dengan nama sama +- Data redundancy +- Confusing saat search + +**Severity:** 🟡 **MEDIUM** - Data integrity + +**Solusi:** +```typescript +// Check duplicate sebelum create +const existing = await prisma.penghargaan.findFirst({ + where: { + name: body.name, + isActive: true + } +}); + +if (existing) { + return Response.json({ + success: false, + message: "Nama penghargaan sudah digunakan" + }, { status: 400 }); +} + +// Lanjut create +const penghargaan = await prisma.penghargaan.create({ ... }); +``` + +**Alternative - Schema Level:** +```prisma +model Penghargaan { + name String @unique // Add unique constraint + // ... +} +``` + +--- + +### 4. Search Tidak Reset Pagination + +**File:** `src/app/admin/(dashboard)/desa/penghargaan/page.tsx` + +```typescript +// Line 35-38 +useShallowEffect(() => { + load(page, 10, debouncedSearch); +}, [page, debouncedSearch]); +``` + +**Dampak:** +- User di page 5, search untuk data yang hanya ada di page 1 +- Result kosong, user bingung +- UX buruk + +**Severity:** 🟡 **MEDIUM** - UX issue + +**Solusi:** +```typescript +// Reset page saat search berubah +useShallowEffect(() => { + if (debouncedSearch !== search) { + setPage(1); // Reset to page 1 + } + load(page, 10, debouncedSearch); +}, [page, debouncedSearch, search]); +``` + +**Better Solution:** +```typescript +// Watch search separately +useEffect(() => { + setPage(1); // Reset page saat search berubah +}, [debouncedSearch]); + +useEffect(() => { + load(page, 10, debouncedSearch); +}, [page, debouncedSearch]); +``` + +--- + +### 5. Image Upload Hanya Saat Submit + +**File:** `src/app/admin/(dashboard)/desa/penghargaan/create/page.tsx` + +```typescript +// Line 81-95 +const handleSubmit = async () => { + // Validasi + // ... + + // Upload image BARU saat submit + const res = await ApiFetch.api.fileStorage.create.post({ + file, + name: file.name, + }); + + const uploaded = res.data?.data; + if (!uploaded?.id) { + return toast.error('Gagal mengunggah gambar'); + } + + // Create penghargaan + await statePenghargaan.penghargaan.create.form.imageId = uploaded.id; + await statePenghargaan.penghargaan.create(); +}; +``` + +**Dampak:** +- Jika create penghargaan gagal, file sudah ter-upload (orphaned file) +- User tidak bisa preview image yang sudah di-upload sebelumnya +- Tidak ada progress indicator saat upload + +**Severity:** 🟡 **MEDIUM** - Data integrity & UX + +**Solusi:** + +**Option A - Upload Dulu, Baru Create:** +```typescript +// Upload immediately saat file selected +const handleFileChange = async (file: File) => { + const res = await ApiFetch.api.fileStorage.create.post({ + file, + name: file.name, + }); + + const uploaded = res.data?.data; + if (uploaded?.id) { + setFile(file); + setPreviewImage(URL.createObjectURL(file)); + statePenghargaan.penghargaan.create.form.imageId = uploaded.id; + } +}; + +// Submit hanya create penghargaan +const handleSubmit = async () => { + await statePenghargaan.penghargaan.create(); +}; +``` + +**Option B - Transaction dengan Rollback:** +```typescript +const handleSubmit = async () => { + try { + // Upload file + const uploaded = await uploadFile(file); + + // Create penghargaan + const result = await createPenghargaan({ imageId: uploaded.id }); + + if (!result.success) { + // Rollback: delete uploaded file + await deleteFile(uploaded.id); + throw new Error('Create failed'); + } + } catch (error) { + toast.error('Gagal membuat penghargaan'); + } +}; +``` + +--- + +### 6. Dropzone Accept Format Typo + +**File:** `src/app/admin/(dashboard)/desa/penghargaan/create/page.tsx` + +```typescript +// Line 140-143 + +``` + +**Same issue di:** `edit/page.tsx` line 180-183 + +**Dampak:** +- File `.webp` tidak akan di-accept oleh dropzone +- User confusion saat coba upload WebP +- Inconsistent dengan validasi lainnya + +**Severity:** 🟡 **MEDIUM** - UX issue + +**Solusi:** +```typescript + +``` + +--- + +### 7. Schema `deletedAt` Default Value (SAME BUG) + +**File:** `prisma/schema.prisma` + +```prisma +model Penghargaan { + id String @id @default(cuid()) + name String + deletedAt DateTime @default(now()) // ❌ SAME BUG AS OTHER MODULES + isActive Boolean @default(true) +} +``` + +**Dampak:** +- Record baru langsung ter-mark deleted saat dibuat +- Soft delete logic tidak bekerja +- Query dengan `deletedAt: null` tidak dapat data baru + +**Severity:** 🟡 **MEDIUM** - Data integrity bug + +**Solusi:** +```prisma +model Penghargaan { + id String @id @default(cuid()) + name String + deletedAt DateTime? // ✅ Nullable, tanpa default + isActive Boolean @default(true) +} +``` + +**Migration:** +```bash +bunx prisma db push +# atau +bunx prisma migrate dev --name fix_penghargaan_deleted_at + +# Data cleanup +UPDATE "Penghargaan" SET "deletedAt" = NULL WHERE "isActive" = true; +``` + +--- + +## 🟢 LOW PRIORITY ISSUES + +### 8. `isHtmlEmpty` Tidak Handle Edge Cases + +**File:** `src/app/admin/(dashboard)/desa/penghargaan/create/page.tsx` + +```typescript +// Line 23-26 +const isHtmlEmpty = (html: string) => { + const textContent = html.replace(/<[^>]*>/g, '').trim(); + return textContent === ''; +}; +``` + +**Dampak:** +- HTML dengan hanya ` ` atau `
` akan dianggap empty +- User bisa submit content yang sebenarnya kosong + +**Severity:** 🟢 **LOW** - Validation edge case + +**Solusi:** +```typescript +const isHtmlEmpty = (html: string) => { + // Strip HTML tags + const tmp = document.createElement('div'); + tmp.innerHTML = html; + // Get text content + const textContent = tmp.textContent || tmp.innerText || ''; + // Check if empty or only whitespace + return textContent.trim().length === 0; +}; +``` + +--- + +### 9. Duplicate Validation Check + +**File:** `src/app/admin/(dashboard)/desa/penghargaan/create/page.tsx` + +```typescript +// Line 58-73: Validasi pertama +const handleSubmit = async () => { + if (!statePenghargaan.penghargaan.create.form.name?.trim()) { + toast.error('Nama penghargaan wajib diisi'); + return; + } + // ... validasi lainnya + + // Line 81-84: Validasi diulang lagi (redundant) + if ( + !statePenghargaan.penghargaan.create.form.name?.trim() || + !statePenghargaan.penghargaan.create.form.juara?.trim() || + isHtmlEmpty(statePenghargaan.penghargaan.create.form.deskripsi) || + !file + ) { + toast.error('Mohon lengkapi semua data'); + return; + } +}; +``` + +**Dampak:** Code redundancy, minor performance overhead. + +**Severity:** 🟢 **LOW** - Code quality + +**Solusi:** +```typescript +const handleSubmit = async () => { + // Single validation block + if (!statePenghargaan.penghargaan.create.form.name?.trim()) { + toast.error('Nama penghargaan wajib diisi'); + return; + } + if (!statePenghargaan.penghargaan.create.form.juara?.trim()) { + toast.error('Juara wajib diisi'); + return; + } + if (isHtmlEmpty(statePenghargaan.penghargaan.create.form.deskripsi)) { + toast.error('Deskripsi wajib diisi'); + return; + } + if (!file) { + toast.error('Gambar wajib diunggah'); + return; + } + + // Submit logic + // ... +}; +``` + +--- + +### 10. Inconsistent Button Labels (Reset vs Batal) + +**File:** Create page vs Edit page + +```typescript +// create/page.tsx line 109 + + +// edit/page.tsx line 100 + +``` + +**Dampak:** Minor UX inconsistency. + +**Severity:** 🟢 **LOW** - UX consistency + +**Solusi:** Standardize to "Reset Form" untuk kedua page. + +--- + +### 11. Tidak Ada Karakter Counter + +**File:** Create & Edit pages + +```typescript + { + statePenghargaan.penghargaan.create.form.name = e.target.value; + }} + // ❌ Tidak ada maxLength atau character counter +/> +``` + +**Dampak:** User tidak tahu ada limit atau tidak. + +**Severity:** 🟢 **LOW** - UX polish + +**Solusi:** +```typescript + { + statePenghargaan.penghargaan.create.form.name = e.target.value; + }} + maxLength={255} // Add max length + rightSection={ + + {statePenghargaan.penghargaan.create.form.name?.length || 0}/255 + + } +/> +``` + +--- + +## ✅ YANG SUDAH BAIK + +### **Schema:** +- ✅ Relasi ke FileStorage untuk gambar sudah benar +- ✅ Soft delete pattern dengan `deletedAt` dan `isActive` +- ✅ Audit trail dengan `createdAt` dan `updatedAt` +- ✅ Field yang diperlukan sudah lengkap + +### **API:** +- ✅ CRUD lengkap untuk Penghargaan +- ✅ Pagination support dengan `page`, `limit`, `search` +- ✅ Search functionality dengan case-insensitive +- ✅ Include relasi image di response +- ✅ **File cleanup saat update** (hapus old image) ✅ +- ✅ **File cleanup saat delete** (hapus image) ✅ +- ✅ Parallel query untuk data & count (optimasi performa) +- ✅ Response format mostly konsisten: `{ success, message, data }` + +### **UI/UX:** +- ✅ Responsive design (desktop table + mobile cards) +- ✅ Loading states dan skeleton +- ✅ Toast notifications untuk feedback +- ✅ Form validation comprehensive +- ✅ Image upload dengan dropzone & preview +- ✅ File size limit & format validation +- ✅ Rich text editor untuk deskripsi +- ✅ Search dengan debounce (1000ms) +- ✅ Modal konfirmasi hapus +- ✅ Empty state message +- ✅ Reset form functionality +- ✅ Button disabled saat invalid/submitting + +### **State Management:** +- ✅ Valtio proxy untuk global state +- ✅ Zod validation schema +- ✅ Loading state management +- ✅ Auto-refresh after CRUD operations +- ✅ Error handling dengan toast + +--- + +## 📊 Metrics + +| Aspek | Score | Keterangan | +|-------|-------|------------| +| **Schema Design** | 7/10 | Good, tapi ada bug deletedAt | +| **API Design** | 7.5/10 | RESTful, file cleanup implemented | +| **API Security** | 5/10 | Tidak ada auth, XSS vulnerability | +| **UI/UX** | 8/10 | Responsive, comprehensive features | +| **State Management** | 7/10 | Valtio works well, inconsistent fetch | +| **Code Quality** | 7/10 | Good structure, minor inconsistencies | + +**Overall Score: 7/10** - **Good** + +--- + +## 🎯 Action Plan + +### Week 1 (Critical Fixes) 🔴 + +- [ ] **URGENT:** Sanitize HTML content (DOMPurify) untuk XSS prevention +- [ ] **URGENT:** Konsistensi fetch pattern (gunakan ApiFetch untuk semua) + +### Week 2 (Medium Priority) 🟡 + +- [ ] Tambahkan validasi duplicate name di API create/update +- [ ] Fix search reset pagination logic +- [ ] Fix image upload timing (upload dulu atau transaction) +- [ ] Fix dropzone accept format typo (`.webp`) +- [ ] Fix `deletedAt @default(now())` di schema + +### Week 3 (Polish) 🟢 + +- [ ] Improve `isHtmlEmpty` function +- [ ] Remove duplicate validation +- [ ] Standardize button labels (Reset Form) +- [ ] Add character counter untuk text fields +- [ ] Add loading state saat load data di edit page + +--- + +## 📝 Technical Notes + +### **Database Migration:** + +Fix deletedAt default: +```bash +bunx prisma migrate dev --name fix_penghargaan_deleted_at +# atau +bunx prisma db push + +# Data cleanup +UPDATE "Penghargaan" SET "deletedAt" = NULL WHERE "isActive" = true; +``` + +### **XSS Prevention:** + +Install DOMPurify: +```bash +bun add dompurify +bun add -D @types/dompurify +``` + +Usage: +```typescript +import DOMPurify from 'dompurify'; + +// Di component + +``` + +### **Duplicate Name Prevention:** + +API validation: +```typescript +// Check existing name +const existing = await prisma.penghargaan.findFirst({ + where: { + name: body.name, + isActive: true, + id: body.id ? { not: body.id } : undefined // Exclude current for update + } +}); + +if (existing) { + return Response.json({ + success: false, + message: "Nama penghargaan sudah digunakan" + }, { status: 400 }); +} +``` + +### **Search Reset Pagination:** + +```typescript +// Watch search separately +useEffect(() => { + setPage(1); // Reset page saat search berubah +}, [debouncedSearch]); + +useEffect(() => { + load(page, 10, debouncedSearch); +}, [page, debouncedSearch]); +``` + +--- + +## 📚 References + +- [Prisma Soft Delete Pattern](https://www.prisma.io/docs/concepts/components/prisma-client/soft-delete) +- [DOMPurify Documentation](https://github.com/cure53/DOMPurify) +- [Mantine Dropzone Documentation](https://mantine.dev/x/dropzone/) +- [React Toastify Documentation](https://fkhadra.github.io/react-toastify/) +- [Zod Documentation](https://zod.dev/) + +--- + +## 📈 Comparison dengan QC Sebelumnya + +| Aspek | Profil | Potensi | Berita | Pengumuman | Gallery | Layanan | **Penghargaan** | +|-------|--------|---------|--------|------------|---------|---------|-----------------| +| Schema | 6/10 | 7/10 | 8/10 | 7/10 | 6/10 | 7/10 | **7/10** | +| API Design | 7/10 | 8/10 | 7.5/10 | 7/10 | 6/10 | 5/10 | **7.5/10** ✅ | +| API Security | 4/10 | 6/10 | 6/10 | 6/10 | 4/10 | 5/10 | **5/10** | +| UI/UX | 8/10 | 8.5/10 | 8/10 | 7.5/10 | 7.5/10 | 7.5/10 | **8/10** ✅ | +| State Mgmt | 7/10 | 8/10 | 8/10 | 7/10 | 6.5/10 | 6.5/10 | **7/10** | +| Code Quality | 7/10 | 7.5/10 | 7/10 | 6.5/10 | 6/10 | 6/10 | **7/10** | +| **Overall** | **6.5/10** | **7.5/10** | **7/10** | **6.5/10** | **6/10** | **6.5/10** | **7/10** | + +**Penghargaan** memiliki score **tertinggi kedua** (setelah Potensi Desa) karena: + +**Positif:** +- ✅ CRUD lengkap & berfungsi dengan baik +- ✅ File cleanup implemented (update & delete) ✅ +- ✅ Responsive design bagus +- ✅ Comprehensive validation +- ✅ Parallel query untuk performa +- ✅ Tidak ada incomplete features (seperti Layanan) +- ✅ Tidak ada critical data loss bugs (seperti Gallery) + +**Yang Perlu Diperbaiki:** +- ❌ XSS vulnerability (dangerouslySetInnerHTML) +- ❌ Inconsistent fetch patterns +- ❌ Duplicate name validation tidak ada +- ❌ `deletedAt @default(now())` bug +- ❌ Search tidak reset pagination + +--- + +**Dibuat oleh:** QC Automation +**Review Status:** ⏳ Menunggu Review Developer +**Next Review:** Setelah implementasi fixes diff --git a/QC/DESA/summary-qc-pengumuman-desa.md b/QC/DESA/summary-qc-pengumuman-desa.md new file mode 100644 index 00000000..28e49b6e --- /dev/null +++ b/QC/DESA/summary-qc-pengumuman-desa.md @@ -0,0 +1,809 @@ +# Quality Control Report - Pengumuman Desa Admin + +**Lokasi:** `/src/app/admin/(dashboard)/desa/pengumuman/` +**Tanggal QC:** 25 Februari 2026 +**Status:** ⚠️ **Needs Improvement** (ada issue critical yang perlu segera diperbaiki) + +--- + +## 📋 Ringkasan Eksekutif + +Halaman Pengumuman Desa memiliki implementasi yang **cukup baik** dengan CRUD lengkap dan state management terstruktur. Namun ditemukan **15 issue** dengan rincian: + +- 🔴 **High Priority:** 2 issue +- 🟡 **Medium Priority:** 7 issue +- 🟢 **Low Priority:** 6 issue + +**Overall Score: 6.5/10** - Needs Improvement + +--- + +## 📁 Struktur File yang Diperiksa + +``` +/src/app/admin/(dashboard)/desa/pengumuman/ +├── layout.tsx +├── _com/ +│ └── layoutTabs.tsx # Tab navigation component +├── kategori-pengumuman/ +│ ├── page.tsx # List kategori dengan search & pagination +│ ├── create/ +│ │ └── page.tsx # Form create kategori +│ └── [id]/ +│ └── page.tsx # Edit kategori +└── list-pengumuman/ + ├── page.tsx # List pengumuman dengan search & pagination + ├── create/ + │ └── page.tsx # Form create pengumuman (rich text) + └── [id]/ + ├── page.tsx # Detail pengumuman + └── edit/ + └── page.tsx # Edit pengumuman +``` + +**File Terkait:** +- State: `/src/app/admin/(dashboard)/_state/desa/pengumuman.ts` +- API: `/src/app/api/[[...slugs]]/_lib/desa/pengumuman/` (9 files) +- API: `/src/app/api/[[...slugs]]/_lib/desa/pengumuman/kategori-pengumuman/` (6 files) +- Schema: `/prisma/schema.prisma` (Model `Pengumuman` & `CategoryPengumuman`) + +--- + +## 🔴 HIGH PRIORITY ISSUES + +### 1. API - Hard Delete vs Soft Delete Mismatch (DATA LOSS RISK) + +**File:** `src/app/api/[[...slugs]]/_lib/desa/pengumuman/del.ts` + +```typescript +export default async function pengumumanDelete(context: Context) { + const id = context.params?.id as string; + + // ❌ HARD DELETE - Data benar-benar terhapus dari database + await prisma.pengumuman.delete({ where: { id } }); + + return { success: true, message: "Pengumuman berhasil dihapus" }; +} +``` + +**Schema yang Diharapkan:** +```prisma +model Pengumuman { + deletedAt DateTime? @default(null) // Soft delete field + isActive Boolean @default(true) +} +``` + +**Dampak:** +- **DATA LOSS** - Data pengumuman terhapus permanen, tidak bisa direcover +- Audit trail hilang (riwayat pengumuman tidak ada lagi) +- Inconsistent dengan schema design yang sudah ada soft delete fields +- Bisa melanggar compliance requirements untuk data retention + +**Solusi:** +```typescript +// Ganti hard delete dengan soft delete +export default async function pengumumanDelete(context: Context) { + const id = context.params?.id as string; + + // ✅ SOFT DELETE - Update deletedAt dan isActive + await prisma.pengumuman.update({ + where: { id }, + data: { + deletedAt: new Date(), + isActive: false + } + }); + + return { success: true, message: "Pengumuman berhasil dihapus" }; +} +``` + +**File yang Perlu Diperbaiki:** +- `src/app/api/[[...slugs]]/_lib/desa/pengumuman/del.ts` +- `src/app/api/[[...slugs]]/_lib/desa/pengumuman/kategori-pengumuman/del.ts` + +--- + +### 2. Schema - `deletedAt` Default Value `now()` Bermasalah + +**File:** `prisma/schema.prisma` + +```prisma +model Pengumuman { + id String @id @default(cuid()) + judul String + deletedAt DateTime @default(now()) // ❌ PROBLEMATIC DEFAULT + isActive Boolean @default(true) +} + +model CategoryPengumuman { + id String @id @default(cuid()) + name String @unique + deletedAt DateTime @default(now()) // ❌ PROBLEMATIC DEFAULT + isActive Boolean @default(true) +} +``` + +**Dampak:** +- Setiap record **baru langsung ter-mark sebagai deleted** saat dibuat +- Query dengan filter `deletedAt: null` tidak akan dapat data baru +- Soft delete logic tidak bekerja dengan benar +- Data inconsistency antara `deletedAt` (set) dan `isActive` (true) + +**Solusi:** +```prisma +model Pengumuman { + id String @id @default(cuid()) + judul String + deletedAt DateTime? // ✅ Nullable, tanpa default + isActive Boolean @default(true) +} + +model CategoryPengumuman { + id String @id @default(cuid()) + name String @unique + deletedAt DateTime? // ✅ Nullable, tanpa default + isActive Boolean @default(true) +} +``` + +**Migration Required:** +```bash +# Generate migration +bunx prisma migrate dev --name fix_deleted_at_default + +# Atau jika tidak pakai migrate +bunx prisma db push + +# Data cleanup untuk record yang sudah ter-affected +UPDATE "Pengumuman" SET "deletedAt" = NULL WHERE "isActive" = true; +UPDATE "CategoryPengumuman" SET "deletedAt" = NULL WHERE "isActive" = true; +``` + +--- + +## 🟡 MEDIUM PRIORITY ISSUES + +### 3. UI - Search Parameter Hilang Saat Pagination + +**File:** `src/app/admin/(dashboard)/desa/pengumuman/list-pengumuman/page.tsx` + +```typescript + { + load(newPage, 10); // ❌ Missing search parameter + }} +/> +``` + +**Dampak:** +- Saat user ganti halaman, search query hilang +- User harus ketik ulang search query +- UX sangat buruk untuk pagination dengan search +- Inconsistent dengan page lain (berita, potensi) + +**Solusi:** +```typescript + { + load(newPage, 10, debouncedSearch); // ✅ Include search parameter + }} +/> +``` + +**Note:** Pastikan function `load` menerima parameter search: +```typescript +const load = async (page: number, limit: number, searchQuery?: string) => { + // ... +}; +``` + +--- + +### 4. UI - Duplicate State Management + +**File:** `src/app/admin/(dashboard)/desa/pengumuman/list-pengumuman/[id]/edit/page.tsx` + +```typescript +// Local state +const [formData, setFormData] = useState({ + judul: '', + deskripsi: '', + content: '', + categoryPengumumanId: '', +}); + +const [originalData, setOriginalData] = useState({...formData}); + +// Global state (Valtio) +editState.pengumuman.edit.form = { + ...editState.pengumuman.edit.form, + ...formData, // ❌ Duplicate data +}; +``` + +**Dampak:** +- Data inconsistency antara local state dan global state +- Sulit debug karena data ada di 2 tempat +- Memory overhead +- Potential bugs saat reset form + +**Solusi:** + +**Option A - Gunakan hanya global state:** +```typescript +// Hapus local state, gunakan langsung global state +const formData = editState.pengumuman.edit.form; + +const handleResetForm = () => { + editState.pengumuman.edit.form = { ...originalData }; +}; +``` + +**Option B - Sinkronisasi dengan useEffect:** +```typescript +useEffect(() => { + // Sync local state ke global state + editState.pengumuman.edit.form = { ...formData }; +}, [formData]); +``` + +--- + +### 5. UI - Error Handling Silent Failures + +**File:** `src/app/admin/(dashboard)/_state/desa/pengumuman.ts` + +```typescript +// Line 266-268 +catch (error) { + console.log((error as Error).message); + // ❌ Error tidak ditampilkan ke user, silent failure +} +``` + +**Dampak:** +- User tidak tahu ada error +- Sulit debug production issues +- User experience buruk (loading forever tanpa feedback) + +**Solusi:** +```typescript +catch (error) { + const errorMessage = error instanceof Error ? error.message : 'Unknown error'; + console.error('Failed to load pengumuman:', errorMessage); + toast.error(`Gagal memuat data: ${errorMessage}`); +} +``` + +--- + +### 6. UI - ColSpan Mismatch + +**File:** `src/app/admin/(dashboard)/desa/pengumuman/kategori-pengumuman/page.tsx` + +```typescript + + + Nama + Dibuat + Aksi {/* 3 kolom total */} + + + + + {loading ? ( + + {/* ❌ colSpan 4, seharusnya 3 */} + + + + ) : ( + // ... + )} + +``` + +**Dampak:** Layout table tidak rapi, colSpan terlalu lebar. + +**Solusi:** +```typescript + // ✅ Match column count +``` + +--- + +### 7. State Management - Copy-Paste Error Message + +**File:** `src/app/admin/(dashboard)/_state/desa/pengumuman.ts` + +```typescript +// Line 68-70 +kategoriPengumuman: { + findMany: { + loading: false, + async load(page = 1, limit = 10, search = '') { + try { + // ... + } catch (error) { + console.error("Failed to load potensi desa:", res.data?.message); + // ❌ Copy-paste error dari file potensi! Seharusnya "kategori pengumuman" + } + } + } +} +``` + +**Dampak:** +- Membingungkan saat debug +- Tidak profesional +- Menunjukkan kurangnya attention to detail + +**Solusi:** +```typescript +console.error("Failed to load kategori pengumuman:", res.data?.message); +``` + +--- + +### 8. UI - Button Text "Batal" Membingungkan + +**File:** `src/app/admin/(dashboard)/desa/pengumuman/kategori-pengumuman/[id]/page.tsx` + +```typescript + +``` + +**Dampak:** User mungkin bingung apakah button ini akan cancel edit atau reset form. + +**Solusi:** +```typescript + +``` + +--- + +### 9. UI - Button Order Tidak Mengikuti UX Best Practice + +**File:** `src/app/admin/(dashboard)/desa/pengumuman/list-pengumuman/[id]/page.tsx` + +```typescript + + +``` + +--- + +### 10. Validasi Form Hanya di Frontend + +**File:** Create & Edit pages + +**Dampak:** +- User bisa bypass validation via API call langsung +- Data invalid bisa masuk ke database +- Security risk + +**Severity:** 🟡 **MEDIUM** - Security & data integrity + +**Solusi:** +```typescript +// Tambah validasi di API create.ts +const { name, nomor, deskripsi, jadwalPelayanan } = await context.body; + +// Validasi required fields +if (!name || !nomor || !deskripsi || !jadwalPelayanan) { + return Response.json({ + success: false, + message: "Semua field wajib diisi" + }, { status: 400 }); +} + +// Validasi length +if (name.length > 255) { + return Response.json({ + success: false, + message: "Nama maksimal 255 karakter" + }, { status: 400 }); +} + +// Validasi nomor format (jika perlu) +if (!/^\d+$/.test(nomor)) { + return Response.json({ + success: false, + message: "Nomor harus angka" + }, { status: 400 }); +} +``` + +--- + +## 🟢 LOW PRIORITY ISSUES + +### 11. Schema Field `name` Tidak Unique + +**File:** `prisma/schema.prisma` + +```prisma +model Posyandu { + name String // ❌ Tidak ada @unique (berbeda dengan Berita, KategoriBerita, dll) + nomor String // ❌ Tidak ada @unique + // ... +} +``` + +**Dampak:** Tidak ada constraint di database level untuk mencegah duplikasi. + +**Severity:** 🟢 **LOW** - Schema design + +**Solusi:** +```prisma +model Posyandu { + name String @unique @db.VarChar(255) + nomor String @unique @db.VarChar(50) + // ... +} +``` + +--- + +### 12. Tidak Ada Constraint Panjang untuk Field Text + +**File:** `prisma/schema.prisma` + +```prisma +model Posyandu { + name String // ❌ Tidak ada max length + nomor String // ❌ Tidak ada max length + deskripsi String @db.Text + jadwalPelayanan String // ❌ Tidak ada max length + // ... +} +``` + +**Dampak:** User bisa input text sangat panjang, bisa break UI atau database. + +**Severity:** 🟢 **LOW** - Schema design + +**Solusi:** +```prisma +model Posyandu { + name String @db.VarChar(255) + nomor String @db.VarChar(50) + deskripsi String @db.Text + jadwalPelayanan String @db.VarChar(500) + // ... +} +``` + +--- + +### 13. Empty State Tanpa Illustration + +**File:** `src/app/admin/(dashboard)/kesehatan/posyandu/page.tsx` + +```typescript +// Line 67-69 +{filteredData.length === 0 && ( + + Tidak ada data posyandu + +)} +``` + +**Dampak:** Empty state kurang informatif dan kurang visually appealing. + +**Severity:** 🟢 **LOW** - UX polish + +**Solusi:** +```typescript +{filteredData.length === 0 && ( + + No data + Tidak ada data posyandu + + {search ? 'Coba kata kunci lain' : 'Mulai dengan menambahkan posyandu baru'} + + {!search && ( + + )} + +)} +``` + +--- + +### 14. Tidak Ada Sorting Option + +**File:** `find-many.ts` dan `page.tsx` + +```typescript +// find-many.ts +orderBy: { createdAt: 'desc' } // ❌ Hardcoded, tidak ada option sorting +``` + +**Dampak:** User tidak bisa sort by name, nomor, atau jadwal. + +**Severity:** 🟢 **LOW** - UX + +**Solusi:** +```typescript +// API find-many.ts +const { page = 1, limit = 10, search = '', sortBy = 'createdAt', sortOrder = 'desc' } = context.query; + +orderBy: { + [sortBy as string]: sortOrder === 'asc' ? 'asc' : 'desc' +} +``` + +--- + +### 15. Toast Error Tidak Spesifik + +**File:** `posyandu.ts` state + +```typescript +// Line 45-53 +if (res.status === 200) { + toast.success("Posyandu berhasil disimpan!"); +} else { + toast.error("Gagal menyimpan posyandu"); // ❌ Generic error +} +``` + +**Dampak:** User tidak tahu penyebab error. + +**Severity:** 🟢 **LOW** - UX + +**Solusi:** +```typescript +if (res.status === 200) { + toast.success("Posyandu berhasil disimpan!"); +} else { + const errorMessage = res.data?.message || 'Terjadi kesalahan'; + toast.error(`Gagal menyimpan posyandu: ${errorMessage}`); +} +``` + +--- + +## ✅ YANG SUDAH BAIK + +### **Schema:** +- ✅ Relasi ke FileStorage untuk gambar sudah benar +- ✅ Soft delete pattern dengan `deletedAt` dan `isActive` (tapi tidak dipakai di delete) +- ✅ Audit trail dengan `createdAt` dan `updatedAt` +- ✅ Field yang diperlukan sudah lengkap (name, nomor, deskripsi, jadwal, image) + +### **API:** +- ✅ CRUD lengkap untuk Posyandu +- ✅ Pagination support dengan `page`, `limit`, `search` +- ✅ Search functionality dengan case-insensitive (include semua field) +- ✅ Include relasi image di response +- ✅ File cleanup saat delete (hapus file fisik + database) +- ✅ Error handling ada di semua endpoints +- ✅ Response format konsisten: `{ success, message, data }` + +### **UI/UX:** +- ✅ Responsive design (desktop table + mobile cards) +- ✅ Loading states dan skeleton +- ✅ Toast notifications untuk feedback +- ✅ Form validation comprehensive (name, nomor, deskripsi, jadwal, image) +- ✅ Image upload dengan dropzone & preview +- ✅ File size limit & format validation +- ✅ Rich text editor untuk deskripsi dan jadwal +- ✅ Search dengan debounce (1000ms) +- ✅ Modal konfirmasi hapus +- ✅ Empty state message +- ✅ Reset form functionality +- ✅ Button disabled saat invalid/submitting + +### **State Management:** +- ✅ Valtio proxy untuk global state +- ✅ Zod validation schema +- ✅ Loading state management +- ✅ Auto-refresh after CRUD operations +- ✅ Separate state untuk create, findMany, findUnique, edit, delete + +--- + +## 📊 Metrics + +| Aspek | Score | Keterangan | +|-------|-------|------------| +| **Schema Design** | 6.5/10 | Good structure, tapi tidak ada unique constraints | +| **API Design** | 6.5/10 | RESTful, file cleanup implemented, tapi tidak ada validation | +| **API Security** | 5/10 | Tidak ada auth, tidak ada backend validation | +| **UI/UX** | 7.5/10 | Responsive, comprehensive features | +| **State Management** | 6.5/10 | Valtio works well, inconsistent fetch patterns | +| **Code Quality** | 6.5/10 | Good structure, race condition potential | + +**Overall Score: 6.5/10** - **Needs Improvement** + +--- + +## 🎯 Action Plan + +### Week 1 (Critical Fixes) 🔴 + +- [ ] **URGENT:** Fix delete operation (hard delete → soft delete) +- [ ] **URGENT:** Tambahkan validasi duplicate name/nomor di API +- [ ] **URGENT:** Tambahkan validasi imageId existence di API +- [ ] **URGENT:** Fix race condition di edit page (dual state) +- [ ] **URGENT:** Konsistensi fetch pattern (gunakan ApiFetch) + +### Week 2 (Medium Priority) 🟡 + +- [ ] Fix search reset pagination logic +- [ ] Tambahkan filter isActive di find-by-id API +- [ ] Improve error handling upload gambar +- [ ] Tambahkan progress indicator untuk upload +- [ ] Tambahkan backend validation untuk semua field + +### Week 3 (Polish) 🟢 + +- [ ] Tambahkan unique constraint di schema +- [ ] Tambahkan length constraints di schema +- [ ] Improve empty state dengan illustration +- [ ] Tambahkan sorting option +- [ ] Improve toast error messages + +--- + +## 📝 Technical Notes + +### **Database Migration:** + +Fix deletedAt default dan add unique constraints: +```bash +# Generate migration +bunx prisma migrate dev --name fix_posyandu_deleted_at_and_unique + +# Atau jika tidak pakai migrate +bunx prisma db push + +# Data cleanup +UPDATE "Posyandu" SET "deletedAt" = NULL WHERE "isActive" = true; +``` + +### **Soft Delete Implementation:** + +Update delete endpoint: +```typescript +// del.ts - Before (hard delete) +await prisma.posyandu.delete({ where: { id } }); + +// After (soft delete) +await prisma.posyandu.update({ + where: { id }, + data: { + deletedAt: new Date(), + isActive: false + } +}); +``` + +### **Duplicate Validation:** + +```typescript +// Check existing name/nomor +const existing = await prisma.posyandu.findFirst({ + where: { + OR: [ + { name: body.name }, + { nomor: body.nomor } + ], + isActive: true, + id: body.id ? { not: body.id } : undefined // Exclude current for update + } +}); + +if (existing) { + return Response.json({ + success: false, + message: "Nama atau nomor posyandu sudah digunakan" + }, { status: 400 }); +} +``` + +### **Race Condition Fix:** + +```typescript +// Option A: Use only global state +const formData = statePosyandu.edit.form; + +const handleResetForm = () => { + statePosyandu.edit.form = { ...originalData }; +}; + +// Submit directly +const handleSubmit = async () => { + // Validation + await statePosyandu.edit.update(); +}; +``` + +--- + +## 📚 References + +- [Prisma Soft Delete Pattern](https://www.prisma.io/docs/concepts/components/prisma-client/soft-delete) +- [Prisma Unique Constraints](https://www.prisma.io/docs/concepts/components/prisma-schema/relations) +- [Mantine Dropzone Documentation](https://mantine.dev/x/dropzone/) +- [React Toastify Documentation](https://fkhadra.github.io/react-toastify/) +- [Zod Documentation](https://zod.dev/) +- [Valtio Documentation](https://docs.pmnd.rs/valtio) + +--- + +## 📈 Comparison dengan QC Sebelumnya + +| Aspek | Profil | Potensi | Berita | Pengumuman | Gallery | Layanan | Penghargaan | **Posyandu** | +|-------|--------|---------|--------|------------|---------|---------|-------------|--------------| +| Schema | 6/10 | 7/10 | 8/10 | 7/10 | 6/10 | 7/10 | 7/10 | **6.5/10** | +| API Design | 7/10 | 8/10 | 7.5/10 | 7/10 | 6/10 | 5/10 | 7.5/10 | **6.5/10** | +| API Security | 4/10 | 6/10 | 6/10 | 6/10 | 4/10 | 5/10 | 5/10 | **5/10** | +| UI/UX | 8/10 | 8.5/10 | 8/10 | 7.5/10 | 7.5/10 | 7.5/10 | 8/10 | **7.5/10** ✅ | +| State Mgmt | 7/10 | 8/10 | 8/10 | 7/10 | 6.5/10 | 6.5/10 | 7/10 | **6.5/10** | +| Code Quality | 7/10 | 7.5/10 | 7/10 | 6.5/10 | 6/10 | 6/10 | 7/10 | **6.5/10** | +| **Overall** | **6.5/10** | **7.5/10** | **7/10** | **6.5/10** | **6/10** | **6.5/10** | **7/10** | **6.5/10** | + +**Posyandu** memiliki score sama dengan **Profil Desa** dan **Pengumuman** karena: + +**Positif:** +- ✅ CRUD lengkap & berfungsi dengan baik +- ✅ File cleanup implemented (delete) ✅ +- ✅ Responsive design bagus +- ✅ Comprehensive validation di frontend +- ✅ Rich text editor untuk 2 field (deskripsi & jadwal) +- ✅ Search include semua field + +**Negatif:** +- ❌ **Hard delete** vs soft delete mismatch (data loss risk) +- ❌ **Tidak ada validasi backend** (duplicate, imageId, required fields) +- ❌ **Race condition** di edit page (dual state) +- ❌ **Inconsistent fetch patterns** (ApiFetch vs fetch) +- ❌ **Tidak ada unique constraints** di schema +- ❌ **Tidak ada authentication** di API + +--- + +**Dibuat oleh:** QC Automation +**Review Status:** ⏳ Menunggu Review Developer +**Next Review:** Setelah implementasi fixes diff --git a/QC/Landing-Page/QC-APBDES-MODULE.md b/QC/Landing-Page/QC-APBDES-MODULE.md new file mode 100644 index 00000000..1b53600e --- /dev/null +++ b/QC/Landing-Page/QC-APBDES-MODULE.md @@ -0,0 +1,763 @@ +# QC Summary - APBDes Module + +**Scope:** List APBDes, Create, Edit, Detail +**Date:** 2026-02-23 +**Status:** ✅ Secara umum sudah baik, ada beberapa critical issues yang perlu diperbaiki + +--- + +## 📊 OVERVIEW + +| Aspect | Schema | API | UI Admin | State Management | Overall | +|--------|--------|-----|----------|-----------------|---------| +| APBDes | ✅ Baik | ✅ Baik | ✅ Baik | ⚠️ Ada issue | 🟡 Perlu fix | + +--- + +## ✅ YANG SUDAH BAIK + +### **1. UI/UX Consistency** +- ✅ Responsive design (desktop table + mobile cards) +- ✅ Loading states dengan Skeleton +- ✅ Search dengan debounce (1000ms) +- ✅ Pagination konsisten +- ✅ Empty state handling yang informatif +- ✅ Modal konfirmasi hapus + +### **2. File Upload Handling** +- ✅ Dual upload: Gambar + Dokumen +- ✅ Dropzone dengan preview (image + iframe untuk dokumen) +- ✅ Validasi format (gambar: JPEG/PNG/WEBP, dokumen: PDF/DOC/DOCX) +- ✅ Validasi ukuran file (max 5MB untuk gambar, 10MB untuk dokumen di edit) +- ✅ Tombol hapus preview (IconX di pojok kanan atas) +- ✅ URL.createObjectURL untuk preview lokal + +### **3. Form Validation** +- ✅ Zod schema untuk validasi typed +- ✅ isFormValid() check sebelum submit +- ✅ Error toast dengan pesan spesifik +- ✅ Button disabled saat invalid/loading +- ✅ Type number input untuk tahun + +### **4. Complex Feature - APBDes Items** +- ✅ Hierarchical items dengan level (1, 2, 3) +- ✅ Tipe classification (pendapatan, belanja, pembiayaan) +- ✅ Auto-calculation: selisih & persentase +- ✅ Add/remove items dynamic +- ✅ Table preview dengan badge color coding +- ✅ Indentasi visual berdasarkan level + +### **5. Edit Form - Original Data Tracking** +- ✅ Original data state untuk reset form +- ✅ Load data existing dengan benar +- ✅ Preview image & dokumen dari data lama +- ✅ Reset form mengembalikan ke data original +- ✅ File replacement logic (upload baru jika ada perubahan) + +**Code Example (✅ GOOD):** +```typescript +// Line ~95-130 - Load data & save original +const data = await apbdesState.edit.load(id); + +setOriginalData({ + tahun: data.tahun || new Date().getFullYear(), + imageId: data.imageId || '', + fileId: data.fileId || '', + imageUrl: data.image?.link || '', + fileUrl: data.file?.link || '', +}); + +// Set form dengan data lama (termasuk imageId dan fileId) +apbdesState.edit.form = { + tahun: data.tahun || new Date().getFullYear(), + imageId: data.imageId || '', // ✅ Preserve old ID + fileId: data.fileId || '', // ✅ Preserve old ID + items: (data.items || []).map(...), +}; + +// Line ~270 - Handle reset +const handleReset = () => { + apbdesState.edit.form = { + tahun: originalData.tahun, + imageId: originalData.imageId, // ✅ Restore old ID + fileId: originalData.fileId, // ✅ Restore old ID + items: [...apbdesState.edit.form.items], + }; + setPreviewImage(originalData.imageUrl || null); + setPreviewDoc(originalData.fileUrl || null); + setImageFile(null); + setDocFile(null); + toast.info('Form dikembalikan ke data awal'); +}; +``` + +**Verdict:** ✅ **SUDAH BENAR** - Original data tracking sudah implementasi dengan baik. + +--- + +### **6. Schema Design** +- ✅ Proper relations: APBDes ↔ FileStorage (image & file) +- ✅ Self-relation untuk hierarchical items (parentId → children) +- ✅ Indexing untuk performa (kode, level, apbdesId) +- ✅ Soft delete support (deletedAt, isActive) +- ✅ Nullable deletedAt yang benar (`DateTime? @default(null)`) + +**Schema Example (✅ GOOD):** +```prisma +model APBDes { + id String @id @default(cuid()) + tahun Int? + name String? + deskripsi String? + jumlah String? + items APBDesItem[] + image FileStorage? @relation("APBDesImage", fields: [imageId], references: [id]) + imageId String? + file FileStorage? @relation("APBDesFile", fields: [fileId], references: [id]) + fileId String? + deletedAt DateTime? // ✅ Nullable, no default + isActive Boolean @default(true) +} + +model APBDesItem { + id String @id @default(cuid()) + kode String + uraian String + anggaran Float + realisasi Float + selisih Float // ✅ Formula di komentar + persentase Float + tipe String? // ✅ Nullable untuk level 1 + level Int + parentId String? + parent APBDesItem? @relation("APBDesItemParent", fields: [parentId], references: [id]) + children APBDesItem[] @relation("APBDesItemParent") + apbdesId String + apbdes APBDes @relation(fields: [apbdesId], references: [id]) + + @@index([kode]) + @@index([level]) + @@index([apbdesId]) +} +``` + +**Verdict:** ✅ **SUDAH BENAR** - Schema design sudah solid. + +--- + +## ⚠️ ISSUES & SARAN PERBAIKAN + +### **🔴 CRITICAL** + +#### **1. Formula Selisih - SALAH di State, BENAR di Schema/API** + +**Lokasi:** +- `src/app/admin/(dashboard)/_state/landing-page/apbdes.ts` (line 36) +- Schema komentar di `prisma/schema.prisma` (line 210) + +**Masalah:** +```typescript +// ❌ SALAH di state (line 36) +function normalizeItem(item: Partial<...>): z.infer { + const anggaran = item.anggaran ?? 0; + const realisasi = item.realisasi ?? 0; + + // ❌ WRONG FORMULA + const selisih = anggaran - realisasi; // positif = sisa anggaran + + const persentase = anggaran > 0 ? (realisasi / anggaran) * 100 : 0; + + return { ... }; +} +``` + +```prisma +// ✅ BENAR di schema komentar (line 210) +model APBDesItem { + // ... + realisasi Float + selisih Float // ✅ realisasi - anggaran (komentar benar) + // ... +} +``` + +**Dampak:** +- **Data salah!** Selisih positif/negatif terbalik +- Jika realisasi > anggaran (over budget), seharusnya **negatif** tapi jadi **positif** +- Jika realisasi < anggaran (under budget/sisa), seharusnya **positif** tapi jadi **negatif** +- Color coding di UI (green/red) juga terbalik! + +**Contoh:** +``` +Anggaran: Rp 100.000.000 +Realisasi: Rp 120.000.000 (over budget!) + +❌ Formula sekarang: selisih = 100M - 120M = -20M (negatif) + UI show: merah (over budget) ✅ TAPI karena negatif + +✅ Seharusnya: selisih = 120M - 100M = +20M (positif) + UI show: merah (over budget) ✅ Karena positif +``` + +**Rekomendasi:** Fix formula di state: + +```typescript +// ✅ CORRECT FORMULA +const selisih = realisasi - anggaran; // positif = over budget, negatif = under budget +const persentase = anggaran > 0 ? (realisasi / anggaran) * 100 : 0; +``` + +**Priority:** 🔴 **CRITICAL** +**Effort:** Low (1 line fix) +**Impact:** **HIGH** (data integrity issue) + +--- + +#### **2. State Management - Inconsistency Fetch Pattern** + +**Lokasi:** `src/app/admin/(dashboard)/_state/landing-page/apbdes.ts` + +**Masalah:** Ada 3 pattern berbeda untuk fetch API: + +```typescript +// ❌ Pattern 1: ApiFetch (create, findMany, delete, edit.load, edit.update) +const res = await ApiFetch.api.landingpage.apbdes["create"].post(parsed.data); +const res = await ApiFetch.api.landingpage.apbdes["findMany"].get({ query }); +const res = await (ApiFetch.api.landingpage.apbdes as any)["del"][id].delete(); +const res = await (ApiFetch.api.landingpage.apbdes as any)[id].get(); +const res = await (ApiFetch.api.landingpage.apbdes as any)[this.id].put(requestData); + +// ❌ Pattern 2: fetch manual (findUnique) +const response = await fetch(`/api/landingpage/apbdes/${id}`); +const res = await response.json(); +``` + +**Dampak:** +- Code consistency buruk +- Sulit maintenance +- Type safety tidak konsisten +- Duplikasi logic error handling +- Console.log debugging tertinggal di production + +**Rekomendasi:** Gunakan **ApiFetch** untuk semua operasi: + +```typescript +// ✅ Unified pattern +async load(id: string) { + try { + this.loading = true; + const res = await ApiFetch.api.landingpage.apbdes[id].get(); + + if (res.data?.success) { + this.data = res.data.data; + } else { + this.data = null; + this.error = res.data?.message || "Gagal memuat detail APBDes"; + toast.error(this.error); + } + } catch (error) { + console.error("FindUnique error:", error); + this.data = null; + this.error = "Gagal memuat detail APBDes"; + toast.error(this.error); + } finally { + this.loading = false; + } +} +``` + +**Priority:** 🔴 High +**Effort:** Medium (refactor di findUnique) + +--- + +#### **3. Console.log Debugging di Production** + +**Lokasi:** `src/app/admin/(dashboard)/_state/landing-page/apbdes.ts` + +**Masalah:** +```typescript +// Line ~175-177 +const url = `/api/landingpage/apbdes/${id}`; +console.log("🌐 Fetching:", url); // ❌ Debug log + +const response = await fetch(url); +const res = await response.json(); + +console.log("📦 Response:", res); // ❌ Debug log +``` + +**Dampak:** +- Performance impact (I/O operation) +- Security risk (expose API structure) +- Log pollution di production +- Unprofessional + +**Rekomendasi:** Remove atau gunakan conditional logging: + +```typescript +// ✅ Remove completely (recommended) +// Atau gunakan conditional logging +if (process.env.NODE_ENV === 'development') { + console.log("🌐 Fetching:", url); + console.log("📦 Response:", res); +} +``` + +**Priority:** 🔴 Medium +**Effort:** Low + +--- + +### **🟡 MEDIUM** + +#### **4. Type Safety - Any Usage di Edit Methods** + +**Lokasi:** `src/app/admin/(dashboard)/_state/landing-page/apbdes.ts` + +**Masalah:** +```typescript +// Line ~215 +const res = await (ApiFetch.api.landingpage.apbdes as any)[id].get(); +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +// Line ~245 +const res = await (ApiFetch.api.landingpage.apbdes as any)[this.id].put(requestData); +// ^^^^^^^^^^^^^^^^^^^^^^^^^^ +``` + +**Dampak:** +- Type safety hilang +- Autocomplete tidak bekerja +- Runtime errors tidak terdeteksi di compile time +- Refactoring sulit + +**Rekomendasi:** Define typed API client: + +```typescript +// Define proper types +interface APBDesAPI { + [id: string]: { + get: () => Promise>; + put: (data: APBDesForm) => Promise>; + }; + del: { + [id: string]: { + delete: () => Promise>; + }; + }; +} + +// Use typed client +const res = await ApiFetch.api.landingpage.apbdes[id].get(); +// No more `as any` +``` + +**Priority:** 🟡 Medium +**Effort:** Medium (perlu setup types) + +--- + +#### **5. Edit Form - Items Tidak Di-Restore Saat Reset** + +**Lokasi:** `src/app/admin/(dashboard)/landing-page/apbdes/[id]/edit/page.tsx` + +**Masalah:** +```typescript +// Line ~270-285 +const handleReset = () => { + apbdesState.edit.form = { + tahun: originalData.tahun, + imageId: originalData.imageId, + fileId: originalData.fileId, + items: [...apbdesState.edit.form.items], // ⚠️ Keep MODIFIED items + }; + // ... +}; +``` + +**Issue:** Saat reset, items yang sudah di-modified (added/removed) tidak di-restore ke original. User expect reset = kembali ke data awal sepenuhnya. + +**Rekomendasi:** Save original items dan restore saat reset: + +```typescript +// Add to originalData state +const [originalData, setOriginalData] = useState({ + tahun: 0, + imageId: '', + fileId: '', + imageUrl: '', + fileUrl: '', + items: [] as ItemForm[], // ✅ Save original items +}); + +// Load data +setOriginalData({ + tahun: data.tahun || new Date().getFullYear(), + imageId: data.imageId || '', + fileId: data.fileId || '', + imageUrl: data.image?.link || '', + fileUrl: data.file?.link || '', + items: (data.items || []).map((item: any) => ({...})), // ✅ Save +}); + +// Reset +const handleReset = () => { + apbdesState.edit.form = { + tahun: originalData.tahun, + imageId: originalData.imageId, + fileId: originalData.fileId, + items: [...originalData.items], // ✅ Restore original items + }; + // ... +}; +``` + +**Priority:** 🟡 Medium +**Effort:** Low + +--- + +#### **6. Zod Schema - Error Message Tidak Akurat** + +**Lokasi:** `src/app/admin/(dashboard)/_state/landing-page/apbdes.ts` + +**Masalah:** +```typescript +// Line ~10 +const ApbdesItemSchema = z.object({ + kode: z.string().min(1, "Kode wajib diisi"), // ✅ OK + uraian: z.string().min(1, "Uraian wajib diisi"), // ✅ OK + anggaran: z.number().min(0), // ⚠️ No custom message + realisasi: z.number().min(0), // ⚠️ No custom message + // ... +}); + +// Line ~17 +const ApbdesFormSchema = z.object({ + tahun: z.number().int().min(2000, "Tahun tidak valid"), // ⚠️ Generic + imageId: z.string().min(1, "Gambar wajib diunggah"), // ✅ OK + fileId: z.string().min(1, "File wajib diunggah"), // ✅ OK + items: z.array(ApbdesItemSchema).min(1, "Minimal ada 1 item"), // ✅ OK +}); +``` + +**Dampak:** Error messages tidak konsisten, beberapa generic beberapa spesifik. + +**Rekomendasi:** Standardisasi error messages: + +```typescript +const ApbdesItemSchema = z.object({ + kode: z.string().min(1, "Kode wajib diisi"), + uraian: z.string().min(1, "Uraian wajib diisi"), + anggaran: z.number().min(0, "Anggaran tidak boleh negatif"), + realisasi: z.number().min(0, "Realisasi tidak boleh negatif"), + selisih: z.number(), + persentase: z.number(), + level: z.number().int().min(1).max(3, "Level harus antara 1-3"), + tipe: z.enum(['pendapatan', 'belanja', 'pembiayaan']).nullable().optional(), +}); + +const ApbdesFormSchema = z.object({ + tahun: z.number().int().min(2000, "Tahun minimal 2000").max(2100, "Tahun maksimal 2100"), + imageId: z.string().min(1, "Gambar wajib diunggah"), + fileId: z.string().min(1, "Dokumen wajib diunggah"), + items: z.array(ApbdesItemSchema).min(1, "Minimal ada 1 item"), +}); +``` + +**Priority:** 🟡 Low +**Effort:** Low + +--- + +#### **7. Console.log di Production (UI Components)** + +**Lokasi:** Multiple UI files + +**Masalah:** +```typescript +// edit/page.tsx - Line ~220 +console.error('Update error:', err); + +// create/page.tsx - Line ~120 +console.error("Gagal submit:", error); + +// detail/page.tsx - Line ~40 +console.error('Error loading APBDes:', error); +``` + +**Rekomendasi:** Gunakan conditional logging: + +```typescript +if (process.env.NODE_ENV === 'development') { + console.error('Update error:', err); +} +``` + +**Priority:** 🟡 Low +**Effort:** Low + +--- + +### **🟢 LOW (Minor Polish)** + +#### **8. Mobile Layout - Title Order Inconsistency** + +**Lokasi:** `page.tsx` + +**Masalah:** +```typescript +// Line ~170 (Mobile) + + Daftar APBDes + + +// Line ~70 (Desktop - inside Paper) + + Daftar APBDes + +``` + +**Issue:** Mobile pakai `order={2}` (heading besar), desktop `order={4}`. Seharusnya konsisten. + +**Rekomendasi:** Samakan: +```typescript + + Daftar APBDes + +``` + +**Priority:** 🟢 Low +**Effort:** Low + +--- + +#### **9. Search Placeholder Tidak Spesifik** + +**Lokasi:** `page.tsx` + +**Masalah:** +```typescript +// Line ~30 + +``` + +**Rekomendasi:** Lebih spesifik: +```typescript +placeholder='Cari nama atau tahun APBDes...' +``` + +**Priority:** 🟢 Low +**Effort:** Low + +--- + +#### **10. Duplicate Comment** + +**Lokasi:** `src/app/admin/(dashboard)/_state/landing-page/apbdes.ts` + +**Masalah:** +```typescript +// Line ~28-29 +// --- Helper: hitung selisih & persentase otomatis (opsional di frontend) --- +// --- Helper: hitung selisih & persentase otomatis (opsional di frontend) --- +// ^ Duplicate line +``` + +**Priority:** 🟢 Low +**Effort:** Low (remove duplicate) + +--- + +#### **11. Inconsistent Button Label** + +**Lokasi:** Multiple files + +**Masalah:** +```typescript +// create/page.tsx - Line ~270 + + +// edit/page.tsx - Line ~340 + + +// Should be consistent: "Simpan" atau "Simpan Perubahan" +``` + +**Rekomendasi:** Standardisasi: +```typescript +// Create: "Simpan" +// Edit: "Simpan Perubahan" (lebih descriptive untuk edit) +// OR both: "Simpan" +``` + +**Priority:** 🟢 Low +**Effort:** Low + +--- + +#### **12. Missing Search Feature in Pagination** + +**Lokasi:** `page.tsx` + +**Masalah:** +```typescript +// Line ~250 + { + load(newPage, 10); // ⚠️ Missing search parameter + window.scrollTo({ top: 0, behavior: 'smooth' }); + }} + total={totalPages} + // ... +/> +``` + +**Issue:** Saat ganti page, search query hilang. + +**Rekomendasi:** Include search: +```typescript +onChange={(newPage) => { + load(newPage, 10, debouncedSearch); // ✅ Include search + window.scrollTo({ top: 0, behavior: 'smooth' }); +}} +``` + +**Priority:** 🟢 Low +**Effort:** Low + +--- + +#### **13. Edit Page - Document Max Size Inconsistency** + +**Lokasi:** `edit/page.tsx` + +**Masalah:** +```typescript +// Line ~230 (Image) +maxSize={5 * 1024 ** 2} // 5MB + +// Line ~250 (Document) +maxSize={10 * 1024 ** 2} // 10MB +``` + +**Issue:** Create page maksimal 5MB untuk semua file, edit page 10MB untuk dokumen. Inconsistent. + +**Rekomendasi:** Samakan (prefer 5MB untuk consistency): +```typescript +maxSize={5 * 1024 ** 2} // 5MB for both +``` + +**Priority:** 🟢 Low +**Effort:** Low + +--- + +## 📋 RINGKASAN ACTION ITEMS + +| Priority | Issue | Module | Impact | Effort | Status | +|----------|-------|--------|--------|--------|--------| +| 🔴 P0 | **Formula selisih SALAH** | State | **CRITICAL** | Low | **MUST FIX** | +| 🔴 P0 | Fetch method inconsistency | State | Medium | Medium | Perlu refactor | +| 🔴 P1 | Console.log debugging in production | State | Medium | Low | Should fix | +| 🟡 M | Type safety (any usage) | State | Low | Medium | Optional | +| 🟡 M | Items tidak di-restore saat reset | Edit UI | Medium | Low | Should fix | +| 🟡 M | Zod schema error messages | State | Low | Low | Optional | +| 🟢 L | Console.log in UI components | UI | Low | Low | Optional | +| 🟢 L | Mobile title order inconsistency | List UI | Low | Low | Optional | +| 🟢 L | Search placeholder tidak spesifik | List UI | Low | Low | Optional | +| 🟢 L | Duplicate comment | State | Low | Low | Optional | +| 🟢 L | Inconsistent button label | UI | Low | Low | Optional | +| 🟢 L | Missing search in pagination | List UI | Low | Low | Should fix | +| 🟢 L | Document max size inconsistency | Edit UI | Low | Low | Optional | + +--- + +## ✅ KESIMPULAN + +### **Overall Quality: 🟢 BAIK (7/10)** + +**Strengths:** +1. ✅ UI/UX konsisten & responsive +2. ✅ File upload handling solid (dual upload: image + document) +3. ✅ Form validation dengan Zod schema +4. ✅ State management terstruktur (Valtio) +5. ✅ **Edit form reset sudah benar** (original data tracking untuk files) +6. ✅ Complex feature: hierarchical items dengan level & tipe +7. ✅ Schema design solid (proper relations, indexing, soft delete) +8. ✅ Modal konfirmasi hapus untuk user safety + +**Critical Issues:** +1. ⚠️ **FORMULA SELISIH SALAH** - Data integrity issue (CRITICAL) +2. ⚠️ Fetch method pattern inconsistency (ApiFetch vs fetch manual) +3. ⚠️ Console.log debugging tertinggal di production + +**Areas for Improvement:** +1. ⚠️ **Fix formula selisih** (realisasi - anggaran, bukan anggaran - realisasi) +2. ⚠️ **Refactor fetch methods** untuk gunakan ApiFetch consistently +3. ⚠️ **Remove console.log** debugging dari production code +4. ⚠️ **Save & restore original items** saat reset form di edit page +5. ⚠️ **Improve type safety** dengan remove `as any` usage +6. ⚠️ **Standardisasi error messages** di Zod schema + +**Recommended Next Steps:** +1. **🔴 CRITICAL: Fix formula selisih** di state (line 36) - 5 menit fix +2. **🔴 HIGH:** Refactor findUnique ke ApiFetch - 30 menit +3. **🔴 HIGH:** Remove console.log debugging - 10 menit +4. **🟡 MEDIUM:** Save & restore original items - 30 menit +5. **🟡 MEDIUM:** Improve type safety - 1-2 jam +6. **🟢 LOW:** Polish minor issues - 30 menit + +--- + +## 📈 COMPARISON WITH OTHER MODULES + +| Aspect | Profil | Desa Anti Korupsi | SDGs Desa | APBDes | Notes | +|--------|--------|-------------------|-----------|--------|-------| +| Fetch Pattern | ⚠️ Mixed | ⚠️ Mixed | ⚠️ Mixed | ⚠️ Mixed | All perlu refactor | +| Loading State | ⚠️ Some missing | ⚠️ Some missing | ⚠️ Missing | ✅ Good | APBDes paling baik | +| Edit Form Reset | ✅ Good | ✅ Good | ✅ Good | ✅ Good | All consistent | +| Type Safety | ⚠️ Some `any` | ⚠️ Some `any` | ⚠️ Some `any` | ⚠️ Some `any` | Same issue | +| File Upload | ✅ Images | ✅ Documents | ✅ Images | ✅ **Dual** | APBDes paling complex | +| Error Handling | ✅ Good | ✅ Good (better) | ✅ Good | ✅ Good | Consistent | +| Schema Design | ✅ Good | ⚠️ deletedAt issue | ⚠️ deletedAt issue | ✅ **Best** | APBDes paling solid | +| **Data Integrity** | ✅ Good | ✅ Good | ✅ Good | ❌ **Formula WRONG** | **APBDes CRITICAL issue** | +| Complexity | Low | Medium | Low | **High** | APBDes items hierarchy | + +--- + +## 🎯 UNIQUE FEATURES OF APBDes MODULE + +**Most Complex Module So Far:** +1. **Dual file upload** (gambar + dokumen) - unique to APBDes +2. **Hierarchical items** dengan 3 level - unique to APBDes +3. **Auto-calculation** (selisih & persentase) - unique to APBDes +4. **Type classification** (pendapatan, belanja, pembiayaan) - unique to APBDes +5. **Dynamic item management** (add/remove) - unique to APBDes + +**Best Practices:** +1. ✅ Schema design paling solid (deletedAt nullable, proper indexing) +2. ✅ Edit form reset paling comprehensive (preserve files & items) +3. ✅ Validation paling thorough (Zod schema untuk items) + +**Biggest Issue:** +1. ❌ **Formula selisih SALAH** - critical data integrity issue yang tidak ada di modul lain + +--- + +**Catatan:** Secara keseluruhan, modul APBDes adalah **paling complex dan paling solid** dibanding modul lain yang sudah di-QC. Namun, ada **1 CRITICAL BUG** (formula selisih) yang harus **SEGERA DIPERBAIKI** karena menyangkut integritas data. Setelah fix critical issue, module ini production-ready dengan beberapa improvement minor yang bisa dilakukan secara incremental. + +**Priority Action:** +``` +🔴 FIX INI SEKARANG JUGA (5 MENIT): +File: src/app/admin/(dashboard)/_state/landing-page/apbdes.ts +Line: 36 +Change: const selisih = anggaran - realisasi; +To: const selisih = realisasi - anggaran; +``` diff --git a/QC/Landing-Page/QC-DESA-ANTI-KORUPSI.md b/QC/Landing-Page/QC-DESA-ANTI-KORUPSI.md new file mode 100644 index 00000000..ec69bad3 --- /dev/null +++ b/QC/Landing-Page/QC-DESA-ANTI-KORUPSI.md @@ -0,0 +1,639 @@ +# QC Summary - Desa Anti Korupsi Module + +**Scope:** List Desa Anti Korupsi, Kategori Desa Anti Korupsi +**Date:** 2026-02-23 +**Status:** ✅ Secara umum sudah baik, ada beberapa improvement yang diperlukan + +--- + +## 📊 OVERVIEW + +| Module | Schema | API | UI Admin | State Management | Overall | +|--------|--------|-----|----------|-----------------|---------| +| List Desa Anti Korupsi | ✅ Baik | ✅ Baik | ✅ Baik | ⚠️ Ada issue | 🟡 Perlu fix | +| Kategori Desa Anti Korupsi | ✅ Baik | ✅ Baik | ✅ Baik | ⚠️ Ada issue | 🟡 Perlu fix | + +--- + +## ✅ YANG SUDAH BAIK (COMMON) + +### **1. UI/UX Consistency** +- ✅ Responsive design (desktop table + mobile cards) +- ✅ Loading states dengan Skeleton +- ✅ Search dengan debounce (1000ms) +- ✅ Pagination konsisten +- ✅ Empty state handling yang informatif +- ✅ Modal konfirmasi hapus + +### **2. File Upload Handling** (Desa Anti Korupsi) +- ✅ Dropzone dengan preview iframe untuk dokumen +- ✅ Validasi format dokumen (PDF, DOC, DOCX, XLS, XLSX, PPT, PPTX) +- ✅ Validasi ukuran file (max 5MB) +- ✅ Tombol hapus preview (IconX di pojok kanan atas) +- ✅ URL.createObjectURL untuk preview lokal + +### **3. Form Validation** +- ✅ Zod schema untuk validasi typed +- ✅ isFormValid() check sebelum submit +- ✅ Error toast dengan pesan spesifik +- ✅ Button disabled saat invalid/loading + +### **4. CRUD Operations** +- ✅ Create dengan upload file +- ✅ FindMany dengan pagination & search +- ✅ FindUnique untuk detail +- ✅ Delete dengan soft delete +- ✅ Update dengan file replacement + +### **5. Error Handling** +- ✅ Try-catch di semua async operation +- ✅ Toast error dengan pesan user-friendly +- ✅ Console.error untuk debugging +- ✅ Response cloning untuk error handling yang lebih baik (di kategori update) + +--- + +## ⚠️ ISSUES & SARAN PERBAIKAN + +### **🔴 CRITICAL** + +#### **1. Edit Form - File Lama Tidak Tersimpan Saat Reset** + +**Lokasi:** `src/app/admin/(dashboard)/landing-page/desa-anti-korupsi/list-desa-anti-korupsi/[id]/edit/page.tsx` + +**Masalah:** +```typescript +// Line ~70 - Load data +const data = await desaAntiKorupsiState.edit.load(id); + +setFormData({ + name: data.name, + deskripsi: data.deskripsi, + kategoriId: data.kategoriId, + fileId: data.fileId, // ✅ Sudah benar +}); + +setOriginalData({ + name: data.name, + deskripsi: data.deskripsi, + kategoriId: data.kategoriId, + fileId: data.fileId, + fileUrl: data.file?.link || "", // ✅ Sudah benar +}); + +// Line ~130 - Handle reset +const handleResetForm = () => { + setFormData({ + name: originalData.name, + deskripsi: originalData.deskripsi, + kategoriId: originalData.kategoriId, + fileId: originalData.fileId, // ✅ Sudah benar + }); + setPreviewFile(originalData.fileUrl || null); // ✅ Sudah benar + setFile(null); // ✅ Sudah benar +}; +``` + +**Status:** ✅ **SUDAH BENAR** - Original data tracking sudah implementasi dengan baik. + +**Verdict:** Tidak ada action needed. + +--- + +#### **2. State Management - Inconsistency Fetch Pattern** + +**Lokasi:** `src/app/admin/(dashboard)/_state/landing-page/desa-anti-korupsi.ts` + +**Masalah:** Ada 2 pattern berbeda untuk fetch API: + +```typescript +// ❌ Pattern 1: ApiFetch (create operations) +const res = await ApiFetch.api.landingpage.desaantikorupsi["create"].post({...}); + +// ❌ Pattern 2: fetch manual (findUnique, edit, delete) +const res = await fetch(`/api/landingpage/desaantikorupsi/${id}`); +const response = await fetch(`/api/landingpage/desaantikorupsi/del/${id}`, { + method: "DELETE", + headers: { "Content-Type": "application/json" }, +}); +``` + +**Dampak:** +- Code consistency buruk +- Sulit maintenance +- Type safety tidak konsisten +- Duplikasi logic error handling + +**Rekomendasi:** Gunakan **ApiFetch** untuk semua operasi: + +```typescript +// ✅ Unified pattern +const res = await ApiFetch.api.landingpage.desaantikorupsi["create"].post(data); +const res = await ApiFetch.api.landingpage.desaantikorupsi[id].get(); +const res = await ApiFetch.api.landingpage.desaantikorupsi[id].put(data); +const res = await ApiFetch.api.landingpage.desaantikorupsi["del"][id].delete(); +``` + +**Priority:** 🔴 High +**Effort:** Medium (refactor di semua state methods) + +--- + +#### **3. findUnique State - Tidak Ada Loading State Management** + +**Lokasi:** `src/app/admin/(dashboard)/_state/landing-page/desa-anti-korupsi.ts` + +**Masalah:** +```typescript +// Line ~97 - desaAntikorupsi.findUnique.load() +async load(id: string) { + try { + const res = await fetch(`/api/landingpage/desaantikorupsi/${id}`); + if (res.ok) { + const data = await res.json(); + desaAntikorupsi.findUnique.data = data.data ?? null; + } else { + console.error("Failed to fetch data", res.status, res.statusText); + desaAntikorupsi.findUnique.data = null; + } + } catch (error) { + console.error("Error fetching data:", error); + desaAntikorupsi.findUnique.data = null; + } + // ❌ MISSING: finally block untuk stop loading +} +``` + +**Dampak:** UI mungkin stuck di loading state jika ada error. + +**Rekomendasi:** Tambahkan loading state dan finally block: + +```typescript +async load(id: string) { + try { + desaAntikorupsi.findUnique.loading = true; // ✅ Start loading + const res = await fetch(`/api/landingpage/desaantikorupsi/${id}`); + if (res.ok) { + const data = await res.json(); + desaAntikorupsi.findUnique.data = data.data ?? null; + } + } catch (error) { + console.error("Error:", error); + } finally { + desaAntikorupsi.findUnique.loading = false; // ✅ Stop loading + } +} +``` + +**Priority:** 🔴 Medium +**Effort:** Low + +--- + +#### **4. Kategori Edit - Response Cloning Overkill** + +**Lokasi:** `src/app/admin/(dashboard)/_state/landing-page/desa-anti-korupsi.ts` + +**Masalah:** +```typescript +// Line ~370 - kategoriDesaAntiKorupsi.edit.update() +async update() { + // ... + const response = await fetch(...); + + // Clone the response to avoid 'body already read' error + const responseClone = response.clone(); + + try { + const result = await response.json(); + // ... + } catch (error) { + // If JSON parsing fails, try to get the response text + try { + const text = await responseClone.text(); + console.error("Error response text:", text); + throw new Error(`Gagal memproses respons dari server: ${text}`); + } catch (textError) { + // ... + } + } +} +``` + +**Analysis:** +- ✅ **GOOD:** Error handling sangat thorough +- ⚠️ **OVERKILL:** Untuk production API yang stable, ini berlebihan +- ⚠️ **INCONSISTENT:** Module lain tidak punya error handling se-detail ini + +**Rekomendasi:** Simplify untuk consistency: + +```typescript +async update() { + try { + kategoriDesaAntiKorupsi.edit.loading = true; + + const response = await fetch(`/api/landingpage/kategoridak/${this.id}`, { + method: "PUT", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ name: this.form.name }), + }); + + const result = await response.json(); + + if (!response.ok) { + throw new Error(result?.message || `HTTP ${response.status}`); + } + + if (result.success) { + toast.success(result.message || "Berhasil update"); + await kategoriDesaAntiKorupsi.findMany.load(); + return true; + } + + throw new Error(result.message || "Gagal update"); + } catch (error) { + console.error("Error updating:", error); + toast.error(error instanceof Error ? error.message : "Gagal update"); + return false; + } finally { + kategoriDesaAntiKorupsi.edit.loading = false; + } +} +``` + +**Priority:** 🟡 Low +**Effort:** Low + +--- + +### **🟡 MEDIUM** + +#### **5. HTML Injection Risk - dangerouslySetInnerHTML** + +**Lokasi:** +- `list-desa-anti-korupsi/[id]/page.tsx` (line ~105) +- `list-desa-anti-korupsi/create/page.tsx` (CreateEditor component) +- `list-desa-anti-korupsi/[id]/edit/page.tsx` (EditEditor component) + +**Masalah:** +```typescript +// ❌ Direct HTML render tanpa sanitization + +``` + +**Risk:** +- XSS attack jika admin input script malicious +- Bisa inject iframe, script tag, dll +- Security vulnerability + +**Rekomendasi:** Gunakan DOMPurify atau library sanitization: + +```typescript +import DOMPurify from 'dompurify'; + +// Sanitize sebelum render +const sanitizedHtml = DOMPurify.sanitize(data.deskripsi); + +``` + +Atau validasi di backend untuk whitelist tag HTML yang diperbolehkan (hanya `

`, `