deskripsi:
- pemanggilan api di rapikan
This commit is contained in:
2025-02-04 11:10:10 +08:00
parent 61845b0e50
commit 51105a24c8
9 changed files with 225 additions and 246 deletions

View File

@@ -3,67 +3,82 @@ import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
import { NextResponse } from "next/server";
export const dynamic = "force-dynamic";
// GET DATA HOME
export async function GET(request: Request) {
try {
let fixData
const { searchParams } = new URL(request.url)
const kategori = searchParams.get("cat")
try {
let fixData;
const { searchParams } = new URL(request.url);
const kategori = searchParams.get("cat");
const userLoginId = await funGetUserIdByToken()
if (userLoginId == null) {
return NextResponse.json({ success: false, message: "Gagal mendapatkan data, user id tidak ada" }, { status: 500 });
}
const userLoginId = await funGetUserIdByToken();
if (userLoginId == null) {
return NextResponse.json(
{
success: false,
message: "Gagal mendapatkan data, user id tidak ada",
},
{ status: 500 }
);
}
if (kategori == "job") {
fixData = await prisma.job.findMany({
take: 2,
orderBy: {
createdAt: "desc",
},
where: {
isActive: true,
masterStatusId: "1"
},
if (kategori == "job") {
fixData = await prisma.job.findMany({
take: 2,
orderBy: {
createdAt: "desc",
},
where: {
isActive: true,
masterStatusId: "1",
},
select: {
id: true,
Author: {
select: {
id: true,
Author: {
select: {
id: true,
username: true,
},
},
title: true,
deskripsi: true
id: true,
username: true,
},
});
} else if (kategori == "cek_profile") {
const data = await prisma.user.findUnique({
where: {
id: userLoginId,
},
title: true,
deskripsi: true,
},
});
} else if (kategori == "cek_profile") {
const data = await prisma.user.findUnique({
where: {
id: userLoginId,
},
include: {
Profile: {
select: {
id: true,
imageId: true,
},
include: {
Profile: {
select: {
id: true,
imageId: true,
}
}
}
});
},
},
});
fixData = {
profile: data?.Profile?.id,
imageId: data?.Profile?.imageId
}
fixData = {
profile: data?.Profile?.id,
imageId: data?.Profile?.imageId,
};
}
}
return NextResponse.json({ success: true, message: "Berhasil mendapatkan data", data: fixData }, { 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: fixData },
{ 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 }
);
} finally {
await prisma.$disconnect();
}
}