Merge pull request #298 from bipproduction/join

fix version
This commit is contained in:
Bagasbanuna02
2025-02-11 11:01:04 +08:00
committed by GitHub
9 changed files with 487 additions and 128 deletions

View File

@@ -0,0 +1,156 @@
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: { status: string } }
) {
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;
try {
let fixData;
const fixStatus = _.startCase(status);
if (!page) {
fixData = await prisma.projectCollaboration.findMany({
skip: skipData,
take: takeData,
orderBy: {
createdAt: "desc",
},
where: {
isActive: true,
isReject: false,
Author: {
active: true,
},
title: {
contains: search ? search : "",
mode: "insensitive",
},
},
select: {
id: true,
createdAt: true,
isActive: true,
title: true,
Author: {
select: {
id: true,
username: true,
Profile: true,
},
},
projectCollaborationMaster_IndustriId: true,
ProjectCollaborationMaster_Industri: true,
ProjectCollaboration_Partisipasi: {
where: {
User: {
active: true,
},
},
// select: {
// User: {
// select: {
// id: true,
// username: true,
// Profile: true,
// },
// },
// },
},
},
});
} else {
const data = await prisma.projectCollaboration.findMany({
skip: skipData,
take: takeData,
orderBy: {
createdAt: "desc",
},
where: {
isActive: true,
isReject: false,
Author: {
active: true,
},
title: {
contains: search ? search : "",
mode: "insensitive",
},
},
select: {
id: true,
createdAt: true,
isActive: true,
title: true,
Author: {
select: {
id: true,
username: true,
Profile: true,
},
},
projectCollaborationMaster_IndustriId: true,
ProjectCollaborationMaster_Industri: true,
ProjectCollaboration_Partisipasi: {
where: {
User: {
active: true,
},
},
// select: {
// User: {
// select: {
// id: true,
// username: true,
// Profile: true,
// },
// },
// },
},
},
});
const nCount = await prisma.projectCollaboration.count({
where: {
isActive: true,
isReject: false,
Author: {
active: true,
},
},
});
fixData = {
data: data,
nPage: _.ceil(nCount / takeData),
}
}
return NextResponse.json({
success: true,
message: "Success get data collaboration dashboard",
data: fixData,
},
{ status: 200 }
);
} catch (error) {
backendLogger.error("Error get data collaboration dashboard >>", error);
return NextResponse.json({
success: false,
message: "Error get data collaboration dashboard",
reason: (error as Error).message
},
{ status: 500 }
)
}
}

View File

@@ -0,0 +1,139 @@
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 { 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;
if (!page) {
fixData = await prisma.projectCollaboration_RoomChat.findMany({
orderBy: {
createdAt: "desc",
},
where: {
isActive: true,
},
select: {
id: true,
createdAt: true,
isActive: true,
name: true,
ProjectCollaboration_AnggotaRoomChat: {
select: {
User: {
select: {
id: true,
Profile: true,
},
},
},
},
ProjectCollaboration: {
select: {
id: true,
isActive: true,
title: true,
lokasi: true,
purpose: true,
benefit: true,
createdAt: true,
report: true,
Author: {
select: {
id: true,
Profile: {
select: {
name: true,
},
},
},
},
ProjectCollaborationMaster_Industri: true,
},
},
},
});
} else {
const data = await prisma.projectCollaboration_RoomChat.findMany({
take: takeData,
skip: skipData,
orderBy: {
createdAt: "desc",
},
where: {
isActive: true,
},
select: {
id: true,
createdAt: true,
isActive: true,
name: true,
ProjectCollaboration_AnggotaRoomChat: {
select: {
User: {
select: {
id: true,
Profile: true,
},
},
},
},
ProjectCollaboration: {
select: {
id: true,
isActive: true,
title: true,
lokasi: true,
purpose: true,
benefit: true,
createdAt: true,
report: true,
Author: {
select: {
id: true,
Profile: {
select: {
name: true,
},
},
},
},
ProjectCollaborationMaster_Industri: true,
},
},
},
});
const nCount = await prisma.projectCollaboration_RoomChat.count({
where: {
isActive: true,
},
})
fixData = {
data: data,
nPage: _.ceil(nCount / takeData)
}
}
} catch (error) {
backendLogger.error("Error get data collaboration group >>", error);
return NextResponse.json({
success: false,
message: "Error get data collaboration group",
reason: (error as Error).message
},
{ status: 500 }
)
}
}

View File

