diff --git a/src/app/api/home/search/route.ts b/src/app/api/home/search/route.ts index fd9c017..103220d 100644 --- a/src/app/api/home/search/route.ts +++ b/src/app/api/home/search/route.ts @@ -4,12 +4,13 @@ import { prisma } from "@/module/_global"; import { funGetUserByCookies } from "@/module/auth"; +import _ from "lodash"; import { NextResponse } from "next/server"; export async function GET(request: Request) { try { - const { searchParams } = new URL(request.url); - const search = searchParams.get("search"); + const { searchParams } = new URL(request.url) + const search = searchParams.get("search") const userId = await funGetUserByCookies() if (userId.id == undefined) { return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 }); @@ -69,31 +70,68 @@ export async function GET(request: Request) { select: { id: true, name: true, - email: true + email: true, + img: true, + Position: { + select: { + name: true + } + }, + Group: { + select: { + name: true + } + } } }) + const userOmit = user.map((v: any) => ({ + ..._.omit(v, ["Position", "Group"]), + position: v.Position.name, + group: v.Group.name + })) + const divisions = await prisma.division.findMany({ where: kondisi, select: { id: true, name: true, - desc: true + desc: true, + Group: { + select: { + name: true + } + } } }) + const divisionOmit = divisions.map((v: any) => ({ + ..._.omit(v, ["Group"]), + group: v.Group.name + })) + const projects = await prisma.project.findMany({ where: kondisiProject, select: { id: true, title: true, + Group: { + select: { + name: true + } + } } }) + const projectOmit = projects.map((v: any) => ({ + ..._.omit(v, ["Group"]), + group: v.Group.name + })) + const allDataSearch = { - user: user, - division: divisions, - project: projects + user: userOmit, + division: divisionOmit, + project: projectOmit } return NextResponse.json({ success: true, data: allDataSearch }, { status: 200 }); diff --git a/src/module/home/lib/type_search.ts b/src/module/home/lib/type_search.ts index d2100d7..22bbc1a 100644 --- a/src/module/home/lib/type_search.ts +++ b/src/module/home/lib/type_search.ts @@ -2,15 +2,20 @@ export interface IDataUserSearch { id: string name: string email: string + position: string + group: string + img: string +} + +export interface IDataProjectSearch { + id: string + title: string + group: string } export interface IDataDivisionSearch { - id: string - title: string -} - -export interface IDataProjectSearch { id: string name: string desc: string - } + group: string +} diff --git a/src/module/home/ui/view_detail_feature.tsx b/src/module/home/ui/view_detail_feature.tsx index 3e88820..6c46c01 100644 --- a/src/module/home/ui/view_detail_feature.tsx +++ b/src/module/home/ui/view_detail_feature.tsx @@ -98,7 +98,7 @@ export default function ViewDetailFeature() {