upd: coba api pengaduan dengan upload gambar

This commit is contained in:
2025-11-12 14:57:22 +08:00
parent eacc8fc220
commit 63c88161d3
2 changed files with 47 additions and 6 deletions

View File

@@ -6,7 +6,7 @@ import { mimeToExtension } from "../lib/mimetypeToExtension"
import { generateNoPengaduan } from "../lib/no-pengaduan"
import { normalizePhoneNumber } from "../lib/normalizePhone"
import { prisma } from "../lib/prisma"
import { catFile, defaultConfigSF, testConnection, uploadFile, uploadFileBase64 } from "../lib/seafile"
import { catFile, defaultConfigSF, testConnection, uploadFile, uploadFileBase64, uploadFileToFolder } from "../lib/seafile"
const PengaduanRoute = new Elysia({
prefix: "pengaduan",
@@ -100,7 +100,8 @@ const PengaduanRoute = new Elysia({
// --- PENGADUAN ---
.post("/create", async ({ body }) => {
const { title, detail, location, image, idCategory, idWarga, phone } = body
const { title, detail, location, imageData, imageMime, idCategory, idWarga, phone } = body
let imageFix = null
const noPengaduan = await generateNoPengaduan()
let idCategoryFix = idCategory
let idWargaFix = idWarga
@@ -110,6 +111,12 @@ const PengaduanRoute = new Elysia({
}
})
if (!imageData && !imageMime) {
const ext = mimeToExtension(imageMime)
imageFix = `${uuidv4()}.${ext}`
await uploadFileToFolder(defaultConfigSF, { name: imageFix, data: imageData }, "pengaduan")
}
if (!category) {
const cariCategory = await prisma.categoryPengaduan.findFirst({
where: {
@@ -163,7 +170,7 @@ const PengaduanRoute = new Elysia({
idCategory: idCategoryFix,
idWarga: idWargaFix,
location,
image,
image: imageFix,
noPengaduan,
},
select: {
@@ -172,7 +179,7 @@ const PengaduanRoute = new Elysia({
})
if (!pengaduan.id) {
throw new Error("gagal membuat pengaduan")
return { success: false, message: 'gagal membuat pengaduan' }
}
await prisma.historyPengaduan.create({
@@ -188,7 +195,8 @@ const PengaduanRoute = new Elysia({
title: t.String({ minLength: 1, error: "title harus diisi" }),
detail: t.String({ minLength: 1, error: "detail harus diisi" }),
location: t.String({ minLength: 1, error: "location harus diisi" }),
image: t.Any(),
imageData: t.String({ optional: true, description: "base64 encoded image data" }),
imageMime: t.String({ optional: true, description: "mime type of image" }),
idCategory: t.String({ minLength: 1, error: "idCategory harus diisi" }),
idWarga: t.String({ minLength: 1, error: "idWarga harus diisi" }),
phone: t.String({ minLength: 1, error: "phone harus diisi" }),
@@ -622,7 +630,7 @@ const PengaduanRoute = new Elysia({
const { fileName } = query
const connect = await testConnection(defaultConfigSF)
console.log({connect})
console.log({ connect })
const hasil = await catFile(defaultConfigSF, fileName)
console.log('hasilnya', hasil)