Delete Await Disconnect & Method API

This commit is contained in:
2025-02-11 12:14:24 +08:00
parent 2a93fa787f
commit 7c1d17079a
22 changed files with 21 additions and 226 deletions

View File

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

View File

@@ -6,15 +6,6 @@ import { NextResponse } from "next/server";
export async function GET(request: Request, { params }: { export async function GET(request: Request, { params }: {
params: { name: string } 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 { name } = params;
try { try {
let fixData; let fixData;
@@ -59,7 +50,5 @@ export async function GET(request: Request, { params }: {
}, },
{ status: 500 } { status: 500 }
) )
} finally {
await prisma.$disconnect
} }
} }

View File

@@ -7,15 +7,6 @@ import { NextResponse } from "next/server";
export async function GET(request: Request, export async function GET(request: Request,
{ params }: { params: { status: string } }) { { 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 { status } = params;
const { searchParams } = new URL(request.url); const { searchParams } = new URL(request.url);
@@ -30,7 +21,7 @@ export async function GET(request: Request,
if (!page) { if (!page) {
const data = await prisma.donasi.findMany({ fixData = await prisma.donasi.findMany({
orderBy: { orderBy: {
createdAt: "desc", createdAt: "desc",
}, },
@@ -83,7 +74,7 @@ export async function GET(request: Request,
DonasiMaster_Ketegori: true, DonasiMaster_Ketegori: true,
DonasiMaster_Durasi: true, DonasiMaster_Durasi: true,
imageId: true, imageId: true,
}, },
}) })
@@ -120,7 +111,5 @@ export async function GET(request: Request,
}, },
{ status: 500 } { status: 500 }
); );
} finally {
await prisma.$disconnect();
} }
} }

View File

@@ -7,15 +7,6 @@ import { NextResponse } from "next/server";
export async function GET(request: Request, { params }: { export async function GET(request: Request, { params }: {
params: { name: string } 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 { name } = params;
try { try {
@@ -44,7 +35,5 @@ export async function GET(request: Request, { params }: {
}, },
{ status: 500 } { status: 500 }
) )
} finally {
await prisma.$disconnect();
} }
} }

View File

@@ -4,14 +4,6 @@ import { NextResponse } from "next/server";
export async function GET(request: Request) { export async function GET(request: Request) {
const method = request.method; const method = request.method;
if (method !== "GET") {
return NextResponse.json({
success: false,
message: "Method nol allowed"
},
{ status: 405 }
)
}
try { try {
const data = await prisma.donasiMaster_Kategori.findMany({ const data = await prisma.donasiMaster_Kategori.findMany({
orderBy: { orderBy: {
@@ -38,7 +30,5 @@ export async function GET(request: Request) {
}, },
{ status: 500 } { status: 500 }
) )
} finally {
await prisma.$disconnect
} }
} }

View File

@@ -8,13 +8,7 @@ export async function GET(
request: Request, request: Request,
{ params }: { params: { status: string } } { 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 { status } = params;
const { searchParams } = new URL(request.url); const { searchParams } = new URL(request.url);
@@ -249,7 +243,5 @@ export async function GET(
}, },
{ status: 500 } { status: 500 }
); );
} finally { }
await prisma.$disconnect();
}
} }

View File

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

View File

@@ -4,14 +4,6 @@ import _ from "lodash";
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
export async function GET(request: Request) { 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 { try {
let fixData; let fixData;
fixData = await prisma.event.count({ fixData = await prisma.event.count({
@@ -41,7 +33,5 @@ export async function GET(request: Request) {
}, },
{ status: 500 } { status: 500 }
); );
} finally {
await prisma.$disconnect();
} }
} }

View File

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

View File

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

View File

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

View File

@@ -5,15 +5,6 @@ import { NextResponse } from "next/server";
import _ from 'lodash'; import _ from 'lodash';
export async function GET(request: Request) { 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 { searchParams } = new URL(request.url);
const search = searchParams.get("search"); const search = searchParams.get("search");
@@ -127,7 +118,5 @@ export async function GET(request: Request) {
reason: (error as Error).message 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, export async function GET(request: Request,
{ postingId }: { postingId: string }) { { 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 { searchParams } = new URL(request.url);
const search = searchParams.get('search'); const search = searchParams.get('search');
@@ -144,7 +134,5 @@ export async function GET(request: Request,
}, },
{ status: 500 } { status: 500 }
) )
} finally { }
await prisma.$disconnect();
}
} }

View File

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

View File

@@ -4,15 +4,7 @@ import _ from "lodash";
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
export async function GET(request: Request, { params }: { params: { name: string } }) { 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 { name } = params;
try { try {
let fixData; let fixData;
@@ -40,7 +32,5 @@ export async function GET(request: Request, { params }: { params: { name: string
}, },
{ status: 500 } { status: 500 }
) )
} finally {
await prisma.$disconnect();
} }
} }

View File

@@ -6,15 +6,7 @@ import { NextResponse } from "next/server";
export async function GET(request: Request, { params }: { export async function GET(request: Request, { params }: {
params: { status: string } 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 { status } = params;
try { try {
let fixData; let fixData;
@@ -44,7 +36,5 @@ export async function GET(request: Request, { params }: {
}, },
{ status: 500 } { status: 500 }
) )
} finally { }
await prisma.$disconnect();
}
} }

View File

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

View File

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

View File

@@ -4,12 +4,7 @@ import { NextResponse } from "next/server";
export async function GET(request: Request) { export async function GET(request: Request) {
const method = request.method; const method = request.method;
if (method !== "GET") {
return NextResponse.json(
{ success: false, message: "Method not allowed" },
{ status: 405 }
);
}
try { try {
const data = await prisma.user.count({ const data = await prisma.user.count({
where: { where: {
@@ -35,8 +30,6 @@ export async function GET(request: Request) {
{ status: 500 } { status: 500 }
) )
} finally {
await prisma.$disconnect();
} }
} }

View File

@@ -6,16 +6,7 @@ import { NextResponse } from "next/server";
export async function GET(request: Request, { params }: { export async function GET(request: Request, { params }: {
params: { name: string } 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 { name } = params;
try { try {
let fixData; let fixData;
@@ -45,7 +36,5 @@ export async function GET(request: Request, { params }: {
}, },
{ status: 500 } { status: 500 }
) )
} finally {
await prisma.$disconnect();
} }
} }

View File

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

View File

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