fix :home

Deskripsi:
- home pake api

No Issues
This commit is contained in:
amel
2024-12-05 15:12:18 +08:00
parent ac3c1569d0
commit 2fa96d47ba
13 changed files with 667 additions and 10 deletions

View File

@@ -0,0 +1,68 @@
import { prisma } from "@/app/lib";
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
import { NextResponse } from "next/server";
// GET DATA HOME
export async function GET(request: Request) {
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 });
}
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,
username: true,
},
},
title: true,
deskripsi: true
},
});
} else if (kategori == "cek_profile") {
const data = await prisma.user.findUnique({
where: {
id: userLoginId,
},
select: {
Profile: {
select: {
id: true,
imageId: true,
}
}
}
});
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 });
}
}

View File

@@ -0,0 +1,61 @@
import { prisma } from "@/app/lib";
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
import { NextResponse } from "next/server";
// GET DATA USER LOGIN
export async function GET(request: Request) {
try {
const userLoginId = await funGetUserIdByToken()
if (userLoginId == null) {
return NextResponse.json({ success: false, message: "Gagal mendapatkan data, user id tidak ada" }, { status: 500 });
}
const data = await prisma.user.findFirst({
where: {
id: userLoginId,
},
select: {
id: true,
username: true,
nomor: true,
active: true,
masterUserRoleId: true,
Profile: {
select: {
id: true,
name: true,
email: true,
alamat: true,
jenisKelamin: true,
imageId: true,
imageBackgroundId: true
}
}
}
});
const dataFix = {
id: data?.id,
username: data?.username,
nomor: data?.nomor,
active: data?.active,
masterUserRoleId: data?.masterUserRoleId,
idProfile: data?.Profile?.id,
name: data?.Profile?.name,
email: data?.Profile?.email,
alamat: data?.Profile?.alamat,
jenisKelamin: data?.Profile?.jenisKelamin,
imageId: data?.Profile?.imageId,
imageBackgroundId: data?.Profile?.imageBackgroundId
}
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 });
}
}

View File

@@ -1,23 +1,21 @@
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
import { HomeView } from "@/app_modules/home";
import { user_getOneByUserId } from "@/app_modules/home/fun/get/get_one_user_by_id";
import { job_getTwoForHomeView } from "@/app_modules/job/fun/get/get_two_for_home_view";
import { HomeViewNew } from "@/app_modules/home";
import notifikasi_countUserNotifikasi from "@/app_modules/notifikasi/fun/count/fun_count_by_id";
export default async function PageHome() {
const userLoginId = await funGetUserIdByToken();
const dataUser = await user_getOneByUserId(userLoginId as string);
const dataJob = await job_getTwoForHomeView();
// const userLoginId = await funGetUserIdByToken();
// const dataUser = await user_getOneByUserId(userLoginId as string);
// const dataJob = await job_getTwoForHomeView();
const countNotifikasi = await notifikasi_countUserNotifikasi();
return (
<>
<HomeView
{/* <HomeView
dataUser={dataUser as any}
dataJob={dataJob as any}
countNotifikasi={countNotifikasi}
/>
/> */}
<HomeViewNew countNotifikasi={countNotifikasi} />
</>
);
}