upd: profile dan katalog

Deskripsi:
- mecah dan ganti ke api

No Issues
This commit is contained in:
amel
2024-12-05 17:21:59 +08:00
parent 2fa96d47ba
commit 66c65bc937
14 changed files with 444 additions and 42 deletions

View File

@@ -0,0 +1,55 @@
import { prisma } from "@/app/lib";
import { NextResponse } from "next/server";
// GET ALL DATA PORTOFOLIO BY PROFILE ID
export async function GET(request: Request) {
try {
let fixData
const { searchParams } = new URL(request.url)
const profile = searchParams.get("profile")
const page = searchParams.get("page")
if (page == "profile") {
fixData = await prisma.portofolio.findMany({
take: 2,
orderBy: {
createdAt: "desc",
},
where: {
profileId: profile,
active: true,
},
select: {
id: true,
id_Portofolio: true,
namaBisnis: true,
profileId: true,
},
});
} else if (page == "portofolio") {
fixData = await prisma.portofolio.findMany({
orderBy: {
createdAt: "desc",
},
where: {
profileId: profile,
active: true,
},
select: {
id: true,
id_Portofolio: true,
namaBisnis: true,
profileId: true,
},
});
}
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

@@ -1,53 +1,50 @@
import { prisma } from "@/app/lib";
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
import { NextResponse } from "next/server";
// GET DATA USER LOGIN
// GET ONE DATA USER PROFILE BY PROFILE ID
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 { searchParams } = new URL(request.url)
const profile = searchParams.get("profile")
const data = await prisma.user.findFirst({
const data = await prisma.profile.findUnique({
where: {
id: userLoginId,
id: String(profile),
},
select: {
id: true,
username: true,
nomor: true,
active: true,
masterUserRoleId: true,
Profile: {
name: true,
email: true,
alamat: true,
jenisKelamin: true,
imageId: true,
imageBackgroundId: true,
userId: true,
User: {
select: {
id: true,
name: true,
email: true,
alamat: true,
jenisKelamin: true,
imageId: true,
imageBackgroundId: true
username: true,
nomor: true,
active: true,
masterUserRoleId: 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
id: data?.userId,
username: data?.User?.username,
nomor: data?.User?.nomor,
active: data?.User?.active,
masterUserRoleId: data?.User?.masterUserRoleId,
idProfile: data?.id,
name: data?.name,
email: data?.email,
alamat: data?.alamat,
jenisKelamin: data?.jenisKelamin,
imageId: data?.imageId,
imageBackgroundId: data?.imageBackgroundId
}