API Voting & Belum di Integrasikan ke UInya
This commit is contained in:
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" },
|
{ maxWidth: "36rem", cols: 1, spacing: "sm" },
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
<Paper p={"xs"}>
|
<Paper p={"xs"} bg={AdminColor.softBlue}>
|
||||||
<Stack>
|
<Stack>
|
||||||
<Title align="center" order={4}>
|
<Title c={AdminColor.white} align="center" order={4}>
|
||||||
Gambar Donasi
|
Gambar Donasi
|
||||||
</Title>
|
</Title>
|
||||||
<Admin_ComponentLoadImageLandscape fileId={donasi.imageId} />
|
<Admin_ComponentLoadImageLandscape fileId={donasi.imageId} />
|
||||||
</Stack>
|
</Stack>
|
||||||
</Paper>
|
</Paper>
|
||||||
|
|
||||||
<Paper p={"sm"}>
|
<Paper p={"sm"} bg={AdminColor.softBlue}>
|
||||||
<Stack spacing={5}>
|
<Stack spacing={5}>
|
||||||
<Title order={4}>Detail Donasi</Title>
|
<Title c={AdminColor.white} order={4}>Detail Donasi</Title>
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.Col span={4}>
|
<Grid.Col span={4}>
|
||||||
<Text fz={"xs"}>Judul</Text>
|
<Text c={AdminColor.white} fz={"xs"}>Judul</Text>
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
<Grid.Col span={"content"}>:</Grid.Col>
|
<Grid.Col c={AdminColor.white} span={"content"}>:</Grid.Col>
|
||||||
<Grid.Col span={"auto"}>
|
<Grid.Col span={"auto"}>
|
||||||
<Title order={5} c="blue">
|
<Title order={5} c={AdminColor.white}>
|
||||||
{donasi?.title}
|
{donasi?.title}
|
||||||
</Title>
|
</Title>
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
@@ -146,11 +146,11 @@ function TampilanDetailDonasi({
|
|||||||
|
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.Col span={4}>
|
<Grid.Col span={4}>
|
||||||
<Text fz={"xs"}>Penggalang Dana</Text>
|
<Text c={AdminColor.white} fz={"xs"}>Penggalang Dana</Text>
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
<Grid.Col span={"content"}>:</Grid.Col>
|
<Grid.Col c={AdminColor.white} span={"content"}>:</Grid.Col>
|
||||||
<Grid.Col span={"auto"}>
|
<Grid.Col span={"auto"}>
|
||||||
<Title order={5} c="blue">
|
<Title order={5} c={AdminColor.white}>
|
||||||
{donasi?.Author.username}
|
{donasi?.Author.username}
|
||||||
</Title>
|
</Title>
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
@@ -158,11 +158,11 @@ function TampilanDetailDonasi({
|
|||||||
|
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.Col span={4}>
|
<Grid.Col span={4}>
|
||||||
<Text fz={"xs"}>Durasi</Text>
|
<Text c={AdminColor.white} fz={"xs"}>Durasi</Text>
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
<Grid.Col span={"content"}>:</Grid.Col>
|
<Grid.Col c={AdminColor.white} span={"content"}>:</Grid.Col>
|
||||||
<Grid.Col span={"auto"}>
|
<Grid.Col span={"auto"}>
|
||||||
<Title order={5} c="blue">
|
<Title c={AdminColor.white} order={5}>
|
||||||
{donasi?.DonasiMaster_Durasi.name} hari
|
{donasi?.DonasiMaster_Durasi.name} hari
|
||||||
</Title>
|
</Title>
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
@@ -170,24 +170,24 @@ function TampilanDetailDonasi({
|
|||||||
|
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.Col span={4}>
|
<Grid.Col span={4}>
|
||||||
<Text fz={"xs"}>Dana dibutuhkan</Text>
|
<Text c={AdminColor.white} fz={"xs"}>Dana dibutuhkan</Text>
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
<Grid.Col span={"content"}>:</Grid.Col>
|
<Grid.Col c={AdminColor.white} span={"content"}>:</Grid.Col>
|
||||||
<Grid.Col span={"auto"}>
|
<Grid.Col span={"auto"}>
|
||||||
<ComponentGlobal_TampilanRupiah
|
<ComponentGlobal_TampilanRupiah
|
||||||
nominal={+donasi?.target}
|
nominal={+donasi?.target}
|
||||||
color="darkblue"
|
color={AdminColor.yellow}
|
||||||
/>
|
/>
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.Col span={4}>
|
<Grid.Col span={4}>
|
||||||
<Text fz={"xs"}>Kategori</Text>
|
<Text c={AdminColor.white} fz={"xs"}>Kategori</Text>
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
<Grid.Col span={"content"}>:</Grid.Col>
|
<Grid.Col c={AdminColor.white} span={"content"}>:</Grid.Col>
|
||||||
<Grid.Col span={"auto"}>
|
<Grid.Col span={"auto"}>
|
||||||
<Title order={5} c="blue">
|
<Title c={AdminColor.white} order={5}>
|
||||||
{donasi?.DonasiMaster_Ketegori?.name}
|
{donasi?.DonasiMaster_Ketegori?.name}
|
||||||
</Title>
|
</Title>
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
@@ -195,11 +195,11 @@ function TampilanDetailDonasi({
|
|||||||
|
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.Col span={4}>
|
<Grid.Col span={4}>
|
||||||
<Text fz={"xs"}>Total donatur</Text>
|
<Text c={AdminColor.white} fz={"xs"}>Total donatur</Text>
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
<Grid.Col span={"content"}>:</Grid.Col>
|
<Grid.Col c={AdminColor.white} span={"content"}>:</Grid.Col>
|
||||||
<Grid.Col span={"auto"}>
|
<Grid.Col span={"auto"}>
|
||||||
<Title order={5} c="blue">
|
<Title order={5} c={AdminColor.white}>
|
||||||
{countDonatur}
|
{countDonatur}
|
||||||
</Title>
|
</Title>
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
@@ -207,11 +207,11 @@ function TampilanDetailDonasi({
|
|||||||
|
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.Col span={4}>
|
<Grid.Col span={4}>
|
||||||
<Text fz={12}>Progres</Text>
|
<Text c={AdminColor.white} fz={12}>Progres</Text>
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
<Grid.Col span={"content"}>:</Grid.Col>
|
<Grid.Col c={AdminColor.white} span={"content"}>:</Grid.Col>
|
||||||
<Grid.Col span={"auto"}>
|
<Grid.Col span={"auto"}>
|
||||||
<Title order={5} c="blue">
|
<Title order={5} c={AdminColor.white}>
|
||||||
{toNumber(donasi.progres).toFixed(2)} %
|
{toNumber(donasi.progres).toFixed(2)} %
|
||||||
</Title>
|
</Title>
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
@@ -219,13 +219,13 @@ function TampilanDetailDonasi({
|
|||||||
|
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.Col span={4}>
|
<Grid.Col span={4}>
|
||||||
<Text fz={12}>Dana terkumpul</Text>
|
<Text c={AdminColor.white} fz={12}>Dana terkumpul</Text>
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
<Grid.Col span={"content"}>:</Grid.Col>
|
<Grid.Col c={AdminColor.white} span={"content"}>:</Grid.Col>
|
||||||
<Grid.Col span={"auto"}>
|
<Grid.Col span={"auto"}>
|
||||||
<ComponentGlobal_TampilanRupiah
|
<ComponentGlobal_TampilanRupiah
|
||||||
nominal={+donasi?.terkumpul}
|
nominal={+donasi?.terkumpul}
|
||||||
color="darkblue"
|
color={AdminColor.yellow}
|
||||||
/>
|
/>
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
</Grid>
|
</Grid>
|
||||||
@@ -233,25 +233,25 @@ function TampilanDetailDonasi({
|
|||||||
</Paper>
|
</Paper>
|
||||||
|
|
||||||
{/* Pencairan Dana */}
|
{/* Pencairan Dana */}
|
||||||
<Paper withBorder p={"sm"}>
|
<Paper bg={AdminColor.softBlue} p={"sm"}>
|
||||||
<Stack spacing={"xl"}>
|
<Stack spacing={"xl"}>
|
||||||
<Center>
|
<Center>
|
||||||
<Title order={4}>Pencairan Dana</Title>
|
<Title c={AdminColor.white} order={4}>Pencairan Dana</Title>
|
||||||
</Center>
|
</Center>
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.Col span={"auto"}>
|
<Grid.Col span={"auto"}>
|
||||||
<Stack spacing={0}>
|
<Stack spacing={0}>
|
||||||
<Text fz={"xs"}>Total Dana Dicairkan</Text>
|
<Text c={AdminColor.white} fz={"xs"}>Total Dana Dicairkan</Text>
|
||||||
<ComponentGlobal_TampilanRupiah
|
<ComponentGlobal_TampilanRupiah
|
||||||
nominal={donasi?.totalPencairan}
|
nominal={donasi?.totalPencairan}
|
||||||
color="darkblue"
|
color={AdminColor.yellow}
|
||||||
/>
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
<Grid.Col span={"auto"}>
|
<Grid.Col span={"auto"}>
|
||||||
<Stack spacing={0}>
|
<Stack spacing={0}>
|
||||||
<Text fz={"xs"}>Bank Tujuan</Text>
|
<Text c={AdminColor.white} fz={"xs"}>Bank Tujuan</Text>
|
||||||
<Title order={6} c={"blue"}>
|
<Title order={6} c={AdminColor.white}>
|
||||||
{donasi?.namaBank}
|
{donasi?.namaBank}
|
||||||
</Title>
|
</Title>
|
||||||
</Stack>
|
</Stack>
|
||||||
@@ -260,16 +260,16 @@ function TampilanDetailDonasi({
|
|||||||
<Grid>
|
<Grid>
|
||||||
<Grid.Col span={"auto"}>
|
<Grid.Col span={"auto"}>
|
||||||
<Stack spacing={0}>
|
<Stack spacing={0}>
|
||||||
<Text fz={"xs"}>Akumulasi Pencairan</Text>
|
<Text c={AdminColor.white} fz={"xs"}>Akumulasi Pencairan</Text>
|
||||||
<Title order={6} c={"blue"}>
|
<Title order={6} c={AdminColor.white}>
|
||||||
{donasi?.akumulasiPencairan} Kali
|
{donasi?.akumulasiPencairan} Kali
|
||||||
</Title>
|
</Title>
|
||||||
</Stack>
|
</Stack>
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
<Grid.Col span={"auto"}>
|
<Grid.Col span={"auto"}>
|
||||||
<Stack spacing={0}>
|
<Stack spacing={0}>
|
||||||
<Text fz={"xs"}>Nomor Rekening</Text>
|
<Text fz={"xs"} c={AdminColor.white}>Nomor Rekening</Text>
|
||||||
<Title order={6} c={"blue"}>
|
<Title order={6} c={AdminColor.white}>
|
||||||
{donasi?.rekening}
|
{donasi?.rekening}
|
||||||
</Title>
|
</Title>
|
||||||
</Stack>
|
</Stack>
|
||||||
@@ -277,13 +277,13 @@ function TampilanDetailDonasi({
|
|||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
<Stack align="center" spacing={0}>
|
<Stack align="center" spacing={0}>
|
||||||
<Text fz={"xs"}>Sisa Dana</Text>
|
<Text c={AdminColor.white} fz={"xs"}>Sisa Dana</Text>
|
||||||
<ComponentGlobal_TampilanRupiah
|
<ComponentGlobal_TampilanRupiah
|
||||||
nominal={
|
nominal={
|
||||||
toNumber(donasi.terkumpul) -
|
toNumber(donasi.terkumpul) -
|
||||||
toNumber(donasi.totalPencairan)
|
toNumber(donasi.totalPencairan)
|
||||||
}
|
}
|
||||||
color="darkblue"
|
color={AdminColor.yellow}
|
||||||
/>
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ function TableStatus({ listData }: { listData: any }) {
|
|||||||
<Center c={AccentColor.white}>{e.title}</Center>
|
<Center c={AccentColor.white}>{e.title}</Center>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<Center>
|
<Center c={AccentColor.white}>
|
||||||
<Spoiler
|
<Spoiler
|
||||||
hideLabel="sembunyikan"
|
hideLabel="sembunyikan"
|
||||||
maw={400}
|
maw={400}
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
export {
|
export {
|
||||||
apiGetVoteStatusCountDashboard,
|
apiGetAdminVoteStatusCountDashboard,
|
||||||
apiGetVoteRiwayatCount
|
apiGetAdminVoteRiwayatCount,
|
||||||
|
apiGetAdminVotingByStatus
|
||||||
}
|
}
|
||||||
const apiGetVoteStatusCountDashboard = async ({ name }: {
|
const apiGetAdminVoteStatusCountDashboard = async ({ name }: {
|
||||||
name: "Publish" | "Review" | "Reject";
|
name: "Publish" | "Review" | "Reject";
|
||||||
}) => {
|
}) => {
|
||||||
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
|
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
|
||||||
if (!token) return await token.json().catch(() => null);
|
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",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -19,11 +20,11 @@ const apiGetVoteStatusCountDashboard = async ({ name }: {
|
|||||||
});
|
});
|
||||||
return await response.json().catch(() => null);
|
return await response.json().catch(() => null);
|
||||||
}
|
}
|
||||||
const apiGetVoteRiwayatCount = async () => {
|
const apiGetAdminVoteRiwayatCount = async () => {
|
||||||
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
|
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
|
||||||
if (!token) return await token.json().catch(() => null);
|
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",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -33,4 +34,31 @@ const apiGetVoteRiwayatCount = async () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
return await response.json().catch(() => null);
|
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 { AccentColor, AdminColor } from "@/app_modules/_global/color/color_pallet";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { clientLogger } from "@/util/clientLogger";
|
import { clientLogger } from "@/util/clientLogger";
|
||||||
import { apiGetVoteRiwayatCount, apiGetVoteStatusCountDashboard } from "../lib/api_fetch_admin_voting";
|
|
||||||
import global_limit from "@/lib/limit";
|
import global_limit from "@/lib/limit";
|
||||||
import { useShallowEffect } from "@mantine/hooks";
|
import { useShallowEffect } from "@mantine/hooks";
|
||||||
import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
|
import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
|
||||||
|
import { apiGetAdminVoteRiwayatCount, apiGetAdminVoteStatusCountDashboard } from "../lib/api_fetch_admin_voting";
|
||||||
|
|
||||||
export default function AdminVote_Main() {
|
export default function AdminVote_Main() {
|
||||||
const [countPublish, setCountPublish] = useState<number | null>(null);
|
const [countPublish, setCountPublish] = useState<number | null>(null);
|
||||||
@@ -36,7 +37,7 @@ export default function AdminVote_Main() {
|
|||||||
}
|
}
|
||||||
async function onLoadCountPublish() {
|
async function onLoadCountPublish() {
|
||||||
try {
|
try {
|
||||||
const response = await apiGetVoteStatusCountDashboard({
|
const response = await apiGetAdminVoteStatusCountDashboard({
|
||||||
name: "Publish",
|
name: "Publish",
|
||||||
})
|
})
|
||||||
if (response) {
|
if (response) {
|
||||||
@@ -48,7 +49,7 @@ export default function AdminVote_Main() {
|
|||||||
}
|
}
|
||||||
async function onLoadCountReview() {
|
async function onLoadCountReview() {
|
||||||
try {
|
try {
|
||||||
const response = await apiGetVoteStatusCountDashboard({
|
const response = await apiGetAdminVoteStatusCountDashboard({
|
||||||
name: "Review",
|
name: "Review",
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -61,7 +62,7 @@ export default function AdminVote_Main() {
|
|||||||
}
|
}
|
||||||
async function onLoadCountReject() {
|
async function onLoadCountReject() {
|
||||||
try {
|
try {
|
||||||
const response = await apiGetVoteStatusCountDashboard({
|
const response = await apiGetAdminVoteStatusCountDashboard({
|
||||||
name: "Reject",
|
name: "Reject",
|
||||||
})
|
})
|
||||||
if (response) {
|
if (response) {
|
||||||
@@ -73,7 +74,7 @@ export default function AdminVote_Main() {
|
|||||||
}
|
}
|
||||||
async function onLoadCountRiwayat() {
|
async function onLoadCountRiwayat() {
|
||||||
try {
|
try {
|
||||||
const response = await apiGetVoteRiwayatCount()
|
const response = await apiGetAdminVoteRiwayatCount()
|
||||||
if (response) {
|
if (response) {
|
||||||
setCountRiwayat(response.data);
|
setCountRiwayat(response.data);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,8 +34,8 @@ const middlewareConfig: MiddlewareConfig = {
|
|||||||
|
|
||||||
// ADMIN API
|
// ADMIN API
|
||||||
// >> buat dibawah sini <<
|
// >> buat dibawah sini <<
|
||||||
"api/admin/job/*",
|
"/api/admin/vote/*",
|
||||||
|
|
||||||
|
|
||||||
// Akses awal
|
// Akses awal
|
||||||
"/api/get-cookie",
|
"/api/get-cookie",
|
||||||
|
|||||||
Reference in New Issue
Block a user