Merge pull request #299 from bipproduction/Nico/11-feb-25

API Investasi By Id & Fetch API Investasi By Id
This commit is contained in:
Bagasbanuna02
2025-02-11 17:36:08 +08:00
committed by GitHub
25 changed files with 123 additions and 226 deletions

View File

@@ -10,7 +10,6 @@ export async function GET(request: Request, { params }:
const { status } = 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;
@@ -21,8 +20,6 @@ export async function GET(request: Request, { params }:
if (!page) {
fixData = await prisma.projectCollaboration.findMany({
skip: skipData,
take: takeData,
orderBy: {
createdAt: "desc",
},
@@ -32,10 +29,7 @@ export async function GET(request: Request, { params }:
Author: {
active: true,
},
title: {
contains: search ? search : "",
mode: "insensitive",
},
},
select: {
id: true,
@@ -82,10 +76,6 @@ export async function GET(request: Request, { params }:
Author: {
active: true,
},
title: {
contains: search ? search : "",
mode: "insensitive",
},
},
select: {
id: true,

View File

@@ -6,15 +6,6 @@ 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;
@@ -59,7 +50,5 @@ export async function GET(request: Request, { params }: {
},
{ status: 500 }
)
} finally {
await prisma.$disconnect
}
}

View File

@@ -7,15 +7,6 @@ import { NextResponse } from "next/server";
export async function GET(request: Request,
{ params }: { params: { status: string } }) {
const method = request.method;
if (method !== "GET") {
return NextResponse.json({
succes: false,
message: "Method not allowed"
},
{ status: 405 }
);
}
const { status } = params;
const { searchParams } = new URL(request.url);
@@ -30,7 +21,7 @@ export async function GET(request: Request,
if (!page) {
const data = await prisma.donasi.findMany({
fixData = await prisma.donasi.findMany({
orderBy: {
createdAt: "desc",
},
@@ -83,7 +74,7 @@ export async function GET(request: Request,
DonasiMaster_Ketegori: true,
DonasiMaster_Durasi: true,
imageId: true,
},
})
@@ -120,7 +111,5 @@ export async function GET(request: Request,
},
{ status: 500 }
);
} finally {
await prisma.$disconnect();
}
}

View File

@@ -7,15 +7,6 @@ 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 {
@@ -44,7 +35,5 @@ export async function GET(request: Request, { params }: {
},
{ status: 500 }
)
} finally {
await prisma.$disconnect();
}
}

View File

@@ -4,14 +4,6 @@ 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 nol allowed"
},
{ status: 405 }
)
}
try {
const data = await prisma.donasiMaster_Kategori.findMany({
orderBy: {
@@ -38,7 +30,5 @@ export async function GET(request: Request) {
},
{ status: 500 }
)
} finally {
await prisma.$disconnect
}
}

View File

@@ -8,13 +8,7 @@ export async function GET(
request: Request,
{ params }: { params: { status: string } }
) {
const method = request.method;
if (method !== "GET") {
return NextResponse.json(
{ success: false, message: "Method not allowed" },
{ status: 405 }
);
}
const { status } = params;
const { searchParams } = new URL(request.url);
@@ -249,7 +243,5 @@ export async function GET(
},
{ status: 500 }
);
} finally {
await prisma.$disconnect();
}
}
}

View File

@@ -7,13 +7,6 @@ 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;
@@ -47,7 +40,5 @@ export async function GET(
},
{ status: 500 }
);
} finally {
await prisma.$disconnect();
}
}
}

View File

@@ -4,14 +4,6 @@ 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({
@@ -41,7 +33,5 @@ export async function GET(request: Request) {
},
{ status: 500 }
);
} finally {
await prisma.$disconnect();
}
}

View File

@@ -4,14 +4,7 @@ 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 }
);
}
const { searchParams } = new URL(request.url);
const search = searchParams.get("search");
const page = searchParams.get("page");
@@ -195,7 +188,5 @@ export async function GET(request: Request) {
},
{ status: 500 }
);
} finally {
await prisma.$disconnect();
}
}

