This commit is contained in:
2025-02-06 10:55:50 +08:00
96 changed files with 1759 additions and 2008 deletions

View File

@@ -0,0 +1,30 @@
import { prisma } from "@/app/lib";
import backendLogger from "@/util/backendLogger";
import { NextRequest, NextResponse } from "next/server";
export const dynamic = "force-dynamic";
export async function GET(
request: Request,
{ params }: { params: { id: string } }
) {
if (request.method !== "GET") {
return NextResponse.json(
{ success: false, message: "Method not allowed" },
{ status: 405 }
);
}
try {
const { id } = params;
const data = await prisma.kodeOtp.findFirst({
where: {
id: id as string,
},
});
return NextResponse.json(data, { status: 200 });
} catch (error) {
backendLogger.error("Error get code otp", error); //(error);
return NextResponse.json(null, { status: 500 });
}
}

View File

@@ -1,24 +0,0 @@
import { prisma } from "@/app/lib";
import { data } from "autoprefixer";
import { NextRequest, NextResponse } from "next/server";
export const dynamic = "force-dynamic";
export async function GET(request: NextRequest) {
const id = request.nextUrl.searchParams.get("id");
// const { searchParams } = new URL(request.url);
// const id = searchParams.get("id");
try {
const data = await prisma.kodeOtp.findFirst({
where: {
id: id as string,
},
});
return NextResponse.json(data, { status: 200 });
} catch (error) {
console.log(error);
}
return NextResponse.json(null, { status: 500 });
}

View File

@@ -0,0 +1,56 @@
import { prisma } from "@/app/lib";
import backendLogger from "@/util/backendLogger";
import { NextResponse } from "next/server";
export { DELETE };
async function DELETE(
request: Request,
{ params }: { params: { id: string } }
) {
if (request.method !== "DELETE") {
return NextResponse.json(
{ success: false, message: "Method not allowed" },
{ status: 405 }
);
}
try {
// Ambil parameter id dari URL
const { id } = params;
if (!id) {
return NextResponse.json(
{
success: false,
message: "Parameter 'id' diperlukan",
},
{ status: 400 }
);
}
// Hapus data OTP
await prisma.kodeOtp.delete({
where: {
id: id,
},
});
return NextResponse.json(
{
success: true,
message: "Berhasil menghapus data OTP",
},
{ status: 200 }
);
} catch (error) {
backendLogger.error("Error deleting OTP:", error);
return NextResponse.json(
{
success: false,
message: "Terjadi kesalahan saat menghapus data OTP",
},
{ status: 500 }
);
} finally {
await prisma.$disconnect();
}
}

View File

