Fix notification forum

Fix:
modified:   src/app/api/mobile/admin/forum/[id]/route.ts
modified:   src/app/api/mobile/forum/[id]/comment/route.ts
modified:   src/app/api/mobile/forum/[id]/report-posting/route.ts
modified:   src/app/api/mobile/forum/route.ts
modified:   src/lib/mobile/route-page-mobile.ts

Add:
src/app/api/mobile/forum/[id]/preview-report-posting/

### No Issue
This commit is contained in:
2026-01-17 16:00:46 +08:00
parent d09e30c049
commit cb0845e264
6 changed files with 253 additions and 28 deletions

View File

@@ -1,5 +1,17 @@
import { NextResponse } from "next/server";
import prisma from "@/lib/prisma";
import {
sendNotificationMobileToManyUser,
sendNotificationMobileToOneUser,
} from "@/lib/mobile/notification/send-notification";
import {
NotificationMobileBodyType,
NotificationMobileTitleType,
} from "../../../../../../../types/type-mobile-notification";
import {
routeAdminMobile,
routeUserMobile,
} from "@/lib/mobile/route-page-mobile";
export { POST };
@@ -7,38 +19,73 @@ async function POST(request: Request, { params }: { params: { id: string } }) {
let fixData;
const { id } = params;
const { data } = await request.json();
const { authorId: reportedUserId, categoryId, description } = data;
console.log("[DATA]", data);
console.log("[ID]", id);
try {
const content = await prisma.forum_Posting.findUnique({
where: {
id: id,
},
// Postingan yang akan di report
const findPosting = await prisma.forum_Posting.findUnique({
where: { id: id },
select: { authorId: true, diskusi: true },
});
const msg = `Report Postingan: "${content?.diskusi}"`;
const res = await fetch(
`https://cld-dkr-prod-wajs-server.wibudev.com/api/wa/code?nom=6282340374412&text=${msg}`,
{ cache: "no-cache" }
);
// List admin untuk dikirim notifikasi
const adminUsers = await prisma.user.findMany({
where: {
masterUserRoleId: "2",
NOT: { id: findPosting?.authorId as any },
},
select: { id: true },
});
if (data.categoryId) {
fixData = await prisma.forum_ReportPosting.create({
if (categoryId) {
const createReported = await prisma.forum_ReportPosting.create({
data: {
forum_PostingId: id,
userId: data.authorId,
forumMaster_KategoriReportId: data.categoryId,
userId: reportedUserId,
forumMaster_KategoriReportId: categoryId,
},
});
//SEND NOTIFICATION
await sendNotificationMobileToManyUser({
recipientIds: adminUsers.map((user) => user.id),
senderId: reportedUserId,
payload: {
title: "Laporan Dari User" as NotificationMobileTitleType,
body: `Report terhadap postingan, ${findPosting?.diskusi}` as NotificationMobileBodyType,
type: "announcement",
kategoriApp: "FORUM",
deepLink: routeAdminMobile.forumPreviewReportPosting,
},
});
fixData = createReported;
} else {
fixData = await prisma.forum_ReportPosting.create({
const createReported = await prisma.forum_ReportPosting.create({
data: {
forum_PostingId: id,
userId: data.authorId,
deskripsi: data.description,
userId: reportedUserId,
deskripsi: description,
},
});
//SEND NOTIFICATION
await sendNotificationMobileToManyUser({
recipientIds: adminUsers.map((user) => user.id),
senderId: reportedUserId,
payload: {
title: "Laporan Dari User" as NotificationMobileTitleType,
body: `Report terhadap postingan, ${findPosting?.diskusi}` as NotificationMobileBodyType,
type: "announcement",
kategoriApp: "FORUM",
deepLink: routeAdminMobile.forumPreviewReportPosting,
},
});
fixData = createReported;
}
if (!fixData) {
@@ -64,3 +111,39 @@ async function POST(request: Request, { params }: { params: { id: string } }) {
});
}
}
// async function GET(request: Request, { params }: { params: { id: string } }) {
// const { id } = params;
// try {
// const report = await prisma.forum_ReportPosting.findUnique({
// where: { id: id },
// select: {
// id: true,
// ForumMaster_KategoriReport: true,
// deskripsi: true,
// Forum_Posting: {
// select: {
// id: true,
// diskusi: true,
// authorId: true,
// },
// },
// },
// });
// return NextResponse.json({
// status: 200,
// success: true,
// data: report,
// });
// } catch (error) {
// console.log("[ERROR]", error);
// return NextResponse.json({
// status: 500,
// success: false,
// message: "Gagal mendapatkan report posting",
// reason: (error as Error).message,
// });
// }
// }