View File

@@ -3,15 +3,7 @@ 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 {
let fixData;
fixData = await prisma.forum_ReportKomentar.count({
@@ -35,7 +27,5 @@ export async function GET(request: Request) {
},
{ status: 500 }
)
} finally {
await prisma.$disconnect();
}
}

View File

@@ -3,15 +3,6 @@ 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 {
let fixData;
fixData = await prisma.forum_ReportPosting.count({
@@ -35,7 +26,5 @@ export async function GET(request: Request) {
},
{ status: 500 }
)
} finally {
await prisma.$disconnect();
}
}

View File

@@ -5,15 +5,6 @@ import { NextResponse } from "next/server";
import _ from 'lodash';
export async function GET(request: Request) {
const method = request.method;
if (method !== "GET") {
return NextResponse.json({
success: false,
message: "Method not allowed"
},
{ status: 405 }
);
}
const { searchParams } = new URL(request.url);
const search = searchParams.get("search");
@@ -127,7 +118,5 @@ export async function GET(request: Request) {
reason: (error as Error).message
},
)
} finally {
await prisma.$disconnect();
}
}

View File

@@ -5,16 +5,6 @@ import { NextResponse } from "next/server";
export async function GET(request: Request,
{ postingId }: { postingId: string }) {
const method = request.method;
if (method !== "GET") {
return NextResponse.json({
success: false,
message: "Method not allowed",
},
{ status: 405 }
)
}
const { searchParams } = new URL(request.url);
const search = searchParams.get('search');
@@ -144,7 +134,5 @@ export async function GET(request: Request,
},
{ status: 500 }
)
} finally {
await prisma.$disconnect();
}
}
}

View File

@@ -4,15 +4,6 @@ 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 }
)
}
const { searchParams } = new URL(request.url);
const search = searchParams.get("search");
@@ -124,7 +115,5 @@ export async function GET(request: Request) {
},
{ status: 500 }
)
} finally {
await prisma.$disconnect()
}
}

View File

@@ -4,15 +4,7 @@ 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;
@@ -40,7 +32,5 @@ export async function GET(request: Request, { params }: { params: { name: string
},
{ status: 500 }
)
} finally {
await prisma.$disconnect();
}
}

View File

@@ -0,0 +1,79 @@
import { prisma } from "@/app/lib";
import backendLogger from "@/util/backendLogger";
import { NextResponse } from "next/server";
export async function GET(req: Request,
{ params }: { params: { id: string } }) {
console.log("Ini ID", params.id);
try {
const { id } = params;
const data = await prisma.investasi.findUnique({
where: {
id: id,
},
select: {
imageId: true,
prospektusFileId: true,
id: true,
author: {
select: {
id: true,
username: true,
nomor: true,
Profile: true,
},
},
title: true,
authorId: true,
hargaLembar: true,
targetDana: true,
totalLembar: true,
sisaLembar: true,
lembarTerbeli: true,
progress: true,
roi: true,
active: true,
createdAt: true,
updatedAt: true,
catatan: true,
imagesId: true,
MasterStatusInvestasi: true,
BeritaInvestasi: true,
DokumenInvestasi: true,
ProspektusInvestasi: true,
MasterPembagianDeviden: true,
MasterPencarianInvestor: true,
MasterPeriodeDeviden: true,
MasterProgresInvestasi: true,
masterStatusInvestasiId: true,
Investasi_Invoice: {
where: {
statusInvoiceId: "1",
},
},
countDown: true,
},
});
return NextResponse.json({
success: true,
message: "Success get detail investasi",
data: data,
},
{ status: 200 }
)
} catch (error) {
backendLogger.error("Error get detail investasi", error);
return NextResponse.json({
success: false,
message: "Error get detail investasi",
reason: (error as Error).message
},
{ status: 500 }
);
}
}

