Merge pull request 'upd: api pengaduan' (#4) from amalia/29-okt-25 into main
Reviewed-on: http://wibugit.wibudev.com/wibu/jenna-mcp/pulls/4
This commit is contained in:
@@ -1,5 +1,28 @@
|
|||||||
import { prisma } from "@/server/lib/prisma";
|
import { prisma } from "@/server/lib/prisma";
|
||||||
|
|
||||||
|
const category = [
|
||||||
|
{
|
||||||
|
id: "lainnya",
|
||||||
|
name: "Lainnya"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "kebersihan",
|
||||||
|
name: "Kebersihan"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "keamanan",
|
||||||
|
name: "Keamanan"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "pelayanan",
|
||||||
|
name: "Pelayanan"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "infrastruktur",
|
||||||
|
name: "Infrastruktur"
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
const role = [
|
const role = [
|
||||||
{
|
{
|
||||||
id: "developer",
|
id: "developer",
|
||||||
@@ -36,7 +59,7 @@ const user = [
|
|||||||
|
|
||||||
console.log(`✅ Role ${r.name} seeded successfully`)
|
console.log(`✅ Role ${r.name} seeded successfully`)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const u of user) {
|
for (const u of user) {
|
||||||
await prisma.user.upsert({
|
await prisma.user.upsert({
|
||||||
where: { email: u.email },
|
where: { email: u.email },
|
||||||
@@ -47,7 +70,17 @@ const user = [
|
|||||||
console.log(`✅ User ${u.email} seeded successfully`)
|
console.log(`✅ User ${u.email} seeded successfully`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const c of category) {
|
||||||
|
await prisma.categoryPengaduan.upsert({
|
||||||
|
where: { id: c.id },
|
||||||
|
create: c,
|
||||||
|
update: c
|
||||||
|
})
|
||||||
|
|
||||||
|
console.log(`✅ Category ${c.name} seeded successfully`)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
})().catch((e) => {
|
})().catch((e) => {
|
||||||
|
|||||||
@@ -18,8 +18,9 @@ const PengaduanRoute = new Elysia({
|
|||||||
return data
|
return data
|
||||||
}, {
|
}, {
|
||||||
detail: {
|
detail: {
|
||||||
summary: "get kategori pengaduan",
|
summary: "List Kategori Pengaduan",
|
||||||
description: `tool untuk mendapatkan kategori pengaduan`
|
description: `tool untuk mendapatkan list kategori pengaduan`,
|
||||||
|
tags: ["mcp"]
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.post("/category/create", async ({ body }) => {
|
.post("/category/create", async ({ body }) => {
|
||||||
@@ -100,15 +101,67 @@ const PengaduanRoute = new Elysia({
|
|||||||
|
|
||||||
// --- PENGADUAN ---
|
// --- PENGADUAN ---
|
||||||
.post("/create", async ({ body }) => {
|
.post("/create", async ({ body }) => {
|
||||||
const { title, detail, location, image, idCategory, idWarga } = body
|
const { title, detail, location, image, idCategory, idWarga, phone } = body
|
||||||
const noPengaduan = await generateNoPengaduan()
|
const noPengaduan = await generateNoPengaduan()
|
||||||
|
let idCategoryFix = idCategory
|
||||||
|
let idWargaFix = idWarga
|
||||||
|
const category = await prisma.categoryPengaduan.findUnique({
|
||||||
|
where: {
|
||||||
|
id: idCategory,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!category) {
|
||||||
|
const cariCategory = await prisma.categoryPengaduan.findFirst({
|
||||||
|
where: {
|
||||||
|
name: idCategory,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!cariCategory) {
|
||||||
|
idCategoryFix = "lainnya"
|
||||||
|
} else {
|
||||||
|
idCategoryFix = cariCategory.id
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const warga = await prisma.warga.findUnique({
|
||||||
|
where: {
|
||||||
|
id: idWarga,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!warga) {
|
||||||
|
const cariWarga = await prisma.warga.findFirst({
|
||||||
|
where: {
|
||||||
|
phone,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!cariWarga) {
|
||||||
|
const wargaCreate = await prisma.warga.create({
|
||||||
|
data: {
|
||||||
|
name: idWarga,
|
||||||
|
phone,
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
idWargaFix = wargaCreate.id
|
||||||
|
} else {
|
||||||
|
idWargaFix = cariWarga.id
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
const pengaduan = await prisma.pengaduan.create({
|
const pengaduan = await prisma.pengaduan.create({
|
||||||
data: {
|
data: {
|
||||||
title,
|
title,
|
||||||
detail,
|
detail,
|
||||||
idCategory,
|
idCategory: idCategoryFix,
|
||||||
idWarga,
|
idWarga: idWargaFix,
|
||||||
location,
|
location,
|
||||||
image,
|
image,
|
||||||
noPengaduan,
|
noPengaduan,
|
||||||
@@ -138,13 +191,15 @@ const PengaduanRoute = new Elysia({
|
|||||||
title: t.String({ minLength: 1, error: "title harus diisi" }),
|
title: t.String({ minLength: 1, error: "title harus diisi" }),
|
||||||
detail: t.String({ minLength: 1, error: "detail harus diisi" }),
|
detail: t.String({ minLength: 1, error: "detail harus diisi" }),
|
||||||
location: t.String({ minLength: 1, error: "location harus diisi" }),
|
location: t.String({ minLength: 1, error: "location harus diisi" }),
|
||||||
image: t.String({ minLength: 1, error: "image harus diisi" }),
|
image: t.Any(),
|
||||||
idCategory: t.String({ minLength: 1, error: "idCategory harus diisi" }),
|
idCategory: t.String({ minLength: 1, error: "idCategory harus diisi" }),
|
||||||
idWarga: t.String({ minLength: 1, error: "idWarga harus diisi" }),
|
idWarga: t.String({ minLength: 1, error: "idWarga harus diisi" }),
|
||||||
|
phone: t.String({ minLength: 1, error: "phone harus diisi" }),
|
||||||
}),
|
}),
|
||||||
detail: {
|
detail: {
|
||||||
summary: "buat pengaduan",
|
summary: "Create Pengaduan Warga",
|
||||||
description: `tool untuk membuat pengaduan`
|
description: `tool untuk membuat pengaduan warga`,
|
||||||
|
tags: ["mcp"]
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.post("/update-status", async ({ body }) => {
|
.post("/update-status", async ({ body }) => {
|
||||||
@@ -197,7 +252,7 @@ const PengaduanRoute = new Elysia({
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
detail: {
|
detail: {
|
||||||
summary: "update status pengaduan",
|
summary: "Update status pengaduan",
|
||||||
description: `tool untuk update status pengaduan`
|
description: `tool untuk update status pengaduan`
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -282,8 +337,81 @@ const PengaduanRoute = new Elysia({
|
|||||||
return datafix
|
return datafix
|
||||||
}, {
|
}, {
|
||||||
detail: {
|
detail: {
|
||||||
summary: "get detail pengaduan",
|
summary: "Detail Pengaduan Warga",
|
||||||
description: `tool untuk mendapatkan detail pengaduan`
|
description: `tool untuk mendapatkan detail pengaduan warga / history pengaduan / mengecek status pengaduan`,
|
||||||
|
tags: ["mcp"]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.get("/", async ({ query }) => {
|
||||||
|
const { take, page, search } = query
|
||||||
|
const skip = !page ? 0 : (Number(page) - 1) * (!take ? 10 : Number(take))
|
||||||
|
|
||||||
|
const data = await prisma.pengaduan.findMany({
|
||||||
|
skip,
|
||||||
|
take: !take ? 10 : Number(take),
|
||||||
|
orderBy: {
|
||||||
|
createdAt: "asc"
|
||||||
|
},
|
||||||
|
where: {
|
||||||
|
isActive: true,
|
||||||
|
OR: [
|
||||||
|
{
|
||||||
|
title: {
|
||||||
|
contains: search ?? "",
|
||||||
|
mode: "insensitive"
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
noPengaduan: {
|
||||||
|
contains: search ?? "",
|
||||||
|
mode: "insensitive"
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
detail: {
|
||||||
|
contains: search ?? "",
|
||||||
|
mode: "insensitive"
|
||||||
|
},
|
||||||
|
}
|
||||||
|
],
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
noPengaduan: true,
|
||||||
|
title: true,
|
||||||
|
detail: true,
|
||||||
|
location: true,
|
||||||
|
status: true,
|
||||||
|
createdAt: true,
|
||||||
|
CategoryPengaduan: {
|
||||||
|
select: {
|
||||||
|
name: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Warga: {
|
||||||
|
select: {
|
||||||
|
name: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const dataFix = data.map((item) => {
|
||||||
|
return {
|
||||||
|
noPengaduan: item.noPengaduan,
|
||||||
|
title: item.title,
|
||||||
|
detail: item.detail,
|
||||||
|
status: item.status,
|
||||||
|
createdAt: item.createdAt.toLocaleDateString("id-ID", { day: "numeric", month: "long", year: "numeric" }),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return dataFix
|
||||||
|
}, {
|
||||||
|
detail: {
|
||||||
|
summary: "List Pengaduan Warga",
|
||||||
|
description: `tool untuk mendapatkan list pengaduan warga`,
|
||||||
|
tags: ["mcp"]
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
export default PengaduanRoute
|
export default PengaduanRoute
|
||||||
|
|||||||
Reference in New Issue
Block a user