From 5f88fb9a3982854e26442851ff2f984329cf42d1 Mon Sep 17 00:00:00 2001 From: Bagasbanuna02 Date: Wed, 17 Sep 2025 14:27:47 +0800 Subject: [PATCH 1/2] Api Mobile Job Fix: - api/mobile/job ### No Issue --- src/app/api/mobile/job/[id]/[status]/route.ts | 1 - src/app/api/mobile/job/[id]/route.ts | 48 ++++--- src/app/api/mobile/job/route.ts | 122 +++++++++++++----- 3 files changed, 119 insertions(+), 52 deletions(-) diff --git a/src/app/api/mobile/job/[id]/[status]/route.ts b/src/app/api/mobile/job/[id]/[status]/route.ts index 15d78713..e7a6fa51 100644 --- a/src/app/api/mobile/job/[id]/[status]/route.ts +++ b/src/app/api/mobile/job/[id]/[status]/route.ts @@ -111,7 +111,6 @@ async function PUT( }, }); - return NextResponse.json( { success: true, diff --git a/src/app/api/mobile/job/[id]/route.ts b/src/app/api/mobile/job/[id]/route.ts index 2b5956c5..2e112837 100644 --- a/src/app/api/mobile/job/[id]/route.ts +++ b/src/app/api/mobile/job/[id]/route.ts @@ -62,8 +62,6 @@ async function DELETE( }, }); - console.log("[DELETE DATA JOB]", deleteData); - return NextResponse.json( { success: true, @@ -87,25 +85,43 @@ 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, - }, - }); + const { searchParams } = new URL(request.url); + const category = searchParams.get("category"); + let fixData; + + if (category === "archive") { + const updateData = await prisma.job.update({ + where: { + id: id, + }, + data: { + isArsip: data, + }, + }); + + fixData = updateData; + } else if (category === "edit") { + 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, + }, + }); + + fixData = updateData; + } return NextResponse.json( { success: true, message: "Berhasil update data", - data: updateData, + data: fixData, }, { status: 200 } ); diff --git a/src/app/api/mobile/job/route.ts b/src/app/api/mobile/job/route.ts index dd7bb105..527302ed 100644 --- a/src/app/api/mobile/job/route.ts +++ b/src/app/api/mobile/job/route.ts @@ -40,53 +40,105 @@ async function POST(request: Request) { async function GET(request: Request) { const { searchParams } = new URL(request.url); const search = searchParams.get("search"); + const category = searchParams.get("category"); + const authorId = searchParams.get("authorId"); + let fixData; 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, + if (category === "archive") { + const data = await prisma.job.findMany({ + where: { + authorId: authorId, + isActive: true, + isArsip: true, + MasterStatus: { + name: "Publish", }, + // title: { + // contains: search || "", + // mode: "insensitive", + // }, }, - Author: { - select: { - id: true, - username: true, - Profile: { - select: { - id: true, - name: true, - imageId: true, + 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, + }, }, }, }, }, - }, - }); + }); + + fixData = data; + } else if (category === "beranda") { + 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, + }, + }, + }, + }, + }, + }); + + fixData = data; + } + return NextResponse.json( { success: true, message: "Success get data job-vacancy", - data: data, + data: fixData, }, { status: 200 } ); From 40443e70211a9819191aee808ce6a6c067340941 Mon Sep 17 00:00:00 2001 From: Bagasbanuna02 Date: Wed, 17 Sep 2025 17:32:38 +0800 Subject: [PATCH 2/2] Voting Mobile API Add: - api/mobile/voting/ ### No Issue --- .../api/mobile/voting/[id]/[status]/route.ts | 116 ++++++++++++++++++ src/app/api/mobile/voting/[id]/route.ts | 53 ++++++++ src/app/api/mobile/voting/route.ts | 54 ++++++++ 3 files changed, 223 insertions(+) create mode 100644 src/app/api/mobile/voting/[id]/[status]/route.ts create mode 100644 src/app/api/mobile/voting/[id]/route.ts create mode 100644 src/app/api/mobile/voting/route.ts diff --git a/src/app/api/mobile/voting/[id]/[status]/route.ts b/src/app/api/mobile/voting/[id]/[status]/route.ts new file mode 100644 index 00000000..23295d65 --- /dev/null +++ b/src/app/api/mobile/voting/[id]/[status]/route.ts @@ -0,0 +1,116 @@ +import _ from "lodash"; +import { NextResponse } from "next/server"; +import prisma from "@/lib/prisma"; + +export { GET, PUT }; + +async function GET( + request: Request, + { params }: { params: { id: string; status: string } } +) { + try { + const { id, status } = params; + console.log("[ID]", id); + const fixStatusName = _.startCase(status); + console.log("[STATUS]", fixStatusName); + + const data = await prisma.voting.findMany({ + where: { + authorId: id, + Voting_Status: { + name: fixStatusName, + }, + }, + }); + + return NextResponse.json({ + success: true, + message: "Success get voting", + data: data, + }); + } catch (error) { + console.log("[ERROR]", error); + return NextResponse.json({ + success: false, + message: "Error get voting", + reason: (error as Error).message, + }); + } +} + +async function PUT( + request: Request, + { params }: { params: { id: string; status: string } } +) { + try { + const { id, status } = params; + console.log("[ID]", id); + const fixStatusName = _.startCase(status); + console.log("[STATUS]", fixStatusName); + + const checkData = await prisma.voting.findFirst({ + where: { + id: id, + }, + select: { + id: true, + Voting_Status: { + select: { + name: true, + }, + }, + }, + }); + + console.log("[CHECKDATA]", checkData); + + if (!checkData) + return NextResponse.json({ + success: false, + message: "Voting tidak ditemukan", + }); + + if (checkData?.Voting_Status?.name === "Publish") { + return NextResponse.json({ + success: false, + message: "Voting telah terpublish", + }); + } + + const checkStatus = await prisma.masterStatus.findFirst({ + where: { + name: fixStatusName, + }, + }); + + if (!checkStatus) + return NextResponse.json({ + success: false, + message: "Status tidak ditemukan", + }); + + const updateData = await prisma.voting.update({ + where: { + id: id, + }, + data: { + voting_StatusId: checkStatus.id, + }, + }); + + console.log("[UPDATE]", updateData); + + return NextResponse.json({ + success: true, + message: "Success update voting", + data: updateData, + }); + } catch (error) { + console.log("[ERROR]", error); + return NextResponse.json({ + success: false, + message: "Error update voting", + reason: (error as Error).message, + }); + } +} diff --git a/src/app/api/mobile/voting/[id]/route.ts b/src/app/api/mobile/voting/[id]/route.ts new file mode 100644 index 00000000..d8d818ae --- /dev/null +++ b/src/app/api/mobile/voting/[id]/route.ts @@ -0,0 +1,53 @@ +import { NextResponse } from "next/server"; +import prisma from "@/lib/prisma"; + +export { GET }; + +async function GET(request: Request, { params }: { params: { id: string } }) { + try { + const { id } = params; + console.log("[ID]", id); + + const data = await prisma.voting.findUnique({ + where: { + id: id, + }, + include: { + Voting_DaftarNamaVote: { + orderBy: { + createdAt: "asc", + }, + where: { + isActive: true, + }, + }, + Author: { + select: { + id: true, + username: true, + Profile: { + select: { + id: true, + name: true, + imageId: true, + }, + }, + }, + }, + }, + }); + + return NextResponse.json({ + success: true, + message: "Success get voting", + data: data, + }); + } catch (error) { + console.log("[ERROR VOTING]", error); + return NextResponse.json({ + success: false, + message: "Error get voting", + reason: (error as Error).message, + }); + } +} diff --git a/src/app/api/mobile/voting/route.ts b/src/app/api/mobile/voting/route.ts new file mode 100644 index 00000000..62796b68 --- /dev/null +++ b/src/app/api/mobile/voting/route.ts @@ -0,0 +1,54 @@ +import { NextResponse } from "next/server"; +import prisma from "@/lib/prisma"; + +export { POST }; + +async function POST(request: Request) { + try { + const { data } = await request.json(); + + console.log("[DATA]", data); + + const create = await prisma.voting.create({ + data: { + title: data.title, + deskripsi: data.deskripsi, + awalVote: data.awalVote, + akhirVote: data.akhirVote, + authorId: data.authorId, + }, + }); + + if (!create) return { status: 400, message: "Gagal Membuat Vote" }; + + for (let v of data.listVote) { + const val = v.value; + + const namaVote = await prisma.voting_DaftarNamaVote.create({ + data: { + value: val, + votingId: create.id, + }, + }); + + if (!namaVote) return { status: 400, message: "Gagal Membuat List" }; + } + + return NextResponse.json( + { + success: true, + message: "Success create voting", + }, + { status: 201 } + ); + } catch (error) { + return NextResponse.json( + { + success: false, + message: "Error create voting", + reason: (error as Error).message, + }, + { status: 500 } + ); + } +}