View File

@@ -6,15 +6,7 @@ import { NextResponse } from "next/server";
export async function GET(request: Request, { params }: {
params: { status: string }
}) {
const method = request.method;
if (method !== "GET") {
return NextResponse.json({
success: false,
message: "Method not allowed",
},
{ status: 405 }
)
}
const { status } = params;
try {
let fixData;
@@ -44,7 +36,5 @@ export async function GET(request: Request, { params }: {
},
{ status: 500 }
)
} finally {
await prisma.$disconnect();
}
}
}

View File

@@ -4,14 +4,7 @@ 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.job.count({
@@ -38,7 +31,5 @@ export async function GET(request: Request) {
},
{ status: 500 }
)
} finally {
await prisma.$disconnect();
}
}
}

View File

@@ -25,7 +25,5 @@ export async function GET(request: Request) {
},
{ status: 500 }
);
} finally {
await prisma.$disconnect();
}
}
}

View File

@@ -4,12 +4,7 @@ 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 data = await prisma.user.count({
where: {
@@ -35,8 +30,6 @@ export async function GET(request: Request) {
{ status: 500 }
)
} finally {
await prisma.$disconnect();
}
}

View File

@@ -6,16 +6,7 @@ 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;
@@ -45,7 +36,5 @@ export async function GET(request: Request, { params }: {
},
{ status: 500 }
)
} finally {
await prisma.$disconnect();
}
}

View File

@@ -3,15 +3,6 @@ import backendLogger from "@/util/backendLogger";
import { NextResponse } from "next/server";
export async function GET(request: Request) {
if (request.method !== "GET") {
return NextResponse.json(
{
success: false,
message: "Method not allowed",
},
{ status: 405 }
);
}
try {
let fixData;
@@ -42,7 +33,5 @@ export async function GET(request: Request) {
},
{ status: 500 }
);
} finally {
await prisma.$disconnect();
}
}
}

View File

@@ -25,18 +25,17 @@ const apiGetAdminCollaborationStatusCountDashboard = async ({
// console.log("Ini Response", await response.json());
return await response.json().catch(() => null);
}
const apiGetAdminCollaborationStatusById = async ({ status, page, search }: {
const apiGetAdminCollaborationStatusById = async ({ status, page}: {
status: "Publish" | "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/collaboration/${status}${isPage}${isSearch}`, {
const response = await fetch(`/api/admin/collaboration/${status}${isPage}`, {
headers: {
"Content-Type": "application/json",
Accept: "application/json",

View File

@@ -1,6 +1,8 @@
export {
apiGetAdminInvestasiCountDashboard,
apiGetAdminInvestasiByStatus,
apiGetAdminInvestasiById,
}
const apiGetAdminInvestasiCountDashboard = async ({ name }:
{ name: "Publish" | "Review" | "Reject" }) => {
@@ -37,6 +39,7 @@ const apiGetAdminInvestasiByStatus = async ({ status, page, search }: {
const isPage = page ? `?page=${page}` : "";
const isSearch = search ? `&search=${search}` : "";
const response = await fetch(`/api/admin/investasi/${status}${isPage}${isSearch}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
@@ -45,5 +48,24 @@ const apiGetAdminInvestasiByStatus = async ({ status, page, search }: {
},
})
return await response.json().catch(() => null);
}
const apiGetAdminInvestasiById = async ({id} : {id: string}) => {
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/investasi/detail/${id}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"Access-Control-Allow-Origin": "*",
Authorization: `Bearer ${token}`,
}
})
console.log("Ini data Response", await response.json())
return await response.json().catch(() => null);
}

View File

@@ -35,6 +35,7 @@ const middlewareConfig: MiddlewareConfig = {
// ADMIN API
// >> buat dibawah sini <<
"/api/admin/collaboration/*",
"/api/admin/investasi/*",
// Akses awal
"/api/get-cookie",