From f9e72a51bb5b39c49ae5aaab8bd74db49d77330f Mon Sep 17 00:00:00 2001 From: Bagasbanuna02 Date: Thu, 13 Feb 2025 14:43:56 +0800 Subject: [PATCH] fix portofolio map --- src/app/api/new/map/route.ts | 74 +++++++++++-------- .../map/_component/detail_data.tsx | 6 +- src/app_modules/map/ui/ui_map_new.tsx | 4 +- 3 files changed, 48 insertions(+), 36 deletions(-) diff --git a/src/app/api/new/map/route.ts b/src/app/api/new/map/route.ts index 42ec8dcf..61805cbf 100644 --- a/src/app/api/new/map/route.ts +++ b/src/app/api/new/map/route.ts @@ -3,38 +3,50 @@ import _ from "lodash"; import { NextResponse } from "next/server"; export const dynamic = "force-dynamic"; - // GET ALL DATA MAP export async function GET(request: Request) { - try { - const data = await prisma.businessMaps.findMany({ - where: { - isActive: true, - }, - select: { - id: true, - namePin: true, - latitude: true, - longitude: true, - pinId: true, - Portofolio: { - select: { - logoId: true, - } - } - } - }); + try { + const data = await prisma.businessMaps.findMany({ + where: { + isActive: true, + Portofolio: { + NOT: { + logoId: null, + }, + }, + }, + select: { + id: true, + namePin: true, + latitude: true, + longitude: true, + pinId: true, + Portofolio: { + select: { + logoId: true, + }, + }, + }, + }); - const dataFix = data.map((v: any) => ({ - ..._.omit(v, ["Portofolio"]), - logoId: v.Portofolio.logoId - })) + const dataFix = data.map((v: any) => ({ + ..._.omit(v, ["Portofolio"]), + logoId: v.Portofolio.logoId, + })); - return NextResponse.json({ success: true, message: "Berhasil mendapatkan data", data: dataFix }, { status: 200 }); - - } - catch (error) { - console.error(error); - return NextResponse.json({ success: false, message: "Gagal mendapatkan data, coba lagi nanti ", reason: (error as Error).message, }, { status: 500 }); - } -} \ No newline at end of file + return NextResponse.json( + { success: true, message: "Berhasil mendapatkan data", data: dataFix }, + { status: 200 } + ); + } catch (error) { + console.error(error); + return NextResponse.json( + { + success: false, + message: "Gagal mendapatkan data, coba lagi nanti ", + reason: (error as Error).message, + }, + { status: 500 } + ); + } +} diff --git a/src/app_modules/map/_component/detail_data.tsx b/src/app_modules/map/_component/detail_data.tsx index 0d0b6dc3..2e1f1602 100644 --- a/src/app_modules/map/_component/detail_data.tsx +++ b/src/app_modules/map/_component/detail_data.tsx @@ -35,10 +35,10 @@ export function ComponentMap_DetailData({ const [openModal, setOpenModal] = useState(false); useShallowEffect(() => { - onLoadData(setData, setDataUser); - }, [setData, setDataUser]); + onLoadData(); + }, []); - async function onLoadData(setData: any, setDataUser: any) { + async function onLoadData() { const res: any = await map_funGetOneById({ mapId: mapId }); setData(res); setDataUser(res.Author); diff --git a/src/app_modules/map/ui/ui_map_new.tsx b/src/app_modules/map/ui/ui_map_new.tsx index fd851eab..34002068 100644 --- a/src/app_modules/map/ui/ui_map_new.tsx +++ b/src/app_modules/map/ui/ui_map_new.tsx @@ -1,7 +1,7 @@ "use client"; -import { APIs } from "@/lib"; import { AccentColor } from "@/app_modules/_global/color/color_pallet"; import ComponentGlobal_IsEmptyData from "@/app_modules/_global/component/is_empty_data"; +import { APIs } from "@/lib"; import { Avatar, Loader, Stack } from "@mantine/core"; import { useShallowEffect } from "@mantine/hooks"; import "mapbox-gl/dist/mapbox-gl.css"; @@ -64,7 +64,7 @@ export function UiMap_MapBoxViewNew({ mapboxToken, }: { mapboxToken: string }) { }} attributionControl={false} > - {data.map((e, i) => ( + {data?.map((e, i) => (