upd: list pengaduan

This commit is contained in:
2025-12-10 11:44:22 +08:00
parent 84c9f405d6
commit 20e3056e04

View File

@@ -1,6 +1,6 @@
import Elysia, { t } from "elysia" import Elysia, { t } from "elysia"
import type { StatusPengaduan } from "generated/prisma" import type { StatusPengaduan } from "generated/prisma"
import _ from "lodash" import _, { head } from "lodash"
import { v4 as uuidv4 } from "uuid" import { v4 as uuidv4 } from "uuid"
import { getLastUpdated } from "../lib/get-last-updated" import { getLastUpdated } from "../lib/get-last-updated"
import { mimeToExtension } from "../lib/mimetypeToExtension" import { mimeToExtension } from "../lib/mimetypeToExtension"
@@ -478,43 +478,44 @@ const PengaduanRoute = new Elysia({
tags: ["mcp"] tags: ["mcp"]
} }
}) })
.get("/", async ({ query }) => { .get("/", async ({ query, headers }) => {
const { take, page, search, phone } = query // const { take, page, search } = query
const skip = !page ? 0 : (Number(page) - 1) * (!take ? 10 : Number(take)) const phone = headers['x-phone'] || ""
// const skip = !page ? 0 : (Number(page) - 1) * (!take ? 10 : Number(take))
const data = await prisma.pengaduan.findMany({ const data = await prisma.pengaduan.findMany({
skip, // skip,
take: !take ? 10 : Number(take), // take: !take ? 10 : Number(take),
orderBy: { orderBy: {
createdAt: "asc" createdAt: "asc"
}, },
where: { where: {
isActive: true, isActive: true,
OR: [ // OR: [
{ // {
title: { // title: {
contains: search ?? "", // contains: search ?? "",
mode: "insensitive" // mode: "insensitive"
}, // },
}, // },
{ // {
noPengaduan: { // noPengaduan: {
contains: search ?? "", // contains: search ?? "",
mode: "insensitive" // mode: "insensitive"
}, // },
}, // },
{ // {
detail: { // detail: {
contains: search ?? "", // contains: search ?? "",
mode: "insensitive" // mode: "insensitive"
}, // },
} // }
], // ],
AND: { // AND: {
Warga: { // Warga: {
phone: phone // phone: phone
} // }
} // }
}, },
select: { select: {
id: true, id: true,
@@ -549,12 +550,11 @@ const PengaduanRoute = new Elysia({
return dataFix return dataFix
}, { }, {
query: t.Object({ // query: t.Object({
take: t.String({ optional: true }), // take: t.String({ optional: true }),
page: t.String({ optional: true }), // page: t.String({ optional: true }),
search: t.String({ optional: true }), // search: t.String({ optional: true }),
phone: t.String({ minLength: 11, error: "phone harus diisi" }), // }),
}),
detail: { detail: {
summary: "List Pengaduan Warga By Phone", summary: "List Pengaduan Warga By Phone",
description: `tool untuk mendapatkan list pengaduan warga by phone`, description: `tool untuk mendapatkan list pengaduan warga by phone`,