upd: upload gambar

Deskripsi:
- fungsi upload gambar
- verifikasi nomer hp
- get list pengaduan by nomer hp

NO Issues
This commit is contained in:
2025-11-05 17:19:44 +08:00
parent 13f88efb35
commit c2d07b3edf
7 changed files with 461 additions and 40 deletions

View File

@@ -1,7 +1,10 @@
import { swagger } from "@elysiajs/swagger"
import Elysia, { t } from "elysia"
import type { StatusPengaduan } from "generated/prisma"
import { generateNoPengaduan } from "../lib/no-pengaduan"
import { prisma } from "../lib/prisma"
import { defaultConfigSF, testConnection, uploadFile } from "../lib/seafile"
import { normalizePhoneNumber } from "../lib/normalizePhone"
const PengaduanRoute = new Elysia({
prefix: "pengaduan",
@@ -136,9 +139,10 @@ const PengaduanRoute = new Elysia({
})
if (!warga) {
const cariWarga = await prisma.warga.findFirst({
const nomorHP = normalizePhoneNumber({ phone })
const cariWarga = await prisma.warga.findUnique({
where: {
phone,
phone: nomorHP,
}
})
@@ -146,7 +150,7 @@ const PengaduanRoute = new Elysia({
const wargaCreate = await prisma.warga.create({
data: {
name: idWarga,
phone,
phone: nomorHP,
},
select: {
id: true
@@ -346,7 +350,7 @@ const PengaduanRoute = new Elysia({
}
})
.get("/", async ({ query }) => {
const { take, page, search } = query
const { take, page, search, phone } = query
const skip = !page ? 0 : (Number(page) - 1) * (!take ? 10 : Number(take))
const data = await prisma.pengaduan.findMany({
@@ -377,6 +381,11 @@ const PengaduanRoute = new Elysia({
},
}
],
AND: {
Warga: {
phone: phone
}
}
},
select: {
id: true,
@@ -411,10 +420,57 @@ const PengaduanRoute = new Elysia({
return dataFix
}, {
query: t.Object({
take: t.String({ optional: true }),
page: t.String({ optional: true }),
search: t.String({ optional: true }),
phone: t.String({ minLength: 11, error: "phone harus diisi" }),
}),
detail: {
summary: "List Pengaduan Warga",
description: `tool untuk mendapatkan list pengaduan warga`,
summary: "List Pengaduan Warga By Phone",
description: `tool untuk mendapatkan list pengaduan warga by phone`,
tags: ["mcp"]
}
})
.use(swagger())
.post("/upload",
async ({ body }) => {
const { file } = body;
// Validasi file
if (!file) {
return { success: false, message: "File tidak ditemukan" };
}
// Contoh: cek koneksi ke Seafile
const coba = await testConnection(defaultConfigSF);
console.log("Seafile Connection:", coba);
// Upload ke Seafile (pastikan uploadFile menerima Blob atau ArrayBuffer)
// const buffer = await file.arrayBuffer();
const result = await uploadFile(defaultConfigSF, file);
console.log("Upload result:", result);
return {
success: true,
message: "Upload berhasil",
filename: file.name,
size: file.size,
seafileResult: result
};
},
{
body: t.Object({
file: t.File({ format: "binary" })
}),
detail: {
summary: "Upload File",
description: "Tool untuk upload file ke Seafile",
tags: ["mcp"],
consumes: ["multipart/form-data"]
},
}
);
export default PengaduanRoute