From 1e0a1c83ba4ddd4978b07899f7c51ae3b914db5e Mon Sep 17 00:00:00 2001 From: Bagasbanuna02 Date: Tue, 16 Sep 2025 17:35:07 +0800 Subject: [PATCH] API Mobile Job Add: - api/mobile/job/ Fix: - job/_view/view_not_user_view_job.tsx: Tampilan jika user menuju ke web untuk view mon user ### No issue --- src/app/api/mobile/job/[id]/[status]/route.ts | 132 ++++++++++++++++++ src/app/api/mobile/job/[id]/route.ts | 122 ++++++++++++++++ src/app/api/mobile/job/route.ts | 103 ++++++++++++++ .../job/_view/view_not_user_view_job.tsx | 33 ++++- 4 files changed, 383 insertions(+), 7 deletions(-) create mode 100644 src/app/api/mobile/job/[id]/[status]/route.ts create mode 100644 src/app/api/mobile/job/[id]/route.ts create mode 100644 src/app/api/mobile/job/route.ts diff --git a/src/app/api/mobile/job/[id]/[status]/route.ts b/src/app/api/mobile/job/[id]/[status]/route.ts new file mode 100644 index 00000000..15d78713 --- /dev/null +++ b/src/app/api/mobile/job/[id]/[status]/route.ts @@ -0,0 +1,132 @@ +import prisma from "@/lib/prisma"; +import _ from "lodash"; +import { NextResponse } from "next/server"; + +export { GET, PUT }; + +async function GET( + request: Request, + { params }: { params: { id: string; status: string } } +) { + try { + const { id, status } = params; + const fixStatusName = _.startCase(status); + + const data = await prisma.job.findMany({ + orderBy: { + updatedAt: "desc", + }, + where: { + isActive: true, + authorId: id, + isArsip: false, + MasterStatus: { + name: fixStatusName, + }, + }, + select: { + id: true, + title: true, + }, + }); + + return NextResponse.json( + { + success: true, + message: "Success get job", + data: data, + }, + { status: 200 } + ); + } catch (error) { + return NextResponse.json( + { + success: false, + message: "Error get job", + reason: (error as Error).message, + }, + { status: 500 } + ); + } +} + +async function PUT( + request: Request, + { params }: { params: { id: string; status: string } } +) { + try { + const { id, status } = params; + const fixStatusName = _.startCase(status); + + const checkData = await prisma.job.findUnique({ + where: { + id: id, + }, + select: { + id: true, + MasterStatus: { + select: { + name: true, + }, + }, + }, + }); + + if (!checkData) { + return NextResponse.json({ + success: false, + message: "Data tidak ditemukan", + status: 404, + }); + } + + if (checkData?.MasterStatus?.name === "Publish") { + return NextResponse.json({ + success: false, + message: "Job telah terpublish", + status: 400, + }); + } + + const checkStatus = await prisma.masterStatus.findFirst({ + where: { + name: fixStatusName, + }, + }); + + if (!checkStatus) { + return NextResponse.json({ + success: false, + message: "Status tidak ditemukan", + status: 404, + }); + } + + const updateData = await prisma.job.update({ + where: { + id: id, + }, + data: { + masterStatusId: checkStatus.id, + }, + }); + + + return NextResponse.json( + { + success: true, + message: "Update berhasil", + }, + { status: 200 } + ); + } catch (error) { + return NextResponse.json( + { + success: false, + message: "Error update job", + reason: (error as Error).message, + }, + { status: 500 } + ); + } +} diff --git a/src/app/api/mobile/job/[id]/route.ts b/src/app/api/mobile/job/[id]/route.ts new file mode 100644 index 00000000..2b5956c5 --- /dev/null +++ b/src/app/api/mobile/job/[id]/route.ts @@ -0,0 +1,122 @@ +import { NextResponse } from "next/server"; +import prisma from "@/lib/prisma"; + +export { GET, DELETE, PUT }; + +async function GET(request: Request, { params }: { params: { id: string } }) { + try { + const { id } = params; + const data = await prisma.job.findUnique({ + where: { + id: id, + }, + include: { + Author: { + select: { + username: true, + nomor: true, + Profile: { + select: { + name: true, + alamat: true, + }, + }, + }, + }, + MasterStatus: { + select: { + name: true, + }, + }, + }, + }); + return NextResponse.json( + { + success: true, + message: "Success get data job-vacancy", + data: data, + }, + { status: 200 } + ); + } catch (error) { + return NextResponse.json( + { + success: false, + message: "Error get data job-vacancy", + reason: (error as Error).message, + }, + { status: 500 } + ); + } +} + +async function DELETE( + request: Request, + { params }: { params: { id: string } } +) { + try { + const { id } = params; + const deleteData = await prisma.job.delete({ + where: { + id: id, + }, + }); + + console.log("[DELETE DATA JOB]", deleteData); + + return NextResponse.json( + { + success: true, + message: "Data berhasil dihapus", + }, + { status: 200 } + ); + } catch (error) { + return NextResponse.json( + { + success: false, + message: "Gagal menghapus data", + reason: (error as Error).message, + }, + { status: 500 } + ); + } +} + +async function PUT(request: Request, { params }: { params: { id: string } }) { + try { + const { id } = params; + const { data } = await request.json(); + + const updateData = await prisma.job.update({ + where: { + id: id, + }, + data: { + title: data.title, + content: data.content, + deskripsi: data.deskripsi, + // authorId: data.authorId, + imageId: data.imageId || null, + }, + }); + + return NextResponse.json( + { + success: true, + message: "Berhasil update data", + data: updateData, + }, + { status: 200 } + ); + } catch (error) { + return NextResponse.json( + { + success: false, + message: "Gagal update data", + reason: (error as Error).message, + }, + { status: 500 } + ); + } +} diff --git a/src/app/api/mobile/job/route.ts b/src/app/api/mobile/job/route.ts new file mode 100644 index 00000000..dd7bb105 --- /dev/null +++ b/src/app/api/mobile/job/route.ts @@ -0,0 +1,103 @@ +import prisma from "@/lib/prisma"; +import { NextResponse } from "next/server"; + +export { POST, GET }; + +async function POST(request: Request) { + try { + const { data } = await request.json(); + + const create = await prisma.job.create({ + data: { + title: data.title, + content: data.content, + deskripsi: data.deskripsi, + authorId: data.authorId, + imageId: data.imageId || null, + }, + }); + + return NextResponse.json( + { + success: true, + message: "Berhasil disimpan", + data: create, + }, + { status: 201 } + ); + } catch (error) { + return NextResponse.json( + { + success: false, + message: "Error create job", + reason: (error as Error).message, + }, + { status: 500 } + ); + } +} + +async function GET(request: Request) { + const { searchParams } = new URL(request.url); + const search = searchParams.get("search"); + + try { + const data = await prisma.job.findMany({ + where: { + isActive: true, + isArsip: false, + MasterStatus: { + name: "Publish", + }, + title: { + contains: search || "", + mode: "insensitive", + }, + }, + orderBy: { + createdAt: "desc", + }, + select: { + id: true, + title: true, + deskripsi: true, + authorId: true, + MasterStatus: { + select: { + name: true, + }, + }, + Author: { + select: { + id: true, + username: true, + Profile: { + select: { + id: true, + name: true, + imageId: true, + }, + }, + }, + }, + }, + }); + return NextResponse.json( + { + success: true, + message: "Success get data job-vacancy", + data: data, + }, + { status: 200 } + ); + } catch (error) { + return NextResponse.json( + { + success: false, + message: "Error get data job-vacancy", + reason: (error as Error).message, + }, + { status: 500 } + ); + } +} diff --git a/src/app_modules/job/_view/view_not_user_view_job.tsx b/src/app_modules/job/_view/view_not_user_view_job.tsx index 4cd6139d..78371b94 100644 --- a/src/app_modules/job/_view/view_not_user_view_job.tsx +++ b/src/app_modules/job/_view/view_not_user_view_job.tsx @@ -40,13 +40,32 @@ export function Job_ViewNotUserJobVacany() { {data.title} - - -
- - -
- + + + + + Syarat & Ketentuan + + +
"), + }} + /> + + + + + Deskripsi + + +
"), + }} + /> + +