Merge pull request #160 from bipproduction/amalia/05-des-24
Amalia/05 des 24
This commit is contained in:
68
src/app/api/new/home/route.ts
Normal file
68
src/app/api/new/home/route.ts
Normal 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 });
|
||||
}
|
||||
}
|
||||
55
src/app/api/new/portofolio/route.ts
Normal file
55
src/app/api/new/portofolio/route.ts
Normal 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 });
|
||||
}
|
||||
}
|
||||
58
src/app/api/new/user/route.ts
Normal file
58
src/app/api/new/user/route.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import { prisma } from "@/app/lib";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
|
||||
// GET ONE DATA USER PROFILE BY PROFILE ID
|
||||
export async function GET(request: Request) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url)
|
||||
const profile = searchParams.get("profile")
|
||||
|
||||
const data = await prisma.profile.findUnique({
|
||||
where: {
|
||||
id: String(profile),
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
email: true,
|
||||
alamat: true,
|
||||
jenisKelamin: true,
|
||||
imageId: true,
|
||||
imageBackgroundId: true,
|
||||
userId: true,
|
||||
User: {
|
||||
select: {
|
||||
username: true,
|
||||
nomor: true,
|
||||
active: true,
|
||||
masterUserRoleId: true
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const dataFix = {
|
||||
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
|
||||
|
||||
}
|
||||
|
||||
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 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user