fix forum
deskripsi: - fix api forumku
This commit is contained in:
10
.gitignore
vendored
10
.gitignore
vendored
@@ -38,11 +38,11 @@ yarn-error.log*
|
||||
|
||||
# logs
|
||||
logs/
|
||||
**/logs/
|
||||
*.log
|
||||
**/*.log
|
||||
log/
|
||||
**/log/
|
||||
# **/logs/
|
||||
# *.log
|
||||
# **/*.log
|
||||
# log/
|
||||
# **/log/
|
||||
|
||||
# typescript
|
||||
*.tsbuildinfo
|
||||
|
||||
@@ -11,9 +11,6 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||
const takeData = 5;
|
||||
const skipData = Number(page) * takeData - takeData;
|
||||
|
||||
console.log("id", id)
|
||||
console.log("page >", page)
|
||||
|
||||
if (!page) {
|
||||
fixData = await prisma.forum_Posting.findMany({
|
||||
orderBy: {
|
||||
|
||||
@@ -1,42 +1,12 @@
|
||||
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
|
||||
import { Forum_Forumku } from "@/app_modules/forum";
|
||||
import { forum_countPostingByAuthorId } from "@/app_modules/forum/fun/count/count_posting_by_author_id";
|
||||
import { forum_getAllPostingByAuhtorId } from "@/app_modules/forum/fun/get/get_list_posting_by_author_id";
|
||||
import { user_getOneByUserId } from "@/app_modules/home/fun/get/get_one_user_by_id";
|
||||
import _ from "lodash";
|
||||
|
||||
export default async function Page({ params }: { params: { id: string } }) {
|
||||
const authorId = params.id;
|
||||
export default async function Page() {
|
||||
const userLoginId = await funGetUserIdByToken();
|
||||
|
||||
const dataAuthor = await user_getOneByUserId(authorId);
|
||||
const auhtorSelectedData = _.omit(dataAuthor, [
|
||||
"Profile.email",
|
||||
"Profile.alamat",
|
||||
"Profile.jenisKelamin",
|
||||
"Profile.createdAt",
|
||||
"Profile.updatedAt",
|
||||
"Profile.imagesBackgroundId",
|
||||
]);
|
||||
// console.log(dataAuthor)
|
||||
// console.log(auhtorSelectedData)
|
||||
|
||||
// await new Promise((a, b) => {
|
||||
// setTimeout(a, 1000);
|
||||
// });
|
||||
|
||||
const dataPosting = await forum_getAllPostingByAuhtorId({
|
||||
authorId: authorId,
|
||||
page: 1,
|
||||
});
|
||||
const totalPosting = await forum_countPostingByAuthorId(authorId);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Forum_Forumku
|
||||
totalPosting={totalPosting}
|
||||
userLoginId={userLoginId as any}
|
||||
/>
|
||||
<Forum_Forumku userLoginId={userLoginId as any} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
"use client";
|
||||
|
||||
import { RouterForum } from "@/lib/router_hipmi/router_forum";
|
||||
import { RouterProfile } from "@/lib/router_hipmi/router_katalog";
|
||||
import { ComponentGlobal_LoaderAvatar } from "@/app_modules/_global/component";
|
||||
import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global/notifikasi_peringatan";
|
||||
import { Avatar, Badge, Grid, Group, Loader, Stack, Text } from "@mantine/core";
|
||||
import { RouterForum } from "@/lib/router_hipmi/router_forum";
|
||||
import { Badge, Grid, Group, Stack, Text } from "@mantine/core";
|
||||
import { IconCircle } from "@tabler/icons-react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { MODEL_FORUM_POSTING } from "../../model/interface";
|
||||
import ComponentForum_ForumkuMoreButton from "./forumku_more_button";
|
||||
import ComponentGlobal_Loader from "@/app_modules/_global/component/loader";
|
||||
import { ComponentGlobal_LoaderAvatar } from "@/app_modules/_global/component";
|
||||
|
||||
export default function ComponentForum_ForumkuHeaderCard({
|
||||
data,
|
||||
@@ -52,7 +49,7 @@ export default function ComponentForum_ForumkuHeaderCard({
|
||||
<Grid.Col span={"auto"}>
|
||||
<Text lineClamp={1} fz={"sm"} fw={"bold"} c={"white"}>
|
||||
{data.Author.username
|
||||
? data.Author.username
|
||||
? data.Author.Profile.name
|
||||
: "Nama author "}
|
||||
</Text>
|
||||
</Grid.Col>
|
||||
@@ -68,9 +65,7 @@ export default function ComponentForum_ForumkuHeaderCard({
|
||||
: "red"
|
||||
}
|
||||
>
|
||||
<Text c={"white"} fz={10}>
|
||||
{data?.ForumMaster_StatusPosting.status}
|
||||
</Text>
|
||||
<Text fz={10}>{data?.ForumMaster_StatusPosting.status}</Text>
|
||||
</Badge>
|
||||
</Stack>
|
||||
</Grid.Col>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { RouterForum } from "@/lib/router_hipmi/router_forum";
|
||||
import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global/notifikasi_berhasil";
|
||||
import { RouterForum } from "@/lib/router_hipmi/router_forum";
|
||||
import {
|
||||
ActionIcon,
|
||||
Button,
|
||||
@@ -26,16 +26,17 @@ import {
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
|
||||
import {
|
||||
AccentColor,
|
||||
MainColor,
|
||||
} from "@/app_modules/_global/color/color_pallet";
|
||||
import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_global/notifikasi_gagal";
|
||||
import { clientLogger } from "@/util/clientLogger";
|
||||
import mqtt_client from "@/util/mqtt_client";
|
||||
import _ from "lodash";
|
||||
import { forum_funDeletePostingById } from "../../fun/delete/fun_delete_posting_by_id";
|
||||
import { forum_funEditStatusPostingById } from "../../fun/edit/fun_edit_status_posting_by_id";
|
||||
import { MODEL_FORUM_POSTING } from "../../model/interface";
|
||||
import {
|
||||
AccentColor,
|
||||
MainColor,
|
||||
} from "@/app_modules/_global/color/color_pallet";
|
||||
|
||||
export default function ComponentForum_ForumkuMoreButton({
|
||||
authorId,
|
||||
@@ -254,11 +255,12 @@ function ButtonDelete({
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
async function onDelete() {
|
||||
setOpenDel(false);
|
||||
await forum_funDeletePostingById(postingId as any).then(async (res) => {
|
||||
if (res.status === 200) {
|
||||
ComponentGlobal_NotifikasiBerhasil(`Postingan Terhapus`, 2000);
|
||||
setLoading(true);
|
||||
try {
|
||||
setLoading(true);
|
||||
|
||||
const deleteData = await forum_funDeletePostingById(postingId as any);
|
||||
if (deleteData.status === 200) {
|
||||
setOpenDel(false);
|
||||
|
||||
const cloneData = _.clone(allData);
|
||||
const hapusData = cloneData.filter((e) => e.id !== postingId);
|
||||
@@ -271,10 +273,16 @@ function ButtonDelete({
|
||||
data: hapusData,
|
||||
})
|
||||
);
|
||||
|
||||
ComponentGlobal_NotifikasiBerhasil(`Postingan Terhapus`, 2000);
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiGagal(res.message);
|
||||
setLoading(false);
|
||||
ComponentGlobal_NotifikasiGagal(deleteData.message);
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
setLoading(false);
|
||||
clientLogger.error("Error get data forum", error);
|
||||
}
|
||||
}
|
||||
return (
|
||||
<>
|
||||
@@ -323,120 +331,131 @@ function ButtonStatus({
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
async function onTutupForum() {
|
||||
setOpenStatus(false);
|
||||
|
||||
const upateStatusClose = await forum_funEditStatusPostingById(
|
||||
postingId as any,
|
||||
2
|
||||
);
|
||||
if (upateStatusClose.status === 200) {
|
||||
ComponentGlobal_NotifikasiBerhasil(`Forum Ditutup`, 2000);
|
||||
try {
|
||||
setLoading(true);
|
||||
|
||||
const cloneData = _.clone(allData);
|
||||
const loadData = cloneData.map(
|
||||
(e) => (
|
||||
e.id === postingId,
|
||||
{
|
||||
...e,
|
||||
ForumMaster_StatusPosting: {
|
||||
id: e.id === postingId ? 2 : e.ForumMaster_StatusPosting.id,
|
||||
status:
|
||||
e.id === postingId
|
||||
? "Close"
|
||||
: e.ForumMaster_StatusPosting.status,
|
||||
},
|
||||
}
|
||||
)
|
||||
);
|
||||
onLoadData(loadData);
|
||||
|
||||
//
|
||||
mqtt_client.publish(
|
||||
"Forum_ganti_status",
|
||||
JSON.stringify({
|
||||
id: postingId,
|
||||
data: loadData,
|
||||
})
|
||||
const upateStatusClose = await forum_funEditStatusPostingById(
|
||||
postingId as any,
|
||||
2
|
||||
);
|
||||
|
||||
const findData = cloneData.find((val) => val.id === postingId);
|
||||
const updateDetail = {
|
||||
...findData,
|
||||
ForumMaster_StatusPosting: {
|
||||
id: 2,
|
||||
status: "Close",
|
||||
},
|
||||
};
|
||||
if (upateStatusClose.status === 200) {
|
||||
setOpenStatus(false);
|
||||
ComponentGlobal_NotifikasiBerhasil(`Forum Ditutup`, 2000);
|
||||
|
||||
mqtt_client.publish(
|
||||
"Forum_detail_ganti_status",
|
||||
JSON.stringify({
|
||||
id: postingId,
|
||||
data: updateDetail.ForumMaster_StatusPosting,
|
||||
})
|
||||
);
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiGagal(upateStatusClose.message);
|
||||
const cloneData = _.clone(allData);
|
||||
const loadData = cloneData.map(
|
||||
(e) => (
|
||||
e.id === postingId,
|
||||
{
|
||||
...e,
|
||||
ForumMaster_StatusPosting: {
|
||||
id: e.id === postingId ? 2 : e.ForumMaster_StatusPosting.id,
|
||||
status:
|
||||
e.id === postingId
|
||||
? "Close"
|
||||
: e.ForumMaster_StatusPosting.status,
|
||||
},
|
||||
}
|
||||
)
|
||||
);
|
||||
onLoadData(loadData);
|
||||
|
||||
mqtt_client.publish(
|
||||
"Forum_ganti_status",
|
||||
JSON.stringify({
|
||||
id: postingId,
|
||||
data: loadData,
|
||||
})
|
||||
);
|
||||
|
||||
const findData = cloneData.find((val) => val.id === postingId);
|
||||
const updateDetail = {
|
||||
...findData,
|
||||
ForumMaster_StatusPosting: {
|
||||
id: 2,
|
||||
status: "Close",
|
||||
},
|
||||
};
|
||||
|
||||
mqtt_client.publish(
|
||||
"Forum_detail_ganti_status",
|
||||
JSON.stringify({
|
||||
id: postingId,
|
||||
data: updateDetail.ForumMaster_StatusPosting,
|
||||
})
|
||||
);
|
||||
} else {
|
||||
setLoading(false);
|
||||
ComponentGlobal_NotifikasiGagal(upateStatusClose.message);
|
||||
}
|
||||
} catch (error) {
|
||||
setLoading(false);
|
||||
clientLogger.error("Error get data forum", error);
|
||||
}
|
||||
}
|
||||
|
||||
async function onBukaForum() {
|
||||
setOpenStatus(false);
|
||||
|
||||
const updateStatusOpen = await forum_funEditStatusPostingById(
|
||||
postingId as any,
|
||||
1
|
||||
);
|
||||
if (updateStatusOpen.status === 200) {
|
||||
ComponentGlobal_NotifikasiBerhasil(`Forum Dibuka`, 2000);
|
||||
try {
|
||||
setLoading(true);
|
||||
|
||||
const cloneData = _.clone(allData);
|
||||
const loadData = cloneData.map(
|
||||
(e) => (
|
||||
e.id === postingId,
|
||||
{
|
||||
...e,
|
||||
ForumMaster_StatusPosting: {
|
||||
id: e.id === postingId ? 1 : e.ForumMaster_StatusPosting.id,
|
||||
status:
|
||||
e.id === postingId
|
||||
? "Open"
|
||||
: e.ForumMaster_StatusPosting.status,
|
||||
},
|
||||
}
|
||||
)
|
||||
const updateStatusOpen = await forum_funEditStatusPostingById(
|
||||
postingId as any,
|
||||
1
|
||||
);
|
||||
|
||||
mqtt_client.publish(
|
||||
"Forum_ganti_status",
|
||||
JSON.stringify({
|
||||
id: postingId,
|
||||
data: loadData,
|
||||
})
|
||||
);
|
||||
if (updateStatusOpen.status === 200) {
|
||||
setOpenStatus(false);
|
||||
ComponentGlobal_NotifikasiBerhasil(`Forum Dibuka`, 2000);
|
||||
|
||||
onLoadData(loadData);
|
||||
const cloneData = _.clone(allData);
|
||||
const loadData = cloneData.map(
|
||||
(e) => (
|
||||
e.id === postingId,
|
||||
{
|
||||
...e,
|
||||
ForumMaster_StatusPosting: {
|
||||
id: e.id === postingId ? 1 : e.ForumMaster_StatusPosting.id,
|
||||
status:
|
||||
e.id === postingId
|
||||
? "Open"
|
||||
: e.ForumMaster_StatusPosting.status,
|
||||
},
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
const findData = cloneData.find((val) => val.id === postingId);
|
||||
const updateDetail = {
|
||||
...findData,
|
||||
ForumMaster_StatusPosting: {
|
||||
id: 1,
|
||||
status: "Open",
|
||||
},
|
||||
};
|
||||
mqtt_client.publish(
|
||||
"Forum_ganti_status",
|
||||
JSON.stringify({
|
||||
id: postingId,
|
||||
data: loadData,
|
||||
})
|
||||
);
|
||||
|
||||
mqtt_client.publish(
|
||||
"Forum_detail_ganti_status",
|
||||
JSON.stringify({
|
||||
id: postingId,
|
||||
data: updateDetail.ForumMaster_StatusPosting,
|
||||
})
|
||||
);
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiGagal(updateStatusOpen.message);
|
||||
onLoadData(loadData);
|
||||
|
||||
const findData = cloneData.find((val) => val.id === postingId);
|
||||
const updateDetail = {
|
||||
...findData,
|
||||
ForumMaster_StatusPosting: {
|
||||
id: 1,
|
||||
status: "Open",
|
||||
},
|
||||
};
|
||||
|
||||
mqtt_client.publish(
|
||||
"Forum_detail_ganti_status",
|
||||
JSON.stringify({
|
||||
id: postingId,
|
||||
data: updateDetail.ForumMaster_StatusPosting,
|
||||
})
|
||||
);
|
||||
} else {
|
||||
setLoading(false);
|
||||
ComponentGlobal_NotifikasiGagal(updateStatusOpen.message);
|
||||
}
|
||||
} catch (error) {
|
||||
setLoading(false);
|
||||
clientLogger.error("Error get data forum", error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,44 +1,33 @@
|
||||
"use client";
|
||||
|
||||
import { RouterForum } from "@/lib/router_hipmi/router_forum";
|
||||
import { AccentColor } from "@/app_modules/_global/color/color_pallet";
|
||||
import ComponentGlobal_CreateButton from "@/app_modules/_global/component/button_create";
|
||||
import { apiGetUserById } from "@/app_modules/_global/lib/api_user";
|
||||
import { MODEL_USER } from "@/app_modules/home/model/interface";
|
||||
import { RouterForum } from "@/lib/router_hipmi/router_forum";
|
||||
import { clientLogger } from "@/util/clientLogger";
|
||||
import {
|
||||
ActionIcon,
|
||||
Affix,
|
||||
Center,
|
||||
Loader,
|
||||
Stack,
|
||||
Text,
|
||||
rem,
|
||||
Stack
|
||||
} from "@mantine/core";
|
||||
import { useShallowEffect, useWindowScroll } from "@mantine/hooks";
|
||||
import { IconPencilPlus, IconSearchOff } from "@tabler/icons-react";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import _ from "lodash";
|
||||
import { ScrollOnly } from "next-scroll-loader";
|
||||
import { useParams, useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import ComponentForum_ForumkuMainCardView from "../component/forumku_component/forumku_view";
|
||||
import { forum_getAllPostingByAuhtorId } from "../fun/get/get_list_posting_by_author_id";
|
||||
import { MODEL_FORUM_POSTING } from "../model/interface";
|
||||
import ComponentForum_ViewForumProfile from "./forum_profile";
|
||||
import ComponentGlobal_CreateButton from "@/app_modules/_global/component/button_create";
|
||||
import { apiGetUserById } from "@/app_modules/_global/lib/api_user";
|
||||
import backendLogger from "@/util/backendLogger";
|
||||
import { clientLogger } from "@/util/clientLogger";
|
||||
import { apiGetForumkuById } from "../component/api_fetch_forum";
|
||||
import ComponentForum_ForumkuMainCardView from "../component/forumku_component/forumku_view";
|
||||
import { Forum_ComponentIsDataEmpty } from "../component/other_component";
|
||||
import {
|
||||
Forum_SkeletonCard,
|
||||
Forum_SkeletonForumku,
|
||||
} from "../component/skeleton_view";
|
||||
import { data } from "autoprefixer";
|
||||
import { Forum_ComponentIsDataEmpty } from "../component/other_component";
|
||||
import { MODEL_FORUM_POSTING } from "../model/interface";
|
||||
import ComponentForum_ViewForumProfile from "./forum_profile";
|
||||
|
||||
export default function Forum_Forumku({
|
||||
totalPosting,
|
||||
userLoginId,
|
||||
}: {
|
||||
totalPosting: number;
|
||||
userLoginId: string;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
@@ -56,7 +45,6 @@ export default function Forum_Forumku({
|
||||
});
|
||||
|
||||
if (response) {
|
||||
console.log("response", response);
|
||||
setDataUser(response.data);
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -117,7 +105,7 @@ export default function Forum_Forumku({
|
||||
) : (
|
||||
<ComponentForum_ViewForumProfile
|
||||
auhtorSelectedData={dataUser}
|
||||
totalPosting={totalPosting}
|
||||
totalPosting={dataPosting.length}
|
||||
/>
|
||||
)}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user