upd: api pengaduan
Deskripsi: - update seeder kategori pengaduan - list pengaduan warga NO Issues
This commit is contained in:
@@ -1,5 +1,28 @@
|
||||
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 = [
|
||||
{
|
||||
id: "developer",
|
||||
@@ -36,7 +59,7 @@ const user = [
|
||||
|
||||
console.log(`✅ Role ${r.name} seeded successfully`)
|
||||
}
|
||||
|
||||
|
||||
for (const u of user) {
|
||||
await prisma.user.upsert({
|
||||
where: { email: u.email },
|
||||
@@ -47,7 +70,17 @@ const user = [
|
||||
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) => {
|
||||
|
||||
@@ -18,8 +18,9 @@ const PengaduanRoute = new Elysia({
|
||||
return data
|
||||
}, {
|
||||
detail: {
|
||||
summary: "get kategori pengaduan",
|
||||
description: `tool untuk mendapatkan kategori pengaduan`
|
||||
summary: "List Kategori Pengaduan",
|
||||
description: `tool untuk mendapatkan list kategori pengaduan`,
|
||||
tags: ["mcp"]
|
||||
}
|
||||
})
|
||||
.post("/category/create", async ({ body }) => {
|
||||
@@ -100,15 +101,67 @@ const PengaduanRoute = new Elysia({
|
||||
|
||||
// --- PENGADUAN ---
|
||||
.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()
|
||||
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({
|
||||
data: {
|
||||
title,
|
||||
detail,
|
||||
idCategory,
|
||||
idWarga,
|
||||
idCategory: idCategoryFix,
|
||||
idWarga: idWargaFix,
|
||||
location,
|
||||
image,
|
||||
noPengaduan,
|
||||
@@ -138,13 +191,15 @@ 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.String({ minLength: 1, error: "image harus diisi" }),
|
||||
image: t.Any(),
|
||||
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" }),
|
||||
}),
|
||||
detail: {
|
||||
summary: "buat pengaduan",
|
||||
description: `tool untuk membuat pengaduan`
|
||||
summary: "Create Pengaduan Warga",
|
||||
description: `tool untuk membuat pengaduan warga`,
|
||||
tags: ["mcp"]
|
||||
}
|
||||
})
|
||||
.post("/update-status", async ({ body }) => {
|
||||
@@ -197,7 +252,7 @@ const PengaduanRoute = new Elysia({
|
||||
}),
|
||||
|
||||
detail: {
|
||||
summary: "update status pengaduan",
|
||||
summary: "Update status pengaduan",
|
||||
description: `tool untuk update status pengaduan`
|
||||
}
|
||||
})
|
||||
@@ -282,8 +337,81 @@ const PengaduanRoute = new Elysia({
|
||||
return datafix
|
||||
}, {
|
||||
detail: {
|
||||
summary: "get detail pengaduan",
|
||||
description: `tool untuk mendapatkan detail pengaduan`
|
||||
summary: "Detail Pengaduan Warga",
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user