API Dashboard Investasi & Event
This commit is contained in:
50
src/app/api/admin/donasi/dashboard/[name]/route.ts
Normal file
50
src/app/api/admin/donasi/dashboard/[name]/route.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { prisma } from "@/app/lib";
|
||||
import backendLogger from "@/util/backendLogger";
|
||||
import { data } from "autoprefixer";
|
||||
import _ from "lodash";
|
||||
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;
|
||||
try {
|
||||
let fixData;
|
||||
const fixStatus = _.startCase(name);
|
||||
fixData = await prisma.donasi.count({
|
||||
where: {
|
||||
DonasiMaster_Status: {
|
||||
name: fixStatus
|
||||
}
|
||||
}
|
||||
});
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: "Success get data donasi dashboard",
|
||||
data: fixData
|
||||
},
|
||||
{ status: 200 }
|
||||
)
|
||||
} catch (error) {
|
||||
backendLogger.error("Error get data donasi dashboard >>", error);
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: "Failed to get data donasi dashboard",
|
||||
reason: (error as Error).message
|
||||
},
|
||||
{ status: 500 }
|
||||
)
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
}
|
||||
53
src/app/api/admin/event/dashboard/[name]/route.ts
Normal file
53
src/app/api/admin/event/dashboard/[name]/route.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { prisma } from "@/app/lib";
|
||||
import backendLogger from "@/util/backendLogger";
|
||||
import _ from "lodash";
|
||||
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;
|
||||
|
||||
try {
|
||||
let fixData;
|
||||
const fixStatus = _.startCase(name);
|
||||
fixData = await prisma.event.count({
|
||||
where: {
|
||||
EventMaster_Status: {
|
||||
name: fixStatus,
|
||||
},
|
||||
isArsip: false,
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: "Success get data event dashboard",
|
||||
data: fixData,
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
} catch (error) {
|
||||
backendLogger.error("Error get data event dashboard >>", error);
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Failed to get data",
|
||||
reason: (error as Error).message,
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
}
|
||||
47
src/app/api/admin/event/dashboard/riwayat/route.ts
Normal file
47
src/app/api/admin/event/dashboard/riwayat/route.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { prisma } from "@/app/lib";
|
||||
import backendLogger from "@/util/backendLogger";
|
||||
import _ from "lodash";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const method = request.method;
|
||||
if (method !== "GET") {
|
||||
return NextResponse.json(
|
||||
{ success: false, message: "Method not allowed" },
|
||||
{ status: 405 }
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
let fixData;
|
||||
fixData = await prisma.event.count({
|
||||
where: {
|
||||
EventMaster_Status: {
|
||||
name: "Publish",
|
||||
},
|
||||
isArsip: true,
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: "Success get data riwayat event dashboard",
|
||||
data: fixData,
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
} catch (error) {
|
||||
backendLogger.error("Error get data riwayat event dashboard >>", error);
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Failed to get data",
|
||||
reason: (error as Error).message,
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
}
|
||||
44
src/app/api/admin/event/dashboard/tipe-acara/route.ts
Normal file
44
src/app/api/admin/event/dashboard/tipe-acara/route.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { prisma } from "@/app/lib";
|
||||
import backendLogger from "@/util/backendLogger";
|
||||
import _ from "lodash";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const method = request.method;
|
||||
if (method !== "GET") {
|
||||
return NextResponse.json(
|
||||
{ success: false, message: "Method not allowed" },
|
||||
{ status: 405 }
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
let fixData;
|
||||
fixData = await prisma.eventMaster_TipeAcara.count({
|
||||
where: {
|
||||
active: true,
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: "Success get data riwayat event dashboard",
|
||||
data: fixData,
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
} catch (error) {
|
||||
backendLogger.error("Error get data riwayat event dashboard >>", error);
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Failed to get data",
|
||||
reason: (error as Error).message,
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
}
|
||||
@@ -1,24 +1,41 @@
|
||||
import { prisma } from "@/app/lib";
|
||||
import backendLogger from "@/util/backendLogger";
|
||||
import _ from "lodash";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export async function GET(request: Request) {
|
||||
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;
|
||||
try {
|
||||
const data = await prisma.investasi.count({
|
||||
let fixData;
|
||||
const fixStatus = _.startCase(name);
|
||||
fixData = await prisma.investasi.count({
|
||||
where: {
|
||||
active: true
|
||||
},
|
||||
MasterStatusInvestasi: {
|
||||
name: fixStatus
|
||||
},
|
||||
}
|
||||
})
|
||||
return NextResponse.json({
|
||||
message: "Data Investasi",
|
||||
data: data,
|
||||
success: true,
|
||||
message: "Success get data investasi dashboard",
|
||||
data: fixData,
|
||||
},
|
||||
{ status: 200 }
|
||||
)
|
||||
} catch (error) {
|
||||
backendLogger.error("Error Get Count Investasi Main Dashboard")
|
||||
backendLogger.error("Error get data investasi dashboard >>", error);
|
||||
return NextResponse.json({
|
||||
message: "Error Get Count Investasi Main Dashboard",
|
||||
success: false,
|
||||
message: "Error get data investasi dashboard",
|
||||
reason: (error as Error).message
|
||||
},
|
||||
{ status: 500 }
|
||||
|
||||
@@ -32,19 +32,17 @@ export async function GET(
|
||||
},
|
||||
});
|
||||
|
||||
await prisma.$disconnect();
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: "Berhasil mendapatkan data",
|
||||
data: fixData,
|
||||
});
|
||||
} catch (error) {
|
||||
await prisma.$disconnect();
|
||||
return NextResponse.json(
|
||||
{ success: false, message: "Gagal mendapatkan data" },
|
||||
{ status: 500 }
|
||||
);
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
41
src/app/api/master/bank/route.ts
Normal file
41
src/app/api/master/bank/route.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { prisma } from "@/app/lib";
|
||||
import backendLogger from "@/util/backendLogger";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const method = request.method;
|
||||
if (method !== "GET") {
|
||||
return NextResponse.json(
|
||||
{ success: false, message: "Method not allowed" },
|
||||
{ status: 405 }
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await prisma.masterBank.findMany({
|
||||
orderBy: {
|
||||
updatedAt: "asc",
|
||||
},
|
||||
where: {
|
||||
isActive: true,
|
||||
},
|
||||
});
|
||||
|
||||
await prisma.$disconnect();
|
||||
return NextResponse.json(
|
||||
{ success: true, message: "Berhasil mendapatkan data", data: res },
|
||||
{ status: 200 }
|
||||
);
|
||||
} catch (error) {
|
||||
await prisma.$disconnect();
|
||||
backendLogger.error("Error Get Master Bank >>", error);
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "API Error Get Data",
|
||||
reason: (error as Error).message,
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
41
src/app/api/master/status_transaksi/route.ts
Normal file
41
src/app/api/master/status_transaksi/route.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { prisma } from "@/app/lib";
|
||||
import backendLogger from "@/util/backendLogger";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const method = request.method;
|
||||
if (method !== "GET") {
|
||||
return NextResponse.json(
|
||||
{ success: false, message: "Method not allowed" },
|
||||
{ status: 405 }
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await prisma.masterStatusTransaksi.findMany({
|
||||
orderBy: {
|
||||
updatedAt: "asc",
|
||||
},
|
||||
where: {
|
||||
isActive: true,
|
||||
},
|
||||
});
|
||||
|
||||
await prisma.$disconnect();
|
||||
return NextResponse.json(
|
||||
{ success: true, message: "Berhasil mendapatkan data", data: res },
|
||||
{ status: 200 }
|
||||
);
|
||||
} catch (error) {
|
||||
await prisma.$disconnect();
|
||||
backendLogger.error("Error Get Master Status Transaksi >>", error);
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "API Error Get Data",
|
||||
reason: (error as Error).message,
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
60
src/app/dev/admin/event/_lib/api_fecth_admin_event.ts
Normal file
60
src/app/dev/admin/event/_lib/api_fecth_admin_event.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
export {
|
||||
apiGetEventStatusCountDashboard,
|
||||
apiGetEventTipeAcara,
|
||||
apiGetEventRiwayatCount,
|
||||
};
|
||||
|
||||
const apiGetEventStatusCountDashboard = 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/event/dashboard/${name}`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
|
||||
return await response.json().catch(() => null);
|
||||
};
|
||||
|
||||
const apiGetEventRiwayatCount = 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/event/dashboard/riwayat`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
|
||||
return await response.json().catch(() => null);
|
||||
}
|
||||
|
||||
const apiGetEventTipeAcara = 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/event/dashboard/tipe-acara`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
|
||||
return await response.json().catch(() => null);
|
||||
};
|
||||
@@ -1,26 +1,9 @@
|
||||
import { AdminEvent_Main } from "@/app_modules/admin/event";
|
||||
import AdminEvent_funCountByStatusId from "@/app_modules/admin/event/fun/count/fun_count_event_by_status_id";
|
||||
import { AdminEvent_funCountRiwayat } from "@/app_modules/admin/event/fun/count/fun_count_riwayat";
|
||||
import { AdminEvent_funCountTipeAcara } from "@/app_modules/admin/event/fun/count/fun_count_tipe_acara";
|
||||
|
||||
export default async function Page() {
|
||||
const countPublish = await AdminEvent_funCountByStatusId("1");
|
||||
const countReview = await AdminEvent_funCountByStatusId("2");
|
||||
const countDraft = await AdminEvent_funCountByStatusId("3");
|
||||
const countReject = await AdminEvent_funCountByStatusId("4");
|
||||
const countTipeAcara = await AdminEvent_funCountTipeAcara();
|
||||
const countRiwayat = await AdminEvent_funCountRiwayat();
|
||||
|
||||
return (
|
||||
<>
|
||||
<AdminEvent_Main
|
||||
countPublish={countPublish as number}
|
||||
countReview={countReview as number}
|
||||
countDraft={countDraft as number}
|
||||
countReject={countReject as number}
|
||||
countTipeAcara={countTipeAcara as number}
|
||||
countRiwayat={countRiwayat}
|
||||
/>
|
||||
<AdminEvent_Main />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -6,10 +6,10 @@ import Admin_getTotalInvestasiByUser from "@/app_modules/admin/investasi/fun/get
|
||||
|
||||
export default async function Page() {
|
||||
const listInvestasi = await Admin_funGetAllInvestasi();
|
||||
const countDraft = await Admin_CountStatusInvestasi(1);
|
||||
const countReview = await Admin_CountStatusInvestasi(2);
|
||||
const countPublish = await Admin_CountStatusInvestasi(3);
|
||||
const countReject = await Admin_CountStatusInvestasi(4);
|
||||
// const countDraft = await Admin_CountStatusInvestasi(1);
|
||||
// const countReview = await Admin_CountStatusInvestasi(2);
|
||||
// const countPublish = await Admin_CountStatusInvestasi(3);
|
||||
// const countReject = await Admin_CountStatusInvestasi(4);
|
||||
const totalInvestasiByUser = await Admin_getTotalInvestasiByUser()
|
||||
const publishProgres = await Admin_getPublishProgresInvestasi()
|
||||
// console.log(targetTerbesar)
|
||||
@@ -18,10 +18,10 @@ export default async function Page() {
|
||||
<>
|
||||
<Admin_Investasi
|
||||
listInvestasi={listInvestasi as any}
|
||||
countDraft={countDraft}
|
||||
countReview={countReview}
|
||||
countPublish={countPublish}
|
||||
countReject={countReject}
|
||||
// countDraft={countDraft}
|
||||
// countReview={countReview}
|
||||
// countPublish={countPublish}
|
||||
// countReject={countReject}
|
||||
totalInvestasiByUser={totalInvestasiByUser}
|
||||
publishProgres={publishProgres}
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
|
||||
import Event_MetodePembayaran from '@/app_modules/event/detail/sponsor/metode_pembayaran';
|
||||
import { MODEL_MASTER_BANK } from '@/app_modules/investasi/_lib/interface';
|
||||
import React from 'react';
|
||||
|
||||
function Page() {
|
||||
return (
|
||||
14
src/app/dev/event/invoice/[id]/page.tsx
Normal file
14
src/app/dev/event/invoice/[id]/page.tsx
Normal file
@@ -0,0 +1,14 @@
|
||||
import { funGetUserIdByToken } from '@/app_modules/_global/fun/get';
|
||||
import Event_Invoice from '@/app_modules/event/detail/invoice';
|
||||
import React from 'react';
|
||||
|
||||
async function Page() {
|
||||
const userLoginId = await funGetUserIdByToken();
|
||||
return (
|
||||
<>
|
||||
<Event_Invoice userLoginId={userLoginId} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default Page;
|
||||
@@ -1,12 +0,0 @@
|
||||
import Event_Invoice from '@/app_modules/event/detail/invoice';
|
||||
import React from 'react';
|
||||
|
||||
function Page() {
|
||||
return (
|
||||
<>
|
||||
<Event_Invoice/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default Page;
|
||||
5
src/app/lib/limit.ts
Normal file
5
src/app/lib/limit.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import pLimit from "p-limit";
|
||||
|
||||
const global_limit = pLimit(1);
|
||||
|
||||
export default global_limit;
|
||||
@@ -1,28 +0,0 @@
|
||||
"use server";
|
||||
|
||||
import _ from "lodash";
|
||||
import { cookies } from "next/headers";
|
||||
import { decrypt } from "../auth/_lib/decrypt";
|
||||
import backendLogger from "@/util/backendLogger";
|
||||
|
||||
export async function newFunGetUserId() {
|
||||
try {
|
||||
const key = process.env.NEXT_PUBLIC_BASE_SESSION_KEY;
|
||||
const c = cookies().get("hipmi-key");
|
||||
|
||||
if (!c || !c?.value || _.isEmpty(c?.value) || _.isUndefined(c?.value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const token = c.value;
|
||||
const dataUser = await decrypt({
|
||||
token: token,
|
||||
encodedKey: process.env.NEXT_PUBLIC_BASE_TOKEN_KEY!,
|
||||
});
|
||||
|
||||
return dataUser?.id;
|
||||
} catch (error) {
|
||||
backendLogger.log("Gagal mendapatkan user id", error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,11 @@ export const RouterEvent = {
|
||||
`/dev/event/detail/sponsor/tambah_sponsor/${id}`,
|
||||
detail_sponsor: ({ id }: { id: string }) =>
|
||||
`/dev/event/detail/detail_sponsor/${id}`,
|
||||
|
||||
nominal_sponsor: ({ id }: { id: string }) =>
|
||||
`/dev/event/detail/sponsor/nominal_sponsor/${id}`,
|
||||
|
||||
metode_pembayaran: ({ id }: { id: string }) =>
|
||||
`/dev/event/detail/sponsor/metode_pembayaran/${id}`,
|
||||
invoice: ({ id }: { id: string }) =>
|
||||
`/dev/event/invoice/${id}`,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user