@@ -4,59 +4,60 @@ import backendLogger from "@/util/backendLogger";
import { NextResponse } from "next/server";
export async function POST(req: Request) {
if (req.method === "POST") {
if (req.method !== "POST") {
return NextResponse.json(
{ success: false, message: "Method Not Allowed" },
{ status: 405 }
);
}
try {
const codeOtp = randomOTP();
const body = await req.json();
const { nomor } = body;
try {
const res = await fetch(
`https://wa.wibudev.com/code?nom=${nomor}&text=HIPMI - Kode ini bersifat RAHASIA dan JANGAN DI BAGIKAN KEPADA SIAPAPUN, termasuk anggota ataupun pengurus HIPMI lainnya.
const res = await fetch(
`https://wa.wibudev.com/code?nom=${nomor}&text=HIPMI - Kode ini bersifat RAHASIA dan JANGAN DI BAGIKAN KEPADA SIAPAPUN, termasuk anggota ataupun pengurus HIPMI lainnya.
\n
>> Kode OTP anda: ${codeOtp}.
`
);
);
const sendWa = await res.json();
if (sendWa.status !== "success")
return NextResponse.json(
{ success: false, message: "Nomor Whatsapp Tidak Aktif" },
{ status: 400 }
);
const createOtpId = await prisma.kodeOtp.create({
data: {
nomor: nomor,
otp: codeOtp,
},
});
if (!createOtpId)
return NextResponse.json(
{ success: false, message: "Gagal Membuat Kode OTP" },
{ status: 400 }
);
const sendWa = await res.json();
if (sendWa.status !== "success")
return NextResponse.json(
{
success: true,
message: "Kode Verifikasi Dikirim",
kodeId: createOtpId.id,
},
{ status: 200 }
{ success: false, message: "Nomor Whatsapp Tidak Aktif" },
{ status: 400 }
);
} catch (error) {
backendLogger.log("Error Login", error);
const createOtpId = await prisma.kodeOtp.create({
data: {
nomor: nomor,
otp: codeOtp,
},
});
if (!createOtpId)
return NextResponse.json(
{ success: false, message: error as Error },
{ status: 500 }
{ success: false, message: "Gagal mengirim kode OTP" },
{ status: 400 }
);
}
return NextResponse.json(
{
success: true,
message: "Kode verifikasi terkirim",
kodeId: createOtpId.id,
},
{ status: 200 }
);
} catch (error) {
backendLogger.log("Error Login", error);
return NextResponse.json(
{ success: false, message: "Terjadi masalah saat login" , reason: error as Error },
{ status: 500 }
);
} finally {
await prisma.$disconnect();
}
return NextResponse.json(
{ success: false, message: "Method Not Allowed" },
{ status: 405 }
);
}

View File

@@ -1,11 +1,19 @@
import { sessionCreate } from "@/app/auth/_lib/session_create";
import { sessionCreate } from "@/app/(auth)/_lib/session_create";
import prisma from "@/app/lib/prisma";
import backendLogger from "@/util/backendLogger";
import { NextResponse } from "next/server";
export async function POST(req: Request) {
if (req.method === "POST") {
if (req.method !== "POST") {
return NextResponse.json(
{ success: false, message: "Method Not Allowed" },
{ status: 405 }
);
}
try {
const { data } = await req.json();
console.log("data api register", data);
const cekUsername = await prisma.user.findUnique({
where: {
@@ -13,46 +21,51 @@ export async function POST(req: Request) {
},
});
try {
if (cekUsername)
return NextResponse.json(
{ success: false, message: "Username sudah digunakan" },
{ status: 400 }
);
const createUser = await prisma.user.create({
data: {
username: data.username,
nomor: data.nomor,
active: false,
},
if (cekUsername)
return NextResponse.json({
success: false,
message: "Username sudah digunakan",
});
const token = await sessionCreate({
sessionKey: process.env.NEXT_PUBLIC_BASE_SESSION_KEY!,
encodedKey: process.env.NEXT_PUBLIC_BASE_TOKEN_KEY!,
user: createUser as any,
});
const createUser = await prisma.user.create({
data: {
username: data.username,
nomor: data.nomor,
active: false,
},
});
if (!createUser)
return NextResponse.json(
{ success: true, message: "Berhasil Login", data: createUser },
{ status: 200 }
);
} catch (error) {
backendLogger.log("Error registrasi:", error);
return NextResponse.json(
{
success: false,
message: "Server Error",
reason: (error as Error).message,
},
{ success: false, message: "Gagal Registrasi" },
{ status: 500 }
);
}
}
return NextResponse.json(
{ success: false, message: "Method Not Allowed" },
{ status: 405 }
);
const token = await sessionCreate({
sessionKey: process.env.NEXT_PUBLIC_BASE_SESSION_KEY!,
encodedKey: process.env.NEXT_PUBLIC_BASE_TOKEN_KEY!,
user: createUser as any,
});
return NextResponse.json(
{
success: true,
message: "Registrasi Berhasil, Anda Sedang Login",
// data: createUser,
},
{ status: 201 }
);
} catch (error) {
backendLogger.error("Error registrasi:", error);
return NextResponse.json(
{
success: false,
message: "Maaf, Terjadi Keselahan",
reason: (error as Error).message,
},
{ status: 500 }
);
} finally {
await prisma.$disconnect();
}
}

View File

@@ -1,69 +1,72 @@
import { prisma } from "@/app/lib";
import { randomOTP } from "@/app_modules/auth/fun/rondom_otp";
import backendLogger from "@/util/backendLogger";
import { NextResponse } from "next/server";
export async function POST(req: Request) {
if (req.method === "POST") {
if (req.method !== "POST") {
return NextResponse.json(
{ success: false, message: "Method Not Allowed" },
{ status: 405 }
);
}
try {
const codeOtp = randomOTP();
const body = await req.json();
const { nomor } = body;
try {
const res = await fetch(
`https://wa.wibudev.com/code?nom=${nomor}&text=HIPMI - Kode ini bersifat RAHASIA dan JANGAN DI BAGIKAN KEPADA SIAPAPUN, termasuk anggota ataupun pengurus HIPMI lainnya.
const res = await fetch(
`https://wa.wibudev.com/code?nom=${nomor}&text=HIPMI - Kode ini bersifat RAHASIA dan JANGAN DI BAGIKAN KEPADA SIAPAPUN, termasuk anggota ataupun pengurus HIPMI lainnya.
\n
>> Kode OTP anda: ${codeOtp}.
`
);
const sendWa = await res.json();
if (sendWa.status !== "success")
return NextResponse.json(
{
success: false,
message: "Nomor Whatsapp Tidak Aktif",
},
{ status: 400 }
);
const createOtpId = await prisma.kodeOtp.create({
data: {
nomor: nomor,
otp: codeOtp,
},
});
if (!createOtpId)
return NextResponse.json(
{
success: false,
message: "Gagal Membuat Kode OTP",
},
{ status: 400 }
);
return NextResponse.json(
{
success: true,
message: "Kode Verifikasi Dikirim",
kodeId: createOtpId.id,
},
{ status: 200 }
);
} catch (error) {
console.log(error);
);
const sendWa = await res.json();
if (sendWa.status !== "success")
return NextResponse.json(
{
success: false,
message: "Server Whatsapp Error !!",
message: "Nomor Whatsapp Tidak Aktif",
},
{ status: 500 }
{ status: 400 }
);
}
const createOtpId = await prisma.kodeOtp.create({
data: {
nomor: nomor,
otp: codeOtp,
},
});
if (!createOtpId)
return NextResponse.json(
{
success: false,
message: "Gagal Membuat Kode OTP",
},
{ status: 400 }
);
return NextResponse.json(
{
success: true,
message: "Kode Verifikasi Dikirim",
kodeId: createOtpId.id,
},
{ status: 200 }
);
} catch (error) {
backendLogger.error(" Error Resend OTP", error);
return NextResponse.json(
{
success: false,
message: "Server Whatsapp Error !!",
},
{ status: 500 }
);
} finally {
await prisma.$disconnect();
}
return NextResponse.json(
{ success: false, message: "Method Not Allowed" },
{ status: 405 }
);
}

View File

@@ -1,61 +1,63 @@
import { sessionCreate } from "@/app/auth/_lib/session_create";
import { sessionCreate } from "@/app/(auth)/_lib/session_create";
import prisma from "@/app/lib/prisma";
import backendLogger from "@/util/backendLogger";
import { NextResponse } from "next/server";
export async function POST(req: Request) {
if (req.method === "POST") {
if (req.method !== "POST") {
return NextResponse.json(
{ success: false, message: "Method Not Allowed" },
{ status: 405 }
);
}
try {
const { nomor } = await req.json();
const dataUser = await prisma.user.findUnique({
where: {
nomor: nomor,
},
select: {
id: true,
nomor: true,
username: true,
active: true,
masterUserRoleId: true,
},
});
try {
const dataUser = await prisma.user.findUnique({
where: {
nomor: nomor,
},
select: {
id: true,
nomor: true,
username: true,
active: true,
masterUserRoleId: true,
},
});
if (dataUser == null)
return NextResponse.json(
{ success: false, message: "Nomor Belum Terdaftar" },
{ status: 404 }
);
const token = await sessionCreate({
sessionKey: process.env.NEXT_PUBLIC_BASE_SESSION_KEY!,
encodedKey: process.env.NEXT_PUBLIC_BASE_TOKEN_KEY!,
user: dataUser as any,
});
if (dataUser == null)
return NextResponse.json(
{
success: true,
message: "Berhasil Login",
roleId: dataUser.masterUserRoleId,
active: dataUser.active,
},
{ success: false, message: "Nomor Belum Terdaftar" },
{ status: 200 }
);
} catch (error) {
backendLogger.log("Error Validasi:", error);
return NextResponse.json(
{
success: false,
message: "Server Error",
reason: (error as Error).message,
},
{ status: 500 }
);
}
const token = await sessionCreate({
sessionKey: process.env.NEXT_PUBLIC_BASE_SESSION_KEY!,
encodedKey: process.env.NEXT_PUBLIC_BASE_TOKEN_KEY!,
user: dataUser as any,
});
return NextResponse.json(
{
success: true,
message: "Berhasil Login",
roleId: dataUser.masterUserRoleId,
active: dataUser.active,
},
{ status: 200 }
);
} catch (error) {
backendLogger.log("API Error or Server Error", error);
return NextResponse.json(
{
success: false,
message: "Maaf, Terjadi Keselahan",
reason: (error as Error).message,
},
{ status: 500 }
);
} finally {
await prisma.$disconnect();
}
return NextResponse.json(
{ success: false, message: "Method Not Allowed" },
{ status: 405 }
);
}

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

View File

@@ -1,4 +1,4 @@
import { decrypt } from "@/app/auth/_lib/decrypt";
import { decrypt } from "@/app/(auth)/_lib/decrypt";
import { prisma } from "@/app/lib";
import { cookies } from "next/headers";
import { NextRequest, NextResponse } from "next/server";
@@ -32,7 +32,6 @@ export async function GET(req: NextRequest) {
});
// Disconnect after successful query
await prisma.$disconnect();
return NextResponse.json({
success: true,
@@ -41,7 +40,6 @@ export async function GET(req: NextRequest) {
});
} catch (error) {
// Ensure connection is closed even if error occurs
await prisma.$disconnect();
console.error("Error in user validation:", error);
return NextResponse.json(
@@ -51,5 +49,7 @@ export async function GET(req: NextRequest) {
},
{ status: 500 }
);
} finally {
await prisma.$disconnect();
}
}

View File

@@ -1,4 +1,4 @@
import { decrypt } from "@/app/auth/_lib/decrypt";
import { decrypt } from "@/app/(auth)/_lib/decrypt";
import _ from "lodash";
import { cookies } from "next/headers";
import { NextResponse } from "next/server";

View File

@@ -1,5 +1,5 @@
import { decrypt } from "@/app/auth/_lib/decrypt";
import { decrypt } from "@/app/(auth)/_lib/decrypt";
import _ from "lodash";
import { cookies } from "next/headers";
import { NextResponse } from "next/server";

View File

@@ -1,10 +1,9 @@
import { NextResponse } from "next/server";
export async function GET(req: Request) {
const auth = req.headers.get("Authorization");
const token = auth?.split(" ")[1];
if (!token) return NextResponse.json({ success: false }, { status: 401 });
return NextResponse.json({ success: true });