Update Versi 1.5.27 #32
32
src/app/api/forum/master/route.ts
Normal file
32
src/app/api/forum/master/route.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import prisma from "@/lib/prisma";
|
||||
import backendLogger from "@/util/backendLogger";
|
||||
|
||||
export async function GET(request: Request) {
|
||||
try {
|
||||
const data = await prisma.forumMaster_KategoriReport.findMany({
|
||||
orderBy: {
|
||||
createdAt: "asc",
|
||||
},
|
||||
where: {
|
||||
isActive: true,
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: "Berhasil mendapatkan data",
|
||||
data: data,
|
||||
});
|
||||
} catch (error) {
|
||||
backendLogger.error("Error Get Master Kategori Report >>", error);
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Gagal mendapatkan data",
|
||||
reason: (error as Error).message,
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,12 @@
|
||||
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
|
||||
import { Forum_ReportPostingLainnya } from "@/app_modules/forum";
|
||||
|
||||
export default async function Page({ params }: { params: { id: string } }) {
|
||||
let postingId = params.id;
|
||||
export default async function Page() {
|
||||
const userLoginId = await funGetUserIdByToken();
|
||||
|
||||
return (
|
||||
<>
|
||||
<Forum_ReportPostingLainnya
|
||||
postingId={postingId}
|
||||
userLoginId={userLoginId as string}
|
||||
/>
|
||||
<Forum_ReportPostingLainnya userLoginId={userLoginId as string} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,18 +1,13 @@
|
||||
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
|
||||
import { Forum_ReportPosting } from "@/app_modules/forum";
|
||||
import { forum_getMasterKategoriReport } from "@/app_modules/forum/fun/master/get_master_kategori_report";
|
||||
|
||||
export default async function Page({ params }: { params: { id: string } }) {
|
||||
let postingId = params.id;
|
||||
export default async function Page() {
|
||||
const userLoginId = await funGetUserIdByToken();
|
||||
|
||||
const listReport = await forum_getMasterKategoriReport();
|
||||
|
||||
return (
|
||||
<>
|
||||
<Forum_ReportPosting
|
||||
postingId={postingId}
|
||||
listReport={listReport as any}
|
||||
userLoginId={userLoginId as string}
|
||||
/>
|
||||
</>
|
||||
|
||||
@@ -3,6 +3,7 @@ export {
|
||||
apiGetOneForumById,
|
||||
apiGetForumkuByUserId as apiGetForumkuById,
|
||||
apiGetKomentarForumById,
|
||||
apiGetMasterReportForum,
|
||||
};
|
||||
|
||||
const apiGetAllForum = async ({
|
||||
@@ -150,3 +151,44 @@ const apiGetKomentarForumById = async ({ id , page}: { id: string , page: string
|
||||
throw error; // Re-throw the error to handle it in the calling function
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const apiGetMasterReportForum = async () => {
|
||||
try {
|
||||
// Fetch token from cookie
|
||||
const { token } = await fetch("/api/get-cookie").then((res) =>
|
||||
res.json()
|
||||
);
|
||||
if (!token) {
|
||||
console.error("No token found");
|
||||
return null;
|
||||
}
|
||||
|
||||
const response = await fetch(`/api/forum/master`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
|
||||
// Check if the response is OK
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json().catch(() => null);
|
||||
console.error(
|
||||
"Failed to get all forum:",
|
||||
response.statusText,
|
||||
errorData
|
||||
);
|
||||
throw new Error(errorData?.message || "Failed to get all forum");
|
||||
}
|
||||
|
||||
// Return the JSON response
|
||||
return await response.json();
|
||||
} catch (error) {
|
||||
console.error("Error get all forum", error);
|
||||
throw error; // Re-throw the error to handle it in the calling function
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,7 +3,6 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
|
||||
|
||||
|
||||
export async function forum_funCreateReportPosting({
|
||||
postingId,
|
||||
kategoriId,
|
||||
@@ -11,18 +10,28 @@ export async function forum_funCreateReportPosting({
|
||||
postingId: string;
|
||||
kategoriId: number;
|
||||
}) {
|
||||
try {
|
||||
const userLoginId = await funGetUserIdByToken();
|
||||
if (!userLoginId)
|
||||
return { status: 400, message: "Gagal menambahkan report posting!" };
|
||||
|
||||
const createReport = await prisma.forum_ReportPosting.create({
|
||||
data: {
|
||||
userId: userLoginId,
|
||||
forum_PostingId: postingId,
|
||||
forumMaster_KategoriReportId: kategoriId,
|
||||
},
|
||||
});
|
||||
|
||||
const createReport = await prisma.forum_ReportPosting.create({
|
||||
data: {
|
||||
userId: userLoginId,
|
||||
forum_PostingId: postingId,
|
||||
forumMaster_KategoriReportId: kategoriId,
|
||||
},
|
||||
});
|
||||
if (!createReport)
|
||||
return { status: 400, message: "Gagal menambahkan report posting!" };
|
||||
|
||||
if (!createReport)
|
||||
return { status: 400, message: "Gagal menambahkan report posting!" };
|
||||
return { status: 201, message: "Berhasil me-report posting!" };
|
||||
return { status: 201, message: "Berhasil me-report posting!" };
|
||||
} catch (error) {
|
||||
return {
|
||||
status: 400,
|
||||
message: "Error menambahkan report posting",
|
||||
error: (error as Error).message,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,20 +3,32 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
|
||||
|
||||
|
||||
export async function forum_funCreateReportPostingLainnya(
|
||||
postingId: string,
|
||||
deskripsi: string
|
||||
) {
|
||||
const userLoginId = await funGetUserIdByToken();
|
||||
const create = await prisma.forum_ReportPosting.create({
|
||||
data: {
|
||||
forum_PostingId: postingId,
|
||||
deskripsi: deskripsi,
|
||||
userId: userLoginId,
|
||||
},
|
||||
});
|
||||
try {
|
||||
const userLoginId = await funGetUserIdByToken();
|
||||
if (!userLoginId)
|
||||
return { status: 400, message: "Gagal menambah report !" };
|
||||
|
||||
if (!create) return { status: 400, message: "Gagal menambah report !" };
|
||||
return { status: 201, message: "Berhasil menambah report !" };
|
||||
const create = await prisma.forum_ReportPosting.create({
|
||||
data: {
|
||||
forum_PostingId: postingId,
|
||||
deskripsi: deskripsi,
|
||||
userId: userLoginId,
|
||||
},
|
||||
});
|
||||
|
||||
if (!create) return { status: 400, message: "Gagal menambah report !" };
|
||||
|
||||
return { status: 201, message: "Berhasil menambah report !" };
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
return {
|
||||
status: 500,
|
||||
message: "Error API",
|
||||
error: (error as Error).message,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,5 @@ import prisma from "@/lib/prisma";
|
||||
|
||||
export async function forum_getMasterKategoriReport() {
|
||||
const data = await prisma.forumMaster_KategoriReport.findMany({});
|
||||
|
||||
const changeType = JSON.stringify(data, null,2)
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -11,23 +11,43 @@ import notifikasiToAdmin_funCreate from "@/app_modules/notifikasi/fun/create/cre
|
||||
import mqtt_client from "@/util/mqtt_client";
|
||||
import { Button, Radio, Stack, Text, Title } from "@mantine/core";
|
||||
import { toNumber } from "lodash";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useParams, useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { forum_funCreateReportPosting } from "../../fun/create/fun_create_report_posting";
|
||||
import forum_getOneKategoriById from "../../fun/get/get_one_kategori_by_id";
|
||||
import { MODEL_FORUM_MASTER_REPORT } from "../../model/interface";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import { apiGetMasterReportForum } from "../../component/api_fetch_forum";
|
||||
import { clientLogger } from "@/util/clientLogger";
|
||||
import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
|
||||
|
||||
export default function Forum_ReportPosting({
|
||||
postingId,
|
||||
listReport,
|
||||
userLoginId,
|
||||
}: {
|
||||
postingId: string;
|
||||
listReport: MODEL_FORUM_MASTER_REPORT[];
|
||||
userLoginId: string;
|
||||
}) {
|
||||
const param = useParams<{ id: string }>();
|
||||
const postingId = param.id;
|
||||
const [listReport, setListReport] = useState<MODEL_FORUM_MASTER_REPORT[]>();
|
||||
const [reportValue, setReportValue] = useState("1");
|
||||
|
||||
useShallowEffect(() => {
|
||||
handleLoadMasterReport();
|
||||
}, []);
|
||||
|
||||
const handleLoadMasterReport = async () => {
|
||||
try {
|
||||
const response = await apiGetMasterReportForum();
|
||||
if (response.success) {
|
||||
setListReport(response.data);
|
||||
}
|
||||
} catch (error) {
|
||||
clientLogger.error("Error get master report", error);
|
||||
}
|
||||
};
|
||||
|
||||
if (!listReport) return <CustomSkeleton height={50} width={"100%"} />;
|
||||
|
||||
return (
|
||||
<>
|
||||
<Stack
|
||||
@@ -86,38 +106,45 @@ function ButtonAction({
|
||||
const [isLoadingLain, setIsLoadingLain] = useState(false);
|
||||
|
||||
async function onReport() {
|
||||
const report = await forum_funCreateReportPosting({
|
||||
postingId: postingId,
|
||||
kategoriId: kategoriId,
|
||||
});
|
||||
if (report.status === 201) {
|
||||
const getKategori = await forum_getOneKategoriById({
|
||||
kategoriId: toNumber(kategoriId),
|
||||
});
|
||||
// console.log(getKategori);
|
||||
|
||||
ComponentGlobal_NotifikasiBerhasil(report.message, 2000);
|
||||
router.back();
|
||||
|
||||
const dataNotif = {
|
||||
appId: postingId,
|
||||
pesan: getKategori?.deskripsi,
|
||||
kategoriApp: "FORUM",
|
||||
title: getKategori?.title,
|
||||
userId: userLoginId,
|
||||
status: "Report Posting",
|
||||
};
|
||||
|
||||
const createNotifikasi = await notifikasiToAdmin_funCreate({
|
||||
data: dataNotif as any,
|
||||
});
|
||||
|
||||
if (createNotifikasi.status === 201) {
|
||||
mqtt_client.publish("ADMIN", JSON.stringify({ count: 1 }));
|
||||
}
|
||||
try {
|
||||
setIsLoading(true);
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiGagal(report.message);
|
||||
|
||||
const report = await forum_funCreateReportPosting({
|
||||
postingId: postingId,
|
||||
kategoriId: kategoriId,
|
||||
});
|
||||
if (report.status === 201) {
|
||||
const getKategori = await forum_getOneKategoriById({
|
||||
kategoriId: toNumber(kategoriId),
|
||||
});
|
||||
// console.log(getKategori);
|
||||
|
||||
ComponentGlobal_NotifikasiBerhasil(report.message, 2000);
|
||||
router.back();
|
||||
|
||||
const dataNotif = {
|
||||
appId: postingId,
|
||||
pesan: getKategori?.deskripsi,
|
||||
kategoriApp: "FORUM",
|
||||
title: getKategori?.title,
|
||||
userId: userLoginId,
|
||||
status: "Report Posting",
|
||||
};
|
||||
|
||||
const createNotifikasi = await notifikasiToAdmin_funCreate({
|
||||
data: dataNotif as any,
|
||||
});
|
||||
|
||||
if (createNotifikasi.status === 201) {
|
||||
mqtt_client.publish("ADMIN", JSON.stringify({ count: 1 }));
|
||||
}
|
||||
} else {
|
||||
setIsLoading(false);
|
||||
ComponentGlobal_NotifikasiGagal(report.message);
|
||||
}
|
||||
} catch (error) {
|
||||
clientLogger.error("Error Report Posting", error);
|
||||
setIsLoading(false);
|
||||
}
|
||||
}
|
||||
return (
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import { RouterForum } from "@/lib/router_hipmi/router_forum";
|
||||
import { Button, Group, Stack, Textarea } from "@mantine/core";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useParams, useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { forum_funCreateReportPosting } from "../../fun/create/fun_create_report_posting";
|
||||
import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global/notifikasi_berhasil";
|
||||
@@ -10,15 +10,17 @@ import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_glo
|
||||
import { forum_funCreateReportPostingLainnya } from "../../fun/create/fun_create_report_posting_lainnya";
|
||||
import mqtt_client from "@/util/mqtt_client";
|
||||
import notifikasiToAdmin_funCreate from "@/app_modules/notifikasi/fun/create/create_notif_to_admin";
|
||||
import { clientLogger } from "@/util/clientLogger";
|
||||
|
||||
export default function Forum_ReportPostingLainnya({
|
||||
postingId,
|
||||
userLoginId,
|
||||
}: {
|
||||
postingId: string;
|
||||
userLoginId: string;
|
||||
}) {
|
||||
const param = useParams<{ id: string }>();
|
||||
const postingId = param.id;
|
||||
const [deskripsi, setDeskripsi] = useState("");
|
||||
|
||||
return (
|
||||
<>
|
||||
<Stack>
|
||||
@@ -50,50 +52,64 @@ function ButtonAction({
|
||||
userLoginId: string;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
async function onReport() {
|
||||
const report = await forum_funCreateReportPostingLainnya(
|
||||
postingId,
|
||||
deskripsi
|
||||
);
|
||||
if (report.status === 201) {
|
||||
ComponentGlobal_NotifikasiBerhasil(report.message);
|
||||
router.back();
|
||||
try {
|
||||
setIsLoading(true);
|
||||
const report = await forum_funCreateReportPostingLainnya(
|
||||
postingId,
|
||||
deskripsi
|
||||
);
|
||||
if (report.status === 201) {
|
||||
ComponentGlobal_NotifikasiBerhasil(report.message);
|
||||
router.back();
|
||||
|
||||
const dataNotif = {
|
||||
appId: postingId,
|
||||
pesan: deskripsi,
|
||||
kategoriApp: "FORUM",
|
||||
title: "Lainnya",
|
||||
userId: userLoginId,
|
||||
status: "Report Posting",
|
||||
};
|
||||
const dataNotif = {
|
||||
appId: postingId,
|
||||
pesan: deskripsi,
|
||||
kategoriApp: "FORUM",
|
||||
title: "Lainnya",
|
||||
userId: userLoginId,
|
||||
status: "Report Posting",
|
||||
};
|
||||
|
||||
const createNotifikasi = await notifikasiToAdmin_funCreate({
|
||||
data: dataNotif as any,
|
||||
});
|
||||
const createNotifikasi = await notifikasiToAdmin_funCreate({
|
||||
data: dataNotif as any,
|
||||
});
|
||||
|
||||
if (createNotifikasi.status === 201) {
|
||||
mqtt_client.publish("ADMIN", JSON.stringify({ count: 1 }));
|
||||
if (createNotifikasi.status === 201) {
|
||||
mqtt_client.publish("ADMIN", JSON.stringify({ count: 1 }));
|
||||
}
|
||||
} else {
|
||||
setIsLoading(false);
|
||||
ComponentGlobal_NotifikasiGagal(report.message);
|
||||
}
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiGagal(report.message);
|
||||
} catch (error) {
|
||||
setIsLoading(false);
|
||||
clientLogger.error("Error create report posting", error);
|
||||
}
|
||||
}
|
||||
return (
|
||||
<>
|
||||
<Group position="apart" grow>
|
||||
<Button
|
||||
style={{
|
||||
transition: "0.5s",
|
||||
}}
|
||||
disabled={isLoading}
|
||||
radius={"xl"}
|
||||
onClick={() => router.replace(RouterForum.report_posting + postingId)}
|
||||
>
|
||||
Batal
|
||||
</Button>
|
||||
<Button
|
||||
loading={isLoading}
|
||||
loaderPosition="center"
|
||||
style={{
|
||||
transition: "0.5s",
|
||||
}}
|
||||
disabled={deskripsi === "" ? true : false}
|
||||
disabled={deskripsi === ""}
|
||||
radius={"xl"}
|
||||
color="orange"
|
||||
onClick={() => onReport()}
|
||||
|
||||
@@ -13,7 +13,7 @@ export default function LayoutForum_ReportPosting({
|
||||
<>
|
||||
<UIGlobal_LayoutTamplate
|
||||
header={
|
||||
<UIGlobal_LayoutHeaderTamplate title="Mengumpulkan Informasi Posting" />
|
||||
<UIGlobal_LayoutHeaderTamplate title="Informasi Report Posting" />
|
||||
}
|
||||
>
|
||||
{children}
|
||||
|
||||
Reference in New Issue
Block a user