fix portofolio map

This commit is contained in:
2025-02-13 14:43:56 +08:00
parent 542e36345d
commit f9e72a51bb
3 changed files with 48 additions and 36 deletions

View File

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