Update Versi 1.5.27 #32

Merged
bagasbanuna merged 1009 commits from staging into main 2025-12-17 12:22:28 +08:00
2158 changed files with 93789 additions and 24373 deletions
Showing only changes of commit a3b81bda4d - Show all commits

View File

@@ -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.39](https://wibugit.wibudev.com/bip/hipmi/compare/v1.4.38...v1.4.39) (2025-09-19)
## [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)

View File

@@ -1,6 +1,6 @@
{
"name": "hipmi",
"version": "1.4.38",
"version": "1.4.39",
"private": true,
"prisma": {
"seed": "bun prisma/seed.ts"

View File

@@ -7,50 +7,79 @@ 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");
const category = searchParams.get("category");
console.log("[ID Voting]", id);
console.log("[AUTHOR ID Voting]", authorId);
console.log("[CEK DATA]");
console.log("[ID]", id);
console.log("[AUTHOR ID]", authorId);
console.log("[CATEGORY]", category);
let fixData;
try {
const cek = await prisma.voting_Kontributor.count({
where: {
authorId: authorId,
votingId: id,
},
});
if (category === "checked") {
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,
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;
if (cek > 0) {
fixData = true;
} else {
fixData = false;
}
fixData = {
isContribution: cek > 0,
nameChoice: cekPilihan?.Voting_DaftarNamaVote?.value,
};
} else if (category === "list") {
const listKontributor = await prisma.voting_Kontributor.findMany({
where: {
votingId: id,
},
select: {
Voting_DaftarNamaVote: {
select: {
value: true,
},
},
Author: {
select: {
id: true,
username: true,
Profile: {
select: {
id: true,
name: true,
imageId: true,
},
},
},
},
},
});
console.log("[LIST KONTRIBUTOR]", listKontributor);
fixData = listKontributor;
}
fixData = {
isContribution: cek > 0,
nameChoice: cekPilihan?.Voting_DaftarNamaVote?.value,
};
console.log("[FIX DATA]", fixData);
return NextResponse.json({
success: true,
message: "Berhasil mendapatkan data",

View File

@@ -1,13 +1,12 @@
import { NextResponse } from "next/server";
import prisma from "@/lib/prisma";
import _ from "lodash";
export { GET, DELETE, PUT, POST };
async function GET(request: Request, { params }: { params: { id: string } }) {
const { id } = params;
try {
const { id } = params;
console.log("[ID]", id);
const data = await prisma.voting.findUnique({
where: {
id: id,
@@ -37,6 +36,26 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
},
});
const listNamaVote = data?.Voting_DaftarNamaVote || [];
for (let v of listNamaVote) {
const kontributor = await prisma.voting_Kontributor.findMany({
where: {
voting_DaftarNamaVoteId: v.id,
},
});
const updateData = await prisma.voting_DaftarNamaVote.update({
where: {
id: v.id,
},
data: {
jumlah: kontributor.length,
},
});
}
return NextResponse.json({
success: true,
message: "Success get voting",
@@ -65,15 +84,12 @@ async function DELETE(
},
});
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,
@@ -89,89 +105,95 @@ async function DELETE(
}
async function PUT(request: Request, { params }: { params: { id: string } }) {
const { id } = params;
const { data } = await request.json();
const { searchParams } = new URL(request.url);
const category = searchParams.get("category");
let fixData;
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,
if (category === "edit") {
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,
if (!updateVoting)
return NextResponse.json({ status: 400, message: "Gagal Update" });
const deleatePrevPilihan = await prisma.voting_DaftarNamaVote.deleteMany({
where: {
votingId: id,
},
});
console.log("[NAMA PILIHAN]", namaPilihan);
if (!namaPilihan)
if (!deleatePrevPilihan)
return NextResponse.json({
status: 400,
message: "Gagal Membuat List",
message: "Gagal Update Pilihan",
});
for (let v of data.listVote) {
const namaPilihan = await prisma.voting_DaftarNamaVote.create({
data: {
value: v,
votingId: id,
},
});
if (!namaPilihan)
return NextResponse.json({
status: 400,
message: "Gagal Membuat List",
});
}
} else if (category === "archive") {
const updateVoting = await prisma.voting.update({
where: {
id: id,
},
data: {
isArsip: data,
},
});
if (!updateVoting)
return NextResponse.json({ status: 400, message: "Gagal Update" });
}
return NextResponse.json({
success: true,
message: "Berhasil menghapus data",
message: "Berhasil mengupdate data",
});
} catch (error) {
return NextResponse.json({
success: false,
message: "Gagal menghapus data",
message: "Gagal mengupdate data",
reason: (error as Error).message,
});
}
}
// Voting masuk melalui API ini
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: {
@@ -198,7 +220,6 @@ async function POST(request: Request, { params }: { params: { id: string } }) {
},
});
console.log("[UPDATE DATA]", updateData);
if (!updateData)
return NextResponse.json({
@@ -223,8 +244,6 @@ async function POST(request: Request, { params }: { params: { id: string } }) {
},
});
console.log("[CREATE KONTRIBUTOR]", createKontributor);
if (!createKontributor)
return NextResponse.json({
success: false,

View File

@@ -1,5 +1,6 @@
import { NextResponse } from "next/server";
import prisma from "@/lib/prisma";
import _ from "lodash";
export { POST, GET };
@@ -7,8 +8,6 @@ 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,
@@ -56,53 +55,181 @@ 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.voting.findMany({
orderBy: {
updatedAt: "desc",
},
where: {
voting_StatusId: "1",
isArsip: false,
isActive: true,
akhirVote: {
gte: new Date(),
if (category === "beranda") {
fixData = await prisma.voting.findMany({
orderBy: {
updatedAt: "desc",
},
title: {
contains: search || "",
mode: "insensitive",
},
},
include: {
Voting_DaftarNamaVote: {
orderBy: {
createdAt: "asc",
where: {
voting_StatusId: "1",
isArsip: false,
isActive: true,
akhirVote: {
gte: new Date(),
},
title: {
contains: search || "",
mode: "insensitive",
},
},
Author: {
select: {
id: true,
username: true,
Profile: {
select: {
id: true,
name: true,
imageId: true,
include: {
Voting_DaftarNamaVote: {
orderBy: {
createdAt: "asc",
},
},
Author: {
select: {
id: true,
username: true,
Profile: {
select: {
id: true,
name: true,
imageId: true,
},
},
},
},
},
},
});
});
} else if (category === "contribution") {
const data = await prisma.voting_Kontributor.findMany({
orderBy: {
createdAt: "desc",
},
where: {
authorId: authorId,
},
include: {
Voting: {
select: {
id: true,
title: true,
awalVote: true,
akhirVote: true,
Author: {
select: {
id: true,
username: true,
Profile: {
select: {
id: true,
name: true,
imageId: true,
},
},
},
},
},
},
},
});
console.log("[DATA]", data);
const result = data.map((item) => ({
contributionId: item.id,
isActive: item.isActive,
createdAt: item.createdAt,
updatedAt: item.updatedAt,
votingId: item.votingId,
authorId: item.authorId,
voting_DaftarNamaVoteId: item.voting_DaftarNamaVoteId,
id: item.Voting?.id,
title: item.Voting?.title,
awalVote: item.Voting?.awalVote,
akhirVote: item.Voting?.akhirVote,
Author: item.Voting?.Author,
}));
fixData = result;
} else if (category === "all-history") {
fixData = await prisma.voting.findMany({
orderBy: {
updatedAt: "desc",
},
where: {
voting_StatusId: "1",
isActive: true,
akhirVote: {
lte: 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,
},
},
},
},
},
});
} else if (category === "my-history") {
fixData = await prisma.voting.findMany({
orderBy: {
updatedAt: "desc",
},
where: {
authorId: authorId as any,
voting_StatusId: "1",
isActive: true,
akhirVote: {
lte: 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,
},
},
},
},
},
});
}
return NextResponse.json(
{
success: true,
message: "Berhasil mendapatkan data",
data: data,
data: fixData,
},
{
status: 200,