From 7ab42a61b5212a43f947f20543f43737045587e6 Mon Sep 17 00:00:00 2001 From: Bagasbanuna02 Date: Thu, 18 Sep 2025 17:38:31 +0800 Subject: [PATCH 1/2] chore(release): 1.4.38 --- CHANGELOG.md | 2 ++ package.json | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e6fc685..335d9bc0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines. +## [1.4.38](https://wibugit.wibudev.com/bip/hipmi/compare/v1.4.37...v1.4.38) (2025-09-18) + ## [1.4.37](https://wibugit.wibudev.com/bip/hipmi/compare/v1.4.36...v1.4.37) (2025-09-16) ## [1.4.36](https://wibugit.wibudev.com/bip/hipmi/compare/v1.4.35...v1.4.36) (2025-09-15) diff --git a/package.json b/package.json index 5b7c47cd..5e704dd8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hipmi", - "version": "1.4.37", + "version": "1.4.38", "private": true, "prisma": { "seed": "bun prisma/seed.ts" From b4fb23b87a92c8d72b3631ad2058090a7ebdf9bd Mon Sep 17 00:00:00 2001 From: Bagasbanuna02 Date: Thu, 18 Sep 2025 17:38:35 +0800 Subject: [PATCH 2/2] Mobile API Voting Add: - api/mobile/voting/[id]/contribution : mengecek kontibutor - api/mobile/voting: method : GET , POST , PUT, DEL ### No Issue --- .../mobile/voting/[id]/contribution/route.ts | 66 ++++++ src/app/api/mobile/voting/[id]/route.ts | 195 +++++++++++++++++- src/app/api/mobile/voting/route.ts | 71 ++++++- 3 files changed, 330 insertions(+), 2 deletions(-) create mode 100644 src/app/api/mobile/voting/[id]/contribution/route.ts diff --git a/src/app/api/mobile/voting/[id]/contribution/route.ts b/src/app/api/mobile/voting/[id]/contribution/route.ts new file mode 100644 index 00000000..c48ba192 --- /dev/null +++ b/src/app/api/mobile/voting/[id]/contribution/route.ts @@ -0,0 +1,66 @@ +import { NextResponse } from "next/server"; +import prisma from "@/lib/prisma"; + +export { GET }; + +async function GET(request: Request, { params }: { params: { id: string } }) { + const { id } = params; + const { searchParams } = new URL(request.url); + const authorId = searchParams.get("authorId"); + // const category = searchParams.get("category"); + + console.log("[ID Voting]", id); + console.log("[AUTHOR ID Voting]", authorId); + + console.log("[CEK DATA]"); + + let fixData; + + try { + const cek = await prisma.voting_Kontributor.count({ + where: { + authorId: authorId, + votingId: id, + }, + }); + + const cekPilihan = await prisma.voting_Kontributor.findFirst({ + where: { + authorId: authorId, + votingId: id, + }, + select: { + Voting_DaftarNamaVote: { + select: { + value: true, + }, + }, + }, + }); + + if (cek > 0) { + fixData = true; + } else { + fixData = false; + } + + fixData = { + isContribution: cek > 0, + nameChoice: cekPilihan?.Voting_DaftarNamaVote?.value, + }; + + console.log("[FIX DATA]", fixData); + + return NextResponse.json({ + success: true, + message: "Berhasil mendapatkan data", + data: fixData, + }); + } catch (error) { + return NextResponse.json({ + success: false, + message: "Gagal mendapatkan data", + 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 index d8d818ae..24db0a8f 100644 --- a/src/app/api/mobile/voting/[id]/route.ts +++ b/src/app/api/mobile/voting/[id]/route.ts @@ -1,7 +1,7 @@ import { NextResponse } from "next/server"; import prisma from "@/lib/prisma"; -export { GET }; +export { GET, DELETE, PUT, POST }; async function GET(request: Request, { params }: { params: { id: string } }) { try { @@ -51,3 +51,196 @@ async function GET(request: Request, { params }: { params: { id: string } }) { }); } } + +async function DELETE( + request: Request, + { params }: { params: { id: string } } +) { + try { + const { id } = params; + + const deleteListVoteName = await prisma.voting_DaftarNamaVote.deleteMany({ + where: { + votingId: id, + }, + }); + + console.log("[DELETE LIST VOTE NAME]", deleteListVoteName); + + const deleteData = await prisma.voting.delete({ + where: { + id: id, + }, + }); + + console.log("[DELETE DATA]", deleteData); + + return NextResponse.json({ + success: true, + message: "Berhasil menghapus data", + }); + } catch (error) { + return NextResponse.json({ + success: false, + message: "Gagal menghapus data", + reason: (error as Error).message, + }); + } +} + +async function PUT(request: Request, { params }: { params: { id: string } }) { + try { + const { id } = params; + const { data } = await request.json(); + + console.log("[ID]", id); + console.log("[DATA]", data); + + const updateVoting = await prisma.voting.update({ + where: { + id: id, + }, + data: { + title: data.title, + deskripsi: data.deskripsi.trim(), + awalVote: data.awalVote, + akhirVote: data.akhirVote, + }, + select: { + Voting_DaftarNamaVote: { + where: { + isActive: true, + }, + }, + }, + }); + + console.log("[UPDATE VOTING]", updateVoting); + + if (!updateVoting) + return NextResponse.json({ status: 400, message: "Gagal Update" }); + + const deleatePrevPilihan = await prisma.voting_DaftarNamaVote.deleteMany({ + where: { + votingId: id, + }, + }); + + console.log("[DELETE PREV PILIHAN]", deleatePrevPilihan); + + if (!deleatePrevPilihan) + return NextResponse.json({ + status: 400, + message: "Gagal Update Pilihan", + }); + + for (let v of data.listVote) { + console.log("[VOTING LIST >>]", v); + const namaPilihan = await prisma.voting_DaftarNamaVote.create({ + data: { + value: v, + votingId: id, + }, + }); + + console.log("[NAMA PILIHAN]", namaPilihan); + + if (!namaPilihan) + return NextResponse.json({ + status: 400, + message: "Gagal Membuat List", + }); + } + + return NextResponse.json({ + success: true, + message: "Berhasil menghapus data", + }); + } catch (error) { + return NextResponse.json({ + success: false, + message: "Gagal menghapus data", + reason: (error as Error).message, + }); + } +} + +async function POST(request: Request, { params }: { params: { id: string } }) { + const { id } = params; + const { data } = await request.json(); + + console.log("[ID]", id); + console.log("[CHOOSE ID]", data); + + try { + const findData = await prisma.voting_DaftarNamaVote.findFirst({ + where: { + id: data.chooseId, + }, + select: { + jumlah: true, + value: true, + }, + }); + + if (!findData) + return NextResponse.json({ + success: false, + message: "Data tidak ditemukan", + }); + + const updateData = await prisma.voting_DaftarNamaVote.update({ + where: { + id: data.chooseId, + }, + data: { + jumlah: findData.jumlah + 1, + }, + }); + + console.log("[UPDATE DATA]", updateData); + + if (!updateData) + return NextResponse.json({ + success: false, + message: "Gagal Update Data", + }); + + const createKontributor = await prisma.voting_Kontributor.create({ + data: { + votingId: id, + authorId: data.userId, + voting_DaftarNamaVoteId: data.chooseId, + }, + select: { + Voting: { + select: { + id: true, + title: true, + authorId: true, + }, + }, + }, + }); + + console.log("[CREATE KONTRIBUTOR]", createKontributor); + + if (!createKontributor) + return NextResponse.json({ + success: false, + message: "Gagal Menjadi Kontributor", + }); + + return NextResponse.json({ + success: true, + message: "Berhasil Voting", + }); + } catch (error) { + console.log("[ERROR]", error); + return NextResponse.json({ + success: false, + message: "Gagal menghapus data", + reason: (error as Error).message, + }); + } +} diff --git a/src/app/api/mobile/voting/route.ts b/src/app/api/mobile/voting/route.ts index 62796b68..a2f025e9 100644 --- a/src/app/api/mobile/voting/route.ts +++ b/src/app/api/mobile/voting/route.ts @@ -1,7 +1,7 @@ import { NextResponse } from "next/server"; import prisma from "@/lib/prisma"; -export { POST }; +export { POST, GET }; async function POST(request: Request) { try { @@ -52,3 +52,72 @@ async function POST(request: Request) { ); } } + +async function GET(request: Request) { + const { searchParams } = new URL(request.url); + const search = searchParams.get("search"); + + try { + const data = await prisma.voting.findMany({ + orderBy: { + updatedAt: "desc", + }, + where: { + voting_StatusId: "1", + isArsip: false, + isActive: true, + akhirVote: { + gte: new Date(), + }, + title: { + contains: search || "", + mode: "insensitive", + }, + }, + include: { + Voting_DaftarNamaVote: { + orderBy: { + createdAt: "asc", + }, + }, + Author: { + select: { + id: true, + username: true, + Profile: { + select: { + id: true, + name: true, + imageId: true, + }, + }, + }, + }, + }, + }); + + console.log("[DATA]", data); + + return NextResponse.json( + { + success: true, + message: "Berhasil mendapatkan data", + data: data, + }, + { + status: 200, + } + ); + } catch (error) { + return NextResponse.json( + { + success: false, + message: "Gagal mendapatkan data", + reason: (error as Error).message, + }, + { + status: 500, + } + ); + } +}