Update Versi 1.5.27 #32
155
src/app/api/admin/vote/status/[name]/route.ts
Normal file
155
src/app/api/admin/vote/status/[name]/route.ts
Normal file
@@ -0,0 +1,155 @@
|
||||
import { prisma } from "@/lib";
|
||||
import backendLogger from "@/util/backendLogger";
|
||||
import _ from "lodash";
|
||||
import moment from "moment";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export async function GET(request: Request,
|
||||
{ params }: { params: { name: string } }
|
||||
) {
|
||||
|
||||
const { name } = params;
|
||||
const { searchParams } = new URL(request.url);
|
||||
const search = searchParams.get("search");
|
||||
const page = searchParams.get("page");
|
||||
const takeData = 10;
|
||||
const skipData = Number(page) * takeData - takeData;
|
||||
|
||||
try {
|
||||
let fixData;
|
||||
const fixStatus = _.startCase(name);
|
||||
|
||||
if (!page) {
|
||||
fixData = await prisma.voting.findMany({
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
where: {
|
||||
Voting_Status: {
|
||||
name: fixStatus,
|
||||
},
|
||||
isActive: true,
|
||||
title: {
|
||||
contains: search ? search : "",
|
||||
mode: "insensitive",
|
||||
},
|
||||
isArsip: false,
|
||||
},
|
||||
include: {
|
||||
Author: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
Profile: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Voting_Kontributor: true,
|
||||
Voting_DaftarNamaVote: true,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
fixData = await prisma.voting.findMany({
|
||||
take: takeData,
|
||||
skip: skipData,
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
where: {
|
||||
Voting_Status: {
|
||||
name: fixStatus,
|
||||
},
|
||||
isActive: true,
|
||||
title: {
|
||||
contains: search ? search : "",
|
||||
mode: "insensitive",
|
||||
},
|
||||
isArsip: false,
|
||||
},
|
||||
include: {
|
||||
Author: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
Profile: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Voting_Kontributor: true,
|
||||
Voting_DaftarNamaVote: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (fixStatus === "Publish") {
|
||||
const data = await prisma.voting.findMany({
|
||||
where: {
|
||||
Voting_Status: {
|
||||
name: fixStatus,
|
||||
},
|
||||
isActive: true,
|
||||
title: {
|
||||
contains: search ? search : "",
|
||||
mode: "insensitive",
|
||||
},
|
||||
isArsip: false,
|
||||
},
|
||||
});
|
||||
|
||||
for (let i of data) {
|
||||
if (moment(i.akhirVote).diff(moment(), "minutes") < 0) {
|
||||
await prisma.event.update({
|
||||
where: {
|
||||
id: i.id,
|
||||
},
|
||||
data: {
|
||||
isArsip: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
const nCount = await prisma.voting.count({
|
||||
where: {
|
||||
Voting_Status: {
|
||||
name: fixStatus,
|
||||
},
|
||||
isActive: true,
|
||||
title: {
|
||||
contains: search ? search : "",
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
fixData = {
|
||||
data: data,
|
||||
count: _.ceil(nCount / takeData)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: "Success get data voting dashboard",
|
||||
data: fixData
|
||||
},
|
||||
{ status: 200 }
|
||||
)
|
||||
} catch (error) {
|
||||
backendLogger.error("Error get data voting dashboard >>", error);
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: "Error get data voting dashboard",
|
||||
reason: (error as Error).message
|
||||
},
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
import { prisma } from "@/lib";
|
||||
import _ from "lodash";
|
||||
import moment from "moment";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export async function GET(request: Request,
|
||||
{ params }: { params: { name: string } }
|
||||
) {
|
||||
const method = request.method;
|
||||
if (method !== "GET") {
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: "Method not allowed"
|
||||
},
|
||||
{ status: 405 }
|
||||
)
|
||||
}
|
||||
|
||||
const { name } = params;
|
||||
const { searchParams } = new URL(request.url);
|
||||
const search = searchParams.get("search");
|
||||
const page = searchParams.get("page");
|
||||
const takeData = 10;
|
||||
const skipData = Number(page) * takeData - takeData;
|
||||
|
||||
try {
|
||||
let fixData;
|
||||
const fixStatus = _.startCase(name);
|
||||
|
||||
if (!page && !search) {
|
||||
fixData = await prisma.voting.findMany({
|
||||
orderBy: {
|
||||
updatedAt: "desc"
|
||||
},
|
||||
where: {
|
||||
isActive: true,
|
||||
isArsip: false,
|
||||
Voting_Status: {
|
||||
name: fixStatus
|
||||
}
|
||||
},
|
||||
include: {
|
||||
Author: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
Profile: {
|
||||
select: {
|
||||
name: true
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
Voting_Status: true,
|
||||
Voting_Kontributor: true,
|
||||
Voting_DaftarNamaVote: true,
|
||||
}
|
||||
})
|
||||
} else if (!page && search) {
|
||||
fixData = await prisma.voting.findMany({
|
||||
orderBy: {
|
||||
updatedAt: "desc"
|
||||
},
|
||||
where: {
|
||||
isActive: true,
|
||||
isArsip: false,
|
||||
Voting_Status: {
|
||||
name: fixStatus
|
||||
},
|
||||
title: {
|
||||
contains: search,
|
||||
mode: "insensitive"
|
||||
}
|
||||
},
|
||||
include: {
|
||||
Author: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
Profile: {
|
||||
select: {
|
||||
name: true
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
Voting_Status: true,
|
||||
Voting_Kontributor: true,
|
||||
Voting_DaftarNamaVote: true,
|
||||
}
|
||||
})
|
||||
} else if (page && !search) {
|
||||
if (fixStatus === "Publish") {
|
||||
const getAllData = await prisma.voting.findMany({
|
||||
where: {
|
||||
isActive: true,
|
||||
Voting_Status: {
|
||||
name: fixStatus
|
||||
},
|
||||
isArsip: false
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -120,25 +120,25 @@ function TampilanDetailDonasi({
|
||||
{ maxWidth: "36rem", cols: 1, spacing: "sm" },
|
||||
]}
|
||||
>
|
||||
<Paper p={"xs"}>
|
||||
<Paper p={"xs"} bg={AdminColor.softBlue}>
|
||||
<Stack>
|
||||
<Title align="center" order={4}>
|
||||
<Title c={AdminColor.white} align="center" order={4}>
|
||||
Gambar Donasi
|
||||
</Title>
|
||||
<Admin_ComponentLoadImageLandscape fileId={donasi.imageId} />
|
||||
</Stack>
|
||||
</Paper>
|
||||
|
||||
<Paper p={"sm"}>
|
||||
<Paper p={"sm"} bg={AdminColor.softBlue}>
|
||||
<Stack spacing={5}>
|
||||
<Title order={4}>Detail Donasi</Title>
|
||||
<Title c={AdminColor.white} order={4}>Detail Donasi</Title>
|
||||
<Grid>
|
||||
<Grid.Col span={4}>
|
||||
<Text fz={"xs"}>Judul</Text>
|
||||
<Text c={AdminColor.white} fz={"xs"}>Judul</Text>
|
||||
</Grid.Col>
|
||||
<Grid.Col span={"content"}>:</Grid.Col>
|
||||
<Grid.Col c={AdminColor.white} span={"content"}>:</Grid.Col>
|
||||
<Grid.Col span={"auto"}>
|
||||
<Title order={5} c="blue">
|
||||
<Title order={5} c={AdminColor.white}>
|
||||
{donasi?.title}
|
||||
</Title>
|
||||
</Grid.Col>
|
||||
@@ -146,11 +146,11 @@ function TampilanDetailDonasi({
|
||||
|
||||
<Grid>
|
||||
<Grid.Col span={4}>
|
||||
<Text fz={"xs"}>Penggalang Dana</Text>
|
||||
<Text c={AdminColor.white} fz={"xs"}>Penggalang Dana</Text>
|
||||
</Grid.Col>
|
||||
<Grid.Col span={"content"}>:</Grid.Col>
|
||||
<Grid.Col c={AdminColor.white} span={"content"}>:</Grid.Col>
|
||||
<Grid.Col span={"auto"}>
|
||||
<Title order={5} c="blue">
|
||||
<Title order={5} c={AdminColor.white}>
|
||||
{donasi?.Author.username}
|
||||
</Title>
|
||||
</Grid.Col>
|
||||
@@ -158,11 +158,11 @@ function TampilanDetailDonasi({
|
||||
|
||||
<Grid>
|
||||
<Grid.Col span={4}>
|
||||
<Text fz={"xs"}>Durasi</Text>
|
||||
<Text c={AdminColor.white} fz={"xs"}>Durasi</Text>
|
||||
</Grid.Col>
|
||||
<Grid.Col span={"content"}>:</Grid.Col>
|
||||
<Grid.Col c={AdminColor.white} span={"content"}>:</Grid.Col>
|
||||
<Grid.Col span={"auto"}>
|
||||
<Title order={5} c="blue">
|
||||
<Title c={AdminColor.white} order={5}>
|
||||
{donasi?.DonasiMaster_Durasi.name} hari
|
||||
</Title>
|
||||
</Grid.Col>
|
||||
@@ -170,24 +170,24 @@ function TampilanDetailDonasi({
|
||||
|
||||
<Grid>
|
||||
<Grid.Col span={4}>
|
||||
<Text fz={"xs"}>Dana dibutuhkan</Text>
|
||||
<Text c={AdminColor.white} fz={"xs"}>Dana dibutuhkan</Text>
|
||||
</Grid.Col>
|
||||
<Grid.Col span={"content"}>:</Grid.Col>
|
||||
<Grid.Col c={AdminColor.white} span={"content"}>:</Grid.Col>
|
||||
<Grid.Col span={"auto"}>
|
||||
<ComponentGlobal_TampilanRupiah
|
||||
nominal={+donasi?.target}
|
||||
color="darkblue"
|
||||
color={AdminColor.yellow}
|
||||
/>
|
||||
</Grid.Col>
|
||||
</Grid>
|
||||
|
||||
<Grid>
|
||||
<Grid.Col span={4}>
|
||||
<Text fz={"xs"}>Kategori</Text>
|
||||
<Text c={AdminColor.white} fz={"xs"}>Kategori</Text>
|
||||
</Grid.Col>
|
||||
<Grid.Col span={"content"}>:</Grid.Col>
|
||||
<Grid.Col c={AdminColor.white} span={"content"}>:</Grid.Col>
|
||||
<Grid.Col span={"auto"}>
|
||||
<Title order={5} c="blue">
|
||||
<Title c={AdminColor.white} order={5}>
|
||||
{donasi?.DonasiMaster_Ketegori?.name}
|
||||
</Title>
|
||||
</Grid.Col>
|
||||
@@ -195,11 +195,11 @@ function TampilanDetailDonasi({
|
||||
|
||||
<Grid>
|
||||
<Grid.Col span={4}>
|
||||
<Text fz={"xs"}>Total donatur</Text>
|
||||
<Text c={AdminColor.white} fz={"xs"}>Total donatur</Text>
|
||||
</Grid.Col>
|
||||
<Grid.Col span={"content"}>:</Grid.Col>
|
||||
<Grid.Col c={AdminColor.white} span={"content"}>:</Grid.Col>
|
||||
<Grid.Col span={"auto"}>
|
||||
<Title order={5} c="blue">
|
||||
<Title order={5} c={AdminColor.white}>
|
||||
{countDonatur}
|
||||
</Title>
|
||||
</Grid.Col>
|
||||
@@ -207,11 +207,11 @@ function TampilanDetailDonasi({
|
||||
|
||||
<Grid>
|
||||
<Grid.Col span={4}>
|
||||
<Text fz={12}>Progres</Text>
|
||||
<Text c={AdminColor.white} fz={12}>Progres</Text>
|
||||
</Grid.Col>
|
||||
<Grid.Col span={"content"}>:</Grid.Col>
|
||||
<Grid.Col c={AdminColor.white} span={"content"}>:</Grid.Col>
|
||||
<Grid.Col span={"auto"}>
|
||||
<Title order={5} c="blue">
|
||||
<Title order={5} c={AdminColor.white}>
|
||||
{toNumber(donasi.progres).toFixed(2)} %
|
||||
</Title>
|
||||
</Grid.Col>
|
||||
@@ -219,13 +219,13 @@ function TampilanDetailDonasi({
|
||||
|
||||
<Grid>
|
||||
<Grid.Col span={4}>
|
||||
<Text fz={12}>Dana terkumpul</Text>
|
||||
<Text c={AdminColor.white} fz={12}>Dana terkumpul</Text>
|
||||
</Grid.Col>
|
||||
<Grid.Col span={"content"}>:</Grid.Col>
|
||||
<Grid.Col c={AdminColor.white} span={"content"}>:</Grid.Col>
|
||||
<Grid.Col span={"auto"}>
|
||||
<ComponentGlobal_TampilanRupiah
|
||||
nominal={+donasi?.terkumpul}
|
||||
color="darkblue"
|
||||
color={AdminColor.yellow}
|
||||
/>
|
||||
</Grid.Col>
|
||||
</Grid>
|
||||
@@ -233,25 +233,25 @@ function TampilanDetailDonasi({
|
||||
</Paper>
|
||||
|
||||
{/* Pencairan Dana */}
|
||||
<Paper withBorder p={"sm"}>
|
||||
<Paper bg={AdminColor.softBlue} p={"sm"}>
|
||||
<Stack spacing={"xl"}>
|
||||
<Center>
|
||||
<Title order={4}>Pencairan Dana</Title>
|
||||
<Title c={AdminColor.white} order={4}>Pencairan Dana</Title>
|
||||
</Center>
|
||||
<Grid>
|
||||
<Grid.Col span={"auto"}>
|
||||
<Stack spacing={0}>
|
||||
<Text fz={"xs"}>Total Dana Dicairkan</Text>
|
||||
<Text c={AdminColor.white} fz={"xs"}>Total Dana Dicairkan</Text>
|
||||
<ComponentGlobal_TampilanRupiah
|
||||
nominal={donasi?.totalPencairan}
|
||||
color="darkblue"
|
||||
color={AdminColor.yellow}
|
||||
/>
|
||||
</Stack>
|
||||
</Grid.Col>
|
||||
<Grid.Col span={"auto"}>
|
||||
<Stack spacing={0}>
|
||||
<Text fz={"xs"}>Bank Tujuan</Text>
|
||||
<Title order={6} c={"blue"}>
|
||||
<Text c={AdminColor.white} fz={"xs"}>Bank Tujuan</Text>
|
||||
<Title order={6} c={AdminColor.white}>
|
||||
{donasi?.namaBank}
|
||||
</Title>
|
||||
</Stack>
|
||||
@@ -260,16 +260,16 @@ function TampilanDetailDonasi({
|
||||
<Grid>
|
||||
<Grid.Col span={"auto"}>
|
||||
<Stack spacing={0}>
|
||||
<Text fz={"xs"}>Akumulasi Pencairan</Text>
|
||||
<Title order={6} c={"blue"}>
|
||||
<Text c={AdminColor.white} fz={"xs"}>Akumulasi Pencairan</Text>
|
||||
<Title order={6} c={AdminColor.white}>
|
||||
{donasi?.akumulasiPencairan} Kali
|
||||
</Title>
|
||||
</Stack>
|
||||
</Grid.Col>
|
||||
<Grid.Col span={"auto"}>
|
||||
<Stack spacing={0}>
|
||||
<Text fz={"xs"}>Nomor Rekening</Text>
|
||||
<Title order={6} c={"blue"}>
|
||||
<Text fz={"xs"} c={AdminColor.white}>Nomor Rekening</Text>
|
||||
<Title order={6} c={AdminColor.white}>
|
||||
{donasi?.rekening}
|
||||
</Title>
|
||||
</Stack>
|
||||
@@ -277,13 +277,13 @@ function TampilanDetailDonasi({
|
||||
</Grid>
|
||||
|
||||
<Stack align="center" spacing={0}>
|
||||
<Text fz={"xs"}>Sisa Dana</Text>
|
||||
<Text c={AdminColor.white} fz={"xs"}>Sisa Dana</Text>
|
||||
<ComponentGlobal_TampilanRupiah
|
||||
nominal={
|
||||
toNumber(donasi.terkumpul) -
|
||||
toNumber(donasi.totalPencairan)
|
||||
}
|
||||
color="darkblue"
|
||||
color={AdminColor.yellow}
|
||||
/>
|
||||
</Stack>
|
||||
|
||||
|
||||
@@ -129,7 +129,7 @@ function TableStatus({ listData }: { listData: any }) {
|
||||
<Center c={AccentColor.white}>{e.title}</Center>
|
||||
</td>
|
||||
<td>
|
||||
<Center>
|
||||
<Center c={AccentColor.white}>
|
||||
<Spoiler
|
||||
hideLabel="sembunyikan"
|
||||
maw={400}
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
export {
|
||||
apiGetVoteStatusCountDashboard,
|
||||
apiGetVoteRiwayatCount
|
||||
apiGetAdminVoteStatusCountDashboard,
|
||||
apiGetAdminVoteRiwayatCount,
|
||||
apiGetAdminVotingByStatus
|
||||
}
|
||||
const apiGetVoteStatusCountDashboard = async ({ name }: {
|
||||
const apiGetAdminVoteStatusCountDashboard = async ({ name }: {
|
||||
name: "Publish" | "Review" | "Reject";
|
||||
}) => {
|
||||
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
|
||||
if (!token) return await token.json().catch(() => null);
|
||||
|
||||
const response = await fetch(`/api/admin/voting/dashboard/${name}`, {
|
||||
const response = await fetch(`/api/admin/vote/dashboard/${name}`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
@@ -19,11 +20,11 @@ const apiGetVoteStatusCountDashboard = async ({ name }: {
|
||||
});
|
||||
return await response.json().catch(() => null);
|
||||
}
|
||||
const apiGetVoteRiwayatCount = async () => {
|
||||
const apiGetAdminVoteRiwayatCount = async () => {
|
||||
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
|
||||
if (!token) return await token.json().catch(() => null);
|
||||
|
||||
const response = await fetch(`/api/admin/voting/dashboard/riwayat`, {
|
||||
const response = await fetch(`/api/admin/vote/dashboard/riwayat`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
@@ -33,4 +34,31 @@ const apiGetVoteRiwayatCount = async () => {
|
||||
}
|
||||
});
|
||||
return await response.json().catch(() => null);
|
||||
}
|
||||
|
||||
const apiGetAdminVotingByStatus = async ({
|
||||
name,
|
||||
page,
|
||||
search }: {
|
||||
name: "Publish" | "Review" | "Reject";
|
||||
page: string;
|
||||
search: string;
|
||||
}) => {
|
||||
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
|
||||
if (!token) return await token.json().catch(() => null);
|
||||
|
||||
const isPage = page ? `?page=${page}` : "";
|
||||
const isSearch = search ? `&search=${search}` : "";
|
||||
const response = await fetch(
|
||||
`/api/admin/vote/status/${name}${isPage}${isSearch}`,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
Authorization: `Bearer ${token}`
|
||||
}
|
||||
}
|
||||
)
|
||||
return await response.json().catch(() => null);
|
||||
}
|
||||
@@ -7,10 +7,11 @@ import { IconAlertTriangle, IconBookmark, IconHistory, IconUpload } from "@table
|
||||
import { AccentColor, AdminColor } from "@/app_modules/_global/color/color_pallet";
|
||||
import { useState } from "react";
|
||||
import { clientLogger } from "@/util/clientLogger";
|
||||
import { apiGetVoteRiwayatCount, apiGetVoteStatusCountDashboard } from "../lib/api_fetch_admin_voting";
|
||||
|
||||
import global_limit from "@/lib/limit";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
|
||||
import { apiGetAdminVoteRiwayatCount, apiGetAdminVoteStatusCountDashboard } from "../lib/api_fetch_admin_voting";
|
||||
|
||||
export default function AdminVote_Main() {
|
||||
const [countPublish, setCountPublish] = useState<number | null>(null);
|
||||
@@ -36,7 +37,7 @@ export default function AdminVote_Main() {
|
||||
}
|
||||
async function onLoadCountPublish() {
|
||||
try {
|
||||
const response = await apiGetVoteStatusCountDashboard({
|
||||
const response = await apiGetAdminVoteStatusCountDashboard({
|
||||
name: "Publish",
|
||||
})
|
||||
if (response) {
|
||||
@@ -48,7 +49,7 @@ export default function AdminVote_Main() {
|
||||
}
|
||||
async function onLoadCountReview() {
|
||||
try {
|
||||
const response = await apiGetVoteStatusCountDashboard({
|
||||
const response = await apiGetAdminVoteStatusCountDashboard({
|
||||
name: "Review",
|
||||
})
|
||||
|
||||
@@ -61,7 +62,7 @@ export default function AdminVote_Main() {
|
||||
}
|
||||
async function onLoadCountReject() {
|
||||
try {
|
||||
const response = await apiGetVoteStatusCountDashboard({
|
||||
const response = await apiGetAdminVoteStatusCountDashboard({
|
||||
name: "Reject",
|
||||
})
|
||||
if (response) {
|
||||
@@ -73,7 +74,7 @@ export default function AdminVote_Main() {
|
||||
}
|
||||
async function onLoadCountRiwayat() {
|
||||
try {
|
||||
const response = await apiGetVoteRiwayatCount()
|
||||
const response = await apiGetAdminVoteRiwayatCount()
|
||||
if (response) {
|
||||
setCountRiwayat(response.data);
|
||||
}
|
||||
|
||||
@@ -34,8 +34,8 @@ const middlewareConfig: MiddlewareConfig = {
|
||||
|
||||
// ADMIN API
|
||||
// >> buat dibawah sini <<
|
||||
"api/admin/job/*",
|
||||
|
||||
"/api/admin/vote/*",
|
||||
|
||||
|
||||
// Akses awal
|
||||
"/api/get-cookie",
|
||||
|
||||
Reference in New Issue
Block a user