upd: search

deskripsi:
- cek search
- img profile
- link sesuai fitur
- pembatasan sesuai role

No Issues
This commit is contained in:
amel
2024-08-29 17:22:29 +08:00
parent 2ce1f204ed
commit fb5b23a30d
4 changed files with 126 additions and 68 deletions

View File

@@ -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 });