fix: search api
Deskripsi: - fix search api pencarian - upd api version app No Issues
This commit is contained in:
@@ -13,11 +13,26 @@ export async function GET(request: Request) {
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
||||
}
|
||||
|
||||
let kondisi: any, kondisiProject: any
|
||||
let kondisi: any, kondisiProject: any, kondisiDivision: any
|
||||
|
||||
// klo perbekel/developer == semua grup
|
||||
if (userId.idUserRole == "supadmin" || userId.idUserRole == "developer") {
|
||||
kondisi = {
|
||||
isActive: true,
|
||||
idVillage: userId.idVillage,
|
||||
Group: {
|
||||
isActive: true,
|
||||
},
|
||||
name: {
|
||||
contains: (search == undefined || search == null) ? "" : search,
|
||||
mode: "insensitive"
|
||||
},
|
||||
NOT: {
|
||||
idUserRole: "developer"
|
||||
}
|
||||
}
|
||||
|
||||
kondisiDivision = {
|
||||
isActive: true,
|
||||
idVillage: userId.idVillage,
|
||||
Group: {
|
||||
@@ -42,6 +57,19 @@ export async function GET(request: Request) {
|
||||
}
|
||||
} else {
|
||||
kondisi = {
|
||||
idVillage: userId.idVillage,
|
||||
isActive: true,
|
||||
idGroup: userId.idGroup,
|
||||
name: {
|
||||
contains: (search == undefined || search == null) ? "" : search,
|
||||
mode: "insensitive"
|
||||
},
|
||||
NOT: {
|
||||
idUserRole: "developer"
|
||||
}
|
||||
}
|
||||
|
||||
kondisiDivision = {
|
||||
idVillage: userId.idVillage,
|
||||
isActive: true,
|
||||
idGroup: userId.idGroup,
|
||||
@@ -84,12 +112,12 @@ export async function GET(request: Request) {
|
||||
|
||||
const userOmit = user.map((v: any) => ({
|
||||
..._.omit(v, ["Position", "Group"]),
|
||||
position: v.Position.name,
|
||||
position: v.Position?.name,
|
||||
group: v.Group.name
|
||||
}))
|
||||
|
||||
const divisions = await prisma.division.findMany({
|
||||
where: kondisi,
|
||||
where: kondisiDivision,
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
@@ -133,6 +161,7 @@ export async function GET(request: Request) {
|
||||
return NextResponse.json({ success: true, data: allDataSearch }, { status: 200 });
|
||||
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
return NextResponse.json({ success: false, message: 'Gagal mendapatkan data, coba lagi nanti (error: 500)' }, { status: 500 });
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@ import { NextResponse } from "next/server";
|
||||
|
||||
export async function GET(request: Request) {
|
||||
try {
|
||||
return NextResponse.json({ success: true, version: "1.4.1", tahap: "beta", update: "- user role developer; -pencarian minimal 3 karakter; -fitur baca semua notifikasi disable saat tidak ada notifikasi yg blm dibaca; -fix: route back diskusi general tambah member" }, { status: 200 });
|
||||
return NextResponse.json({ success: true, version: "1.4.2", tahap: "beta", update: "- user role developer; -pencarian minimal 3 karakter; -fitur baca semua notifikasi disable saat tidak ada notifikasi yg blm dibaca; -fix: route back diskusi general tambah member; -fix:api search error" }, { status: 200 });
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return NextResponse.json({ success: false, version: "Gagal mendapatkan version, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
|
||||
|
||||
Reference in New Issue
Block a user