142 lines
3.2 KiB
TypeScript
142 lines
3.2 KiB
TypeScript
import Elysia, { t } from "elysia";
|
|
import _ from "lodash";
|
|
import { normalizePhoneNumber } from "../lib/normalizePhone";
|
|
import { prisma } from "../lib/prisma";
|
|
|
|
const WargaRoute = new Elysia({
|
|
prefix: "warga",
|
|
tags: ["warga"],
|
|
})
|
|
|
|
.get("/list", async ({ query }) => {
|
|
const { search } = query
|
|
|
|
const data = await prisma.warga.findMany({
|
|
where: {
|
|
OR: [
|
|
{
|
|
name: {
|
|
contains: search,
|
|
mode: "insensitive"
|
|
}
|
|
},
|
|
{
|
|
phone: {
|
|
contains: search,
|
|
mode: "insensitive"
|
|
}
|
|
}
|
|
]
|
|
},
|
|
orderBy: {
|
|
name: "asc"
|
|
}
|
|
})
|
|
|
|
return data
|
|
}, {
|
|
detail: {
|
|
summary: "List Warga",
|
|
description: `tool untuk mendapatkan list warga`,
|
|
}
|
|
})
|
|
.post("/edit", async ({ body }) => {
|
|
const { id, name, phone } = body
|
|
|
|
const nomorHP = normalizePhoneNumber({ phone })
|
|
await prisma.warga.update({
|
|
where: {
|
|
id,
|
|
},
|
|
data: {
|
|
name,
|
|
phone: nomorHP
|
|
}
|
|
})
|
|
|
|
return { success: true, message: 'data warga sudah diperbarui' }
|
|
}, {
|
|
body: t.Object({
|
|
id: t.String({ minLength: 1, error: "id harus diisi" }),
|
|
name: t.String({ minLength: 1, error: "value harus diisi" }),
|
|
phone: t.String({ minLength: 1 })
|
|
}),
|
|
detail: {
|
|
summary: "edit konfigurasi desa",
|
|
description: `tool untuk edit konfigurasi desa`
|
|
}
|
|
})
|
|
.get("/detail", async ({ query }) => {
|
|
const { id } = query
|
|
const dataWarga = await prisma.warga.findUnique({
|
|
where: {
|
|
id
|
|
}
|
|
})
|
|
|
|
const dataPengaduan = await prisma.pengaduan.findMany({
|
|
orderBy: {
|
|
createdAt: "desc"
|
|
},
|
|
where: {
|
|
isActive: true,
|
|
idWarga: id
|
|
},
|
|
select: {
|
|
id: true,
|
|
status: true,
|
|
noPengaduan: true,
|
|
title: true
|
|
}
|
|
})
|
|
|
|
|
|
|
|
const dataPelayanan = await prisma.pelayananAjuan.findMany({
|
|
orderBy: {
|
|
createdAt: "desc"
|
|
},
|
|
where: {
|
|
isActive: true,
|
|
idWarga: id
|
|
},
|
|
select: {
|
|
id: true,
|
|
noPengajuan: true,
|
|
status: true,
|
|
CategoryPelayanan: {
|
|
select: {
|
|
name: true
|
|
}
|
|
}
|
|
}
|
|
})
|
|
|
|
const dataPelayanFix = dataPelayanan.map((v: any) => ({
|
|
..._.omit(v, ["CategoryPelayanan"]),
|
|
id: v.id,
|
|
noPengaduan: v.noPengajuan,
|
|
status: v.status,
|
|
category: v.CategoryPelayanan.name
|
|
}))
|
|
|
|
return {
|
|
warga: dataWarga,
|
|
pengaduan: dataPengaduan,
|
|
pelayanan: dataPelayanFix
|
|
}
|
|
|
|
}, {
|
|
query: t.Object({
|
|
id: t.String({ minLength: 1, error: "id harus diisi" })
|
|
}),
|
|
detail: {
|
|
summary: "Detail Warga",
|
|
description: `tool untuk mendapatkan detail warga`,
|
|
}
|
|
|
|
})
|
|
;
|
|
|
|
export default WargaRoute
|