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,6 +1,12 @@
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
import prisma from "@/lib/prisma"; import prisma from "@/lib/prisma";
import _ from "lodash"; import _ from "lodash";
import { sendNotificationMobileToOneUser } from "@/lib/mobile/notification/send-notification";
import {
NotificationMobileBodyType,
NotificationMobileTitleType,
} from "../../../../../../../types/type-mobile-notification";
import { routeUserMobile } from "@/lib/mobile/route-page-mobile";
export { GET, PUT }; export { GET, PUT };
@@ -78,6 +84,11 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
async function PUT(request: Request, { params }: { params: { id: string } }) { async function PUT(request: Request, { params }: { params: { id: string } }) {
const { id } = params; const { id } = params;
const data = await request.json();
const { senderId } = data;
console.log("SENDER", senderId);
try { try {
const data = await prisma.forum_Posting.update({ const data = await prisma.forum_Posting.update({
where: { where: {
@@ -86,6 +97,10 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
data: { data: {
isActive: false, isActive: false,
}, },
select: {
authorId: true,
diskusi: true,
},
}); });
const deactivateComment = await prisma.forum_Komentar.updateMany({ const deactivateComment = await prisma.forum_Komentar.updateMany({
@@ -97,6 +112,19 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
}, },
}); });
// SEND NOTIFICATION
await sendNotificationMobileToOneUser({
recipientId: data?.authorId as string,
senderId: senderId,
payload: {
title: "Penghapusan Postingan" as NotificationMobileTitleType,
body: `Postingan anda telah dilaporkan: ${data?.diskusi}` as NotificationMobileBodyType,
type: "announcement",
kategoriApp: "FORUM",
deepLink: routeUserMobile.forumPreviewReportPosting({ id: id }),
},
});
console.log("[DEACTIVATE COMMENT]", deactivateComment); console.log("[DEACTIVATE COMMENT]", deactivateComment);
return NextResponse.json( return NextResponse.json(
{ {

View File

@@ -1,11 +1,18 @@
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
import prisma from "@/lib/prisma"; import prisma from "@/lib/prisma";
import { sendNotificationMobileToOneUser } from "@/lib/mobile/notification/send-notification";
import {
NotificationMobileBodyType,
NotificationMobileTitleType,
} from "../../../../../../../types/type-mobile-notification";
import { routeUserMobile } from "@/lib/mobile/route-page-mobile";
export { POST, GET, DELETE }; export { POST, GET, DELETE };
async function POST(request: Request, { params }: { params: { id: string } }) { async function POST(request: Request, { params }: { params: { id: string } }) {
const { id } = params; const { id } = params;
const { data } = await request.json(); const { data } = await request.json();
const { comment, authorId } = data;
console.log("[ID COMMENT]", id); console.log("[ID COMMENT]", id);
console.log("[DATA COMMENT]", data); console.log("[DATA COMMENT]", data);
@@ -14,8 +21,8 @@ async function POST(request: Request, { params }: { params: { id: string } }) {
const createComment = await prisma.forum_Komentar.create({ const createComment = await prisma.forum_Komentar.create({
data: { data: {
forum_PostingId: id, forum_PostingId: id,
komentar: data.comment, komentar: comment,
authorId: data.authorId, authorId: authorId,
}, },
select: { select: {
id: true, id: true,
@@ -38,6 +45,24 @@ async function POST(request: Request, { params }: { params: { id: string } }) {
}, },
}); });
const findForum = await prisma.forum_Posting.findUnique({
where: { id: id },
select: { authorId: true, diskusi: true },
});
// SEND NOTIFICATION
await sendNotificationMobileToOneUser({
recipientId: findForum?.authorId as string,
senderId: authorId,
payload: {
title: "Komentar Baru" as NotificationMobileTitleType,
body: `Ayo cek komentar pada postingan: ${findForum?.diskusi}` as NotificationMobileBodyType,
type: "announcement",
kategoriApp: "FORUM",
deepLink: routeUserMobile.forumDetail({ id: id }),
},
});
if (!createComment) { if (!createComment) {
return NextResponse.json({ return NextResponse.json({
status: 400, status: 400,
@@ -52,7 +77,6 @@ async function POST(request: Request, { params }: { params: { id: string } }) {
message: "Berhasil update data", message: "Berhasil update data",
data: createComment, data: createComment,
}); });
} catch (error) { } catch (error) {
console.log("[ERROR COMMENT]", error); console.log("[ERROR COMMENT]", error);
return NextResponse.json({ return NextResponse.json({
@@ -114,7 +138,10 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
} }
} }
async function DELETE(request: Request, { params }: { params: { id: string } }) { async function DELETE(
request: Request,
{ params }: { params: { id: string } }
) {
const { id } = params; const { id } = params;
try { try {

View File

@@ -0,0 +1,49 @@
import { NextResponse } from "next/server";
export async function GET(
request: Request,
{ params }: { params: { id: string } }
) {
const { id } = params;
try {
const data = await prisma.forum_Posting.findUnique({
where: {
id: id,
},
select: {
id: true,
diskusi: true,
isActive: true,
createdAt: true,
authorId: true,
Author: {
select: {
id: true,
username: true,
},
},
// Forum_ReportPosting: {
// select: {
// deskripsi: true,
// ForumMaster_KategoriReport: true,
// },
// },
},
});
return NextResponse.json({
status: 200,
success: true,
data: data,
});
} catch (error) {
console.log("[ERROR]", error);
return NextResponse.json({
status: 500,
success: false,
message: "Gagal mendapatkan data posting",
reason: (error as Error).message,
});
}
}

View File

@@ -1,5 +1,17 @@
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
import prisma from "@/lib/prisma"; 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 }; export { POST };
@@ -7,38 +19,73 @@ async function POST(request: Request, { params }: { params: { id: string } }) {
let fixData; let fixData;
const { id } = params; const { id } = params;
const { data } = await request.json(); const { data } = await request.json();
const { authorId: reportedUserId, categoryId, description } = data;
console.log("[DATA]", data); console.log("[DATA]", data);
console.log("[ID]", id); console.log("[ID]", id);
try { try {
const content = await prisma.forum_Posting.findUnique({ // Postingan yang akan di report
const findPosting = await prisma.forum_Posting.findUnique({
where: { id: id },
select: { authorId: true, diskusi: true },
});
// List admin untuk dikirim notifikasi
const adminUsers = await prisma.user.findMany({
where: { where: {
id: id, masterUserRoleId: "2",
NOT: { id: findPosting?.authorId as any },
}, },
select: { id: true },
}); });
const msg = `Report Postingan: "${content?.diskusi}"`; if (categoryId) {
const res = await fetch( const createReported = await prisma.forum_ReportPosting.create({
`https://cld-dkr-prod-wajs-server.wibudev.com/api/wa/code?nom=6282340374412&text=${msg}`,
{ cache: "no-cache" }
);
if (data.categoryId) {
fixData = await prisma.forum_ReportPosting.create({
data: { data: {
forum_PostingId: id, forum_PostingId: id,
userId: data.authorId, userId: reportedUserId,
forumMaster_KategoriReportId: data.categoryId, 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 { } else {
fixData = await prisma.forum_ReportPosting.create({ const createReported = await prisma.forum_ReportPosting.create({
data: { data: {
forum_PostingId: id, forum_PostingId: id,
userId: data.authorId, userId: reportedUserId,
deskripsi: data.description, 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) { 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,
// });
// }
// }

View File

@@ -1,22 +1,54 @@
import _ from "lodash"; import _ from "lodash";
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
import prisma from "@/lib/prisma"; import prisma from "@/lib/prisma";
import { sendNotificationMobileToManyUser } from "@/lib/mobile/notification/send-notification";
import { NotificationMobileBodyType, NotificationMobileTitleType } from "../../../../../types/type-mobile-notification";
import { routeUserMobile } from "@/lib/mobile/route-page-mobile";
export { POST, GET }; export { POST, GET };
async function POST(request: Request) { async function POST(request: Request) {
const { data } = await request.json(); const { data } = await request.json();
console.log("[DATA]", data); console.log("[DATA]", data);
const { diskusi, authorId } = data;
try { try {
const create = await prisma.forum_Posting.create({ const create = await prisma.forum_Posting.create({
data: { data: {
diskusi: data.diskusi, diskusi: diskusi,
authorId: data.authorId, authorId: authorId,
forumMaster_StatusPostingId: 1, forumMaster_StatusPostingId: 1,
}, },
}); });
if (!create) {
return NextResponse.json({
success: false,
message: "Gagal memposting",
status: 400,
});
}
const allUsers = await prisma.user.findMany({
where: {
id: { not: authorId },
},
select: { id: true },
});
// SEND NOTIFICATION
await sendNotificationMobileToManyUser({
recipientIds: allUsers.map((user) => user.id),
senderId: authorId,
payload: {
title: "Ada Diskusi Baru" as NotificationMobileTitleType,
body: `${diskusi}` as NotificationMobileBodyType,
type: "announcement",
kategoriApp: "FORUM",
deepLink: routeUserMobile.forumBeranda,
},
});
return NextResponse.json({ return NextResponse.json({
success: true, success: true,
message: "Berhasil membuat postingan", message: "Berhasil membuat postingan",
@@ -43,7 +75,6 @@ async function GET(request: Request) {
const takeData = 5; const takeData = 5;
const skipData = (Number(page) - 1) * takeData; const skipData = (Number(page) - 1) * takeData;
// console.log("authorId", authorId); // console.log("authorId", authorId);
// console.log("userLoginId", userLoginId); // console.log("userLoginId", userLoginId);
// console.log("search", search); // console.log("search", search);
@@ -128,13 +159,12 @@ async function GET(request: Request) {
fixData = newData; fixData = newData;
} else if (category === "forumku") { } else if (category === "forumku") {
const count = await prisma.forum_Posting.count({ const count = await prisma.forum_Posting.count({
where: { where: {
isActive: true, isActive: true,
authorId: authorId, authorId: authorId,
}, },
}) });
const data = await prisma.forum_Posting.findMany({ const data = await prisma.forum_Posting.findMany({
take: page ? takeData : undefined, take: page ? takeData : undefined,
@@ -191,7 +221,7 @@ async function GET(request: Request) {
const dataFix = { const dataFix = {
data: newData, data: newData,
count, count,
} };
fixData = dataFix; fixData = dataFix;
} else { } else {

View File

@@ -15,6 +15,9 @@ const routeAdminMobile = {
// VOTING // VOTING
votingByStatus: ({ status }: { status: StatusApp }) => votingByStatus: ({ status }: { status: StatusApp }) =>
`/admin/voting/${status}/status`, `/admin/voting/${status}/status`,
// FORUM
forumPreviewReportPosting: `/admin/forum/report-posting`,
}; };
const routeUserMobile = { const routeUserMobile = {
@@ -33,4 +36,9 @@ const routeUserMobile = {
votingByStatus: ({ status }: { status?: StatusApp }) => votingByStatus: ({ status }: { status?: StatusApp }) =>
`/voting/(tabs)/status?status=${status}`, `/voting/(tabs)/status?status=${status}`,
votingDetailPublised: ({ id }: { id: string }) => `/voting/${id}`, votingDetailPublised: ({ id }: { id: string }) => `/voting/${id}`,
// FORUM
forumBeranda: `/forum`,
forumDetail: ({ id }: { id: string }) => `/forum/${id}`,
forumPreviewReportPosting: ({ id }: { id: string }) => `/forum/${id}/preview-report-posting`,
}; };