Fix: voting status

Deskripsi:
- Perubahan router status & riwayat
This commit is contained in:
2024-10-29 14:10:46 +08:00
parent 8f76067380
commit e5e36a3889
35 changed files with 455 additions and 281 deletions

View File

@@ -4,21 +4,33 @@ import prisma from "@/app/lib/prisma";
import { revalidatePath } from "next/cache";
/**
* @param voteId
* @returns isActive berubah menjadi false
* @param votingId
*/
export async function Vote_funDeleteById(voteId: string) {
const del = await prisma.voting.update({
export async function Vote_funDeleteById(votingId: string) {
const del = await prisma.voting.delete({
where: {
id: voteId,
id: votingId,
},
data: {
isActive: false,
select: {
Voting_DaftarNamaVote: true,
},
});
if (!del) return { status: 400, message: "Gagal Hapus Data" };
revalidatePath("/dev/vote/main/status");
for (let i of del.Voting_DaftarNamaVote) {
const hapusDaftarPilihan = await prisma.voting_DaftarNamaVote.delete({
where: {
id: i.id,
},
});
if (!hapusDaftarPilihan)
return { status: 400, message: "Gagal Hapus Daftar Pilihan" };
}
revalidatePath("/dev/vote/main/status/3");
revalidatePath("/dev/vote/main/status/4");
return {
status: 200,
message: "Hapus Berhasil",

View File

@@ -53,7 +53,7 @@ export async function Vote_funEditById(
if (!namaPilihan) return { status: 400, message: "Gagal Membuat List" };
}
revalidatePath("/dev/vote/detail/draft");
revalidatePath(`/dev/vote/detail/draft`);
return {
status: 200,
message: "Berhasil Update",

View File

@@ -0,0 +1,9 @@
"use server";
import { prisma } from "@/app/lib";
export async function voting_getMasterStatus() {
const data = await prisma.voting_Status.findMany({});
return data;
}

View File

@@ -0,0 +1,59 @@
"use server";
import { prisma } from "@/app/lib";
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
export async function vote_funGetAllByStatusId({
page,
statusId,
}: {
page: number;
statusId: string;
}) {
const userLoginId = await funGetUserIdByToken();
const takeData = 10;
const skipData = page * takeData - takeData;
if (statusId == "1") {
const data = await prisma.voting.findMany({
take: takeData,
skip: skipData,
orderBy: {
updatedAt: "desc",
},
where: {
voting_StatusId: "1",
authorId: userLoginId,
isActive: true,
akhirVote: {
gte: new Date(),
},
},
include: {
Voting_DaftarNamaVote: {
orderBy: {
createdAt: "asc",
},
},
},
});
return data;
} else {
const data = await prisma.voting.findMany({
take: takeData,
skip: skipData,
orderBy: {
updatedAt: "desc",
},
where: {
voting_StatusId: statusId,
authorId: userLoginId,
isActive: true,
},
});
return data;
}
}

View File

@@ -1,3 +1,7 @@
import { voting_funUpdateIsArsipById } from "./edit/fun_update_is_arsip_by_id";
import { voting_getMasterStatus } from "./get/get_list_status_voting";
import { vote_funGetAllByStatusId } from "./get/status/get_all_by_status_id";
export { voting_funUpdateIsArsipById };
export { vote_funGetAllByStatusId };
export { voting_getMasterStatus };