Fix API Detail Publish Event

This commit is contained in:
2025-02-12 17:31:02 +08:00
parent dbeab7aa22
commit ddefccb07f
22 changed files with 349 additions and 100 deletions

View File

@@ -0,0 +1,50 @@
import backendLogger from "@/util/backendLogger";
import { NextResponse } from "next/server";
export async function GET(req: Request,
{ params }: { params: { id: string } }) {
try {
const { id } = params;
const data = await prisma.event.findUnique({
where: {
id: id
},
include: {
Author: {
select: {
username: true,
nomor: true,
Profile: {
select: {
name: true,
alamat: true
}
}
}
},
EventMaster_TipeAcara: {
select: {
name: true
}
}
}
})
return NextResponse.json({
success: true,
message: "Success get data event detail",
data: data,
},
{ status: 200 }
)
} catch (error) {
backendLogger.error("Error get data event detail >>", error);
return NextResponse.json({
success: false,
message: "Error get data event detail",
reason: (error as Error).message
},
{ status: 500 }
)
}
}

View File

@@ -1,19 +0,0 @@
import backendLogger from "@/util/backendLogger";
import { NextResponse } from "next/server";
export async function GET(req: Request,
{ params }: { params: { id: string } }) {
try {
} catch (error) {
backendLogger.error("Error get data event detail >>", error);
return NextResponse.json({
success: false,
message: "Error get data event detail",
reason: (error as Error).message
},
{ status: 500 }
)
}
}

View File

@@ -6,11 +6,11 @@ import { NextResponse } from "next/server";
export async function GET(
request: Request,
{ params }: { params: { status: string } }
{ params }: { params: { name: string } }
) {
const { status } = params;
const { name } = params;
const { searchParams } = new URL(request.url);
const search = searchParams.get("search");
const page = searchParams.get("page");
@@ -19,7 +19,7 @@ export async function GET(
try {
let fixData;
const fixStatus = _.startCase(status);
const fixStatus = _.startCase(name);
if (!page && !search) {
fixData = await prisma.event.findMany({
@@ -230,9 +230,11 @@ export async function GET(
return NextResponse.json({
success: true,
message: `Success get data table event ${status}`,
message: `Success get data table event ${name}`,
data: fixData,
});
},
{ status: 200 }
);
} catch (error) {
backendLogger.error("Error get data table event dashboard >>", error);
return NextResponse.json(
@@ -243,5 +245,5 @@ export async function GET(
},
{ status: 500 }
);
}
}
}

View File

@@ -0,0 +1,115 @@
import { prisma } from "@/lib";
import backendLogger from "@/util/backendLogger";
import _ from "lodash";
import { NextResponse } from "next/server";
export async function GET(request: Request,
{ params }: { params: { id: string } }) {
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 { id } = params;
const postingId = id
if (!page) {
fixData = await prisma.forum_ReportPosting.findMany({
orderBy: {
createdAt: "desc",
},
where: {
forum_PostingId: postingId,
},
select: {
id: true,
deskripsi: true,
createdAt: true,
User: {
select: {
id: true,
username: true,
Profile: {
select: {
name: true,
},
},
},
},
ForumMaster_KategoriReport: {
select: {
id: true,
title: true,
deskripsi: true,
},
},
},
});
} else {
const data = await prisma.forum_ReportPosting.findMany({
take: takeData,
skip: skipData,
orderBy: {
createdAt: "desc",
},
where: {
forum_PostingId: postingId,
},
select: {
id: true,
deskripsi: true,
createdAt: true,
User: {
select: {
id: true,
username: true,
Profile: {
select: {
name: true,
},
},
},
},
ForumMaster_KategoriReport: {
select: {
id: true,
title: true,
deskripsi: true,
},
},
},
});
const nCount = await prisma.forum_ReportPosting.count({
where: {
isActive: true,
}
})
fixData = {
data: data,
nCount: _.ceil(nCount / takeData)
}
}
return NextResponse.json({
success: true,
message: "Success get data forum posting",
data: fixData
},
{ status: 200 }
)
} catch (error) {
backendLogger.error("Error get data forum posting >>", error);
return NextResponse.json({
success: false,
message: "Error get data forum posting",
},
{ status: 500 }
)
}
}

View File

@@ -3,8 +3,7 @@ import backendLogger from "@/util/backendLogger";
import _ from "lodash";
import { NextResponse } from "next/server";
export async function GET(request: Request,
{ postingId }: { postingId: string }) {
export async function GET(request: Request) {
const { searchParams } = new URL(request.url);
const search = searchParams.get('search');
@@ -22,7 +21,13 @@ export async function GET(request: Request,
createdAt: "desc",
},
where: {
forum_PostingId: postingId,
Forum_Posting: {
isActive: true,
diskusi: {
contains: search ? search : '',
mode: "insensitive"
}
},
},
select: {
id: true,

View File

@@ -1,134 +0,0 @@
export {
apiGetAdminEventStatusCountDashboard as apiGetEventStatusCountDashboard,
apiGetAdminEventCountTipeAcara as apiGetEventTipeAcara,
apiGetAdminEventRiwayatCount as apiGetEventRiwayatCount,
apiGetAdminEventByStatus as apiGetDataEventByStatus,
apiGetAdminEventRiwayat,
apiGetAdminEventTipeAcara,
};
const apiGetAdminEventStatusCountDashboard = 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 apiGetAdminEventRiwayatCount = 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 apiGetAdminEventCountTipeAcara = 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);
};
const apiGetAdminEventByStatus = async ({
status,
page,
search,
}: {
status: "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 respone = await fetch(
`/api/admin/event/${status}${isPage}${isSearch}`,
{
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"Access-Control-Allow-Origin": "*",
Authorization: `Bearer ${token}`,
},
}
);
return await respone.json().catch(() => null);
};
const apiGetAdminEventRiwayat = async ({
page,
search,
}: {
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/event/riwayat${isPage}${isSearch}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"Access-Control-Allow-Origin": "*",
Authorization: `Bearer ${token}`,
},
});
return await response.json().catch(() => null);
};
const apiGetAdminEventTipeAcara = 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/event/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);
};