@@ -30,7 +30,7 @@ export async function GET(request: Request, { params }: {
if (!page) {
const data = await prisma.investasi.findMany({
fixData = await prisma.investasi.findMany({
orderBy: {
updatedAt: "desc",
},
@@ -62,6 +62,8 @@ export async function GET(request: Request, { params }: {
});
} else {
const data = await prisma.investasi.findMany({
take: takeData,
skip: skipData,
orderBy: {
updatedAt: "desc",
},

View File

@@ -2,11 +2,11 @@ import { AdminForum_TableReportPosting } from "@/app_modules/admin/forum";
import adminForum_funGetAllReportPosting from "@/app_modules/admin/forum/fun/get/get_all_report_posting";
export default async function Page() {
const listData = await adminForum_funGetAllReportPosting({ page: 1 });
return (
<>
<AdminForum_TableReportPosting listData={listData} />
<AdminForum_TableReportPosting />
</>
);
}

View File

@@ -1,5 +1,7 @@
export {
apiGetAdminCollaborationStatusCountDashboard,
apiGetAdminCollaborationStatusById,
apiGetAdminCollaborationRoomById
}
const apiGetAdminCollaborationStatusCountDashboard = async ({
@@ -23,3 +25,47 @@ const apiGetAdminCollaborationStatusCountDashboard = async ({
// console.log("Ini Response", await response.json());
return await response.json().catch(() => null);
}
const apiGetAdminCollaborationStatusById = async ({ status, page, search }: {
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}`, {
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"Access-Control-Allow-Origin": "*",
Authorization: `Bearer ${token}`,
}
})
return await response.json().catch(() => null);
}
const apiGetAdminCollaborationRoomById = 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/collaboration/group${isPage}${isSearch}`, {
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"Access-Control-Allow-Origin": "*",
Authorization: `Bearer ${token}`,
}
})
return await response.json().catch(() => null);
}

View File

@@ -58,11 +58,12 @@ const apiGetAdminCountForumReportKomentar = async () => {
return await response.json().catch(() => null);
}
const apiGetAdminForumReportPosting = async () => {
const apiGetAdminForumReportPosting = async ({page} : { page?: 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/forum/posting`, {
const isPage = page ? `?page=${page}` : "";
const response = await fetch(`/api/admin/forum/posting${isPage}`, {
method: "GET",
headers: {
"Content-Type": "application/json",

View File

@@ -84,7 +84,7 @@ function TablePublish() {
page: `${activePage}`
});
setData(loadData.data.data);
setNPage(loadData.data.nPage);
setNPage(loadData.data.nCount);
}
const onPageClick = (page: number) => {

View File

@@ -30,139 +30,153 @@ import ComponentAdminForum_ButtonDeletePosting from "../component/button_delete"
import adminForum_funGetAllReportPosting from "../fun/get/get_all_report_posting";
import { ComponentAdminGlobal_TitlePage } from "../../_admin_global/_component";
import { AdminColor } from "@/app_modules/_global/color/color_pallet";
import { useShallowEffect } from "@mantine/hooks";
import { apiGetAdminForumReportPosting } from "../lib/api_fetch_admin_forum";
import { clientLogger } from "@/util/clientLogger";
import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
export default function AdminForum_TableReportPosting({
listData,
}: {
listData: any;
}) {
export default function AdminForum_TableReportPosting() {
return (
<>
<Stack>
<ComponentAdminGlobal_HeaderTamplate name="Forum" />
<TableView listData={listData} />
<TableView />
{/* <pre>{JSON.stringify(listPublish, null, 2)}</pre> */}
</Stack>
</>
);
}
function TableView({ listData }: { listData: any }) {
function TableView() {
const router = useRouter();
const [data, setData] = useState<MODEL_FORUM_REPORT_POSTING[]>(listData.data);
const [nPage, setNPage] = useState(listData.nPage);
const [data, setData] = useState<MODEL_FORUM_REPORT_POSTING[] | null>(null);
const [nPage, setNPage] = useState<number>(1);
const [activePage, setActivePage] = useState(1);
const [isSearch, setSearch] = useState("");
async function onSearch(s: string) {
setSearch(s);
useShallowEffect(() => {
const loadInitialData = async () => {
try {
const response = await apiGetAdminForumReportPosting({
page: `${activePage}`
})
if (response?.success && response?.data) {
setData(response.data);
setNPage(response.data.nCount || 1)
} else {
console.error("Invalid data format recieved", response),
setData([])
}
} catch (error) {
clientLogger.error("Invalid data format recieved", error)
setData([])
}
}
loadInitialData();
}, [activePage, isSearch]);
async function onSearch(searchTerm: string) {
setSearch(searchTerm);
setActivePage(1);
const loadData = await adminForum_funGetAllReportPosting({
page: 1,
search: s,
});
setData(loadData.data as any);
setNPage(loadData.nPage);
}
async function onPageClick(p: any) {
setActivePage(p);
const loadData = await adminForum_funGetAllReportPosting({
search: isSearch,
page: p,
});
setData(loadData.data as any);
setNPage(loadData.nPage);
const onPageClick = (page: number) => {
setActivePage(page);
}
async function onLoadData() {
const loadData = await adminForum_funGetAllReportPosting({
page: 1,
});
setData(loadData.data as any);
setNPage(loadData.nPage);
}
const TableRows = data?.map((e, i) => (
<tr key={i}>
<td>
<Center c={AdminColor.white} w={200}>
<Text lineClamp={1}>{e?.User.username}</Text>
</Center>
</td>
<td>
<Center c={AdminColor.white} w={200}>
{e?.forumMaster_KategoriReportId === null ? (
<Text>Lainnya</Text>
) : (
<Text lineClamp={1}>{e?.ForumMaster_KategoriReport.title}</Text>
)}
</Center>
</td>
{/* <td>
<Center w={200}>
<Text lineClamp={1}>{e?.Forum_Posting.Author.username}</Text>
</Center>
</td>
<td>
<Box w={400}>
<Spoiler
// w={400}
maxHeight={60}
hideLabel="sembunyikan"
showLabel="tampilkan"
>
<div
dangerouslySetInnerHTML={{
__html: e?.Forum_Posting.diskusi,
}}
/>
</Spoiler>
</Box>
</td> */}
<td>
<Center w={200}>
<Badge
color={
(e?.Forum_Posting.ForumMaster_StatusPosting?.id as any) === 1
? "green"
: "red"
}
>
{e?.Forum_Posting.ForumMaster_StatusPosting?.status}
</Badge>
</Center>
</td>
<td>
<Center w={150}>
<Text c={AdminColor.white}>
{new Intl.DateTimeFormat(["id-ID"], { dateStyle: "medium" }).format(
e.createdAt
const renderTableBody = () => {
if (!Array.isArray(data) || data.length === 0) {
return (
<tr>
<td colSpan={12}>
<Center>
<Text color={"gray"}>Tidak ada data</Text>
</Center>
</td>
</tr>
)
}
return data?.map((e, i) => (
<tr key={i}>
<td>
<Center c={AdminColor.white} w={200}>
<Text lineClamp={1}>{e?.User.username}</Text>
</Center>
</td>
<td>
<Center c={AdminColor.white} w={200}>
{e?.forumMaster_KategoriReportId === null ? (
<Text>Lainnya</Text>
) : (
<Text lineClamp={1}>{e?.ForumMaster_KategoriReport.title}</Text>
)}
</Text>
</Center>
</td>
<td>
<Stack align="center" spacing={"xs"}>
{/* <ButtonAction postingId={e?.id} /> */}
<ButtonLihatReportLainnya postingId={e?.forum_PostingId} />
{/* <ComponentAdminForum_ButtonDeletePosting
postingId={e?.forum_PostingId}
onSuccesDelete={(val) => {
if (val) {
onLoadData();
</Center>
</td>
{/* <td>
<Center w={200}>
<Text lineClamp={1}>{e?.Forum_Posting.Author.username}</Text>
</Center>
</td>
<td>
<Box w={400}>
<Spoiler
// w={400}
maxHeight={60}
hideLabel="sembunyikan"
showLabel="tampilkan"
>
<div
dangerouslySetInnerHTML={{
__html: e?.Forum_Posting.diskusi,
}}
/>
</Spoiler>
</Box>
</td> */}
<td>
<Center w={200}>
<Badge
color={
(e?.Forum_Posting?.ForumMaster_StatusPosting?.id as any) === 1
? "green"
: "red"
}
}}
/> */}
</Stack>
</td>
</tr>
));
>
{e?.Forum_Posting?.ForumMaster_StatusPosting?.status}
</Badge>
</Center>
</td>
<td>
<Center w={150}>
<Text c={AdminColor.white}>
{new Intl.DateTimeFormat("id-ID", { dateStyle: "medium" }).format(
new Date(e?.createdAt)
)}
</Text>
</Center>
</td>
<td>
<Stack align="center" spacing={"xs"}>
{/* <ButtonAction postingId={e?.id} /> */}
<ButtonLihatReportLainnya postingId={e?.forum_PostingId} />
{/* <ComponentAdminForum_ButtonDeletePosting
postingId={e?.forum_PostingId}
onSuccesDelete={(val) => {
if (val) {
onLoadData();
}
}}
/> */}
</Stack>
</td>
</tr>
));
}
return (
<>
@@ -172,14 +186,14 @@ function TableView({ listData }: { listData: any }) {
color={AdminColor.softBlue}
component={
<TextInput
icon={<IconSearch size={20} />}
radius={"xl"}
placeholder="Cari postingan"
onChange={(val) => {
icon={<IconSearch size={20} />}
radius={"xl"}
placeholder="Cari postingan"
onChange={(val) => {
onSearch(val.currentTarget.value);
}}
/>
onSearch(val.currentTarget.value);
}}
/>
}
/>
{/* <Group
@@ -202,8 +216,8 @@ function TableView({ listData }: { listData: any }) {
/>
</Group> */}
{isEmpty(data) ? (
<ComponentAdminGlobal_IsEmptyData />
{!data ? (
<CustomSkeleton height={"80vh"} width={"100%"} />
) : (
<Paper p={"md"} bg={AdminColor.softBlue} h={"80vh"}>
<ScrollArea w={"100%"} h={"90%"} offsetScrollbars>
@@ -213,7 +227,7 @@ function TableView({ listData }: { listData: any }) {
p={"md"}
w={"100%"}
h={"100%"}
>
<thead>
<tr>
@@ -241,7 +255,7 @@ function TableView({ listData }: { listData: any }) {
</th>
</tr>
</thead>
<tbody>{TableRows}</tbody>
<tbody>{renderTableBody()}</tbody>
</Table>
</ScrollArea>
<Center mt={"xl"}>

View File

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