Fix API notification to report comment
Fix: - src/app/api/mobile/admin/forum/[id]/comment/route.ts - src/app/api/mobile/admin/forum/[id]/route.ts - src/app/api/mobile/forum/[id]/preview-report-posting/route.ts - src/app/api/mobile/forum/[id]/report-commentar/route.ts - src/app/api/mobile/forum/[id]/report-posting/route.ts - src/lib/mobile/route-page-mobile.ts - tsconfig.json Deleted: - src/app/api/mobile/forum/[id]/report-comment/route.ts Add: - src/app/api/mobile/forum/[id]/preview-report-comment/ - src/app/api/mobile/forum/[id]/report-comment-del-soon/ ### No Issue
This commit is contained in:
@@ -1,6 +1,12 @@
|
|||||||
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 { 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 };
|
||||||
|
|
||||||
@@ -82,21 +88,43 @@ 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();
|
||||||
|
|
||||||
|
console.log("SENDER Comment", data);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const deleteData = await prisma.forum_Komentar.update({
|
const deactiveComment = await prisma.forum_Komentar.update({
|
||||||
where: {
|
where: {
|
||||||
id: id,
|
id: id,
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
isActive: false,
|
isActive: false,
|
||||||
},
|
},
|
||||||
|
select: {
|
||||||
|
authorId: true,
|
||||||
|
komentar: true,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// SEND NOTIFICATION
|
||||||
|
await sendNotificationMobileToOneUser({
|
||||||
|
recipientId: deactiveComment?.authorId as string,
|
||||||
|
senderId: data?.senderId,
|
||||||
|
payload: {
|
||||||
|
title: "Penghapusan Komentar" as NotificationMobileTitleType,
|
||||||
|
body: `Komentar anda telah dilaporkan: ${deactiveComment?.komentar}` as NotificationMobileBodyType,
|
||||||
|
type: "announcement",
|
||||||
|
kategoriApp: "FORUM",
|
||||||
|
deepLink: routeUserMobile.forumPreviewReportComment({ id: id }),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log("[DEACTIVATE COMMENT]");
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{
|
{
|
||||||
success: true,
|
success: true,
|
||||||
message: "Success deactivate comment",
|
message: "Success deactivate comment",
|
||||||
data: deleteData,
|
// data: deactiveComment,
|
||||||
},
|
},
|
||||||
{ status: 200 }
|
{ status: 200 }
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -87,10 +87,10 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
|
|||||||
const data = await request.json();
|
const data = await request.json();
|
||||||
const { senderId } = data;
|
const { senderId } = data;
|
||||||
|
|
||||||
console.log("SENDER", senderId);
|
console.log("SENDER POSTING", data);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const data = await prisma.forum_Posting.update({
|
const deactivePosting = await prisma.forum_Posting.update({
|
||||||
where: {
|
where: {
|
||||||
id: id,
|
id: id,
|
||||||
},
|
},
|
||||||
@@ -114,23 +114,23 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
|
|||||||
|
|
||||||
// SEND NOTIFICATION
|
// SEND NOTIFICATION
|
||||||
await sendNotificationMobileToOneUser({
|
await sendNotificationMobileToOneUser({
|
||||||
recipientId: data?.authorId as string,
|
recipientId: deactivePosting?.authorId as string,
|
||||||
senderId: senderId,
|
senderId: senderId,
|
||||||
payload: {
|
payload: {
|
||||||
title: "Penghapusan Postingan" as NotificationMobileTitleType,
|
title: "Penghapusan Postingan" as NotificationMobileTitleType,
|
||||||
body: `Postingan anda telah dilaporkan: ${data?.diskusi}` as NotificationMobileBodyType,
|
body: `Postingan anda telah dilaporkan: ${deactivePosting?.diskusi}` as NotificationMobileBodyType,
|
||||||
type: "announcement",
|
type: "announcement",
|
||||||
kategoriApp: "FORUM",
|
kategoriApp: "FORUM",
|
||||||
deepLink: routeUserMobile.forumPreviewReportPosting({ id: id }),
|
deepLink: routeUserMobile.forumPreviewReportPosting({ id: id }),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("[DEACTIVATE COMMENT]", deactivateComment);
|
console.log("[DEACTIVATE POSTINGAN & COMMENT]", deactivateComment);
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{
|
{
|
||||||
success: true,
|
success: true,
|
||||||
message: "Success deactivate posting",
|
message: "Success deactivate posting",
|
||||||
data: data,
|
data: deactivePosting,
|
||||||
},
|
},
|
||||||
{ status: 200 }
|
{ status: 200 }
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
import { NextResponse } from "next/server";
|
||||||
|
|
||||||
|
export async function GET(
|
||||||
|
request: Request,
|
||||||
|
{ params }: { params: { id: string } }
|
||||||
|
) {
|
||||||
|
const { id } = params;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const data = await prisma.forum_Komentar.findUnique({
|
||||||
|
where: {
|
||||||
|
id: id,
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
komentar: true,
|
||||||
|
isActive: true,
|
||||||
|
createdAt: true,
|
||||||
|
Forum_ReportKomentar: {
|
||||||
|
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,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,12 +23,12 @@ export async function GET(
|
|||||||
username: true,
|
username: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// Forum_ReportPosting: {
|
Forum_ReportPosting: {
|
||||||
// select: {
|
select: {
|
||||||
// deskripsi: true,
|
deskripsi: true,
|
||||||
// ForumMaster_KategoriReport: true,
|
ForumMaster_KategoriReport: true,
|
||||||
// },
|
},
|
||||||
// },
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
import { prisma } from "@/lib";
|
import { prisma } from "@/lib";
|
||||||
|
import { sendNotificationMobileToManyUser } from "@/lib/mobile/notification/send-notification";
|
||||||
|
import { routeAdminMobile } from "@/lib/mobile/route-page-mobile";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
|
import {
|
||||||
|
NotificationMobileBodyType,
|
||||||
|
NotificationMobileTitleType,
|
||||||
|
} from "../../../../../../../types/type-mobile-notification";
|
||||||
|
|
||||||
export { POST };
|
export { POST };
|
||||||
|
|
||||||
@@ -7,44 +13,70 @@ 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();
|
||||||
console.log("[DATA]", data);
|
const { authorId: reportedUserId, categoryId, description } = data;
|
||||||
console.log("[ID]", id);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const content = await prisma.forum_Komentar.findUnique({
|
// Komentar yang di report
|
||||||
where: {
|
const findComment = await prisma.forum_Komentar.findUnique({
|
||||||
id: id,
|
where: { id: id },
|
||||||
},
|
select: { authorId: true, komentar: true },
|
||||||
});
|
});
|
||||||
|
|
||||||
const reportList = await prisma.forumMaster_KategoriReport.findUnique({
|
// List admin untuk dikirim notifikasi
|
||||||
|
const adminUsers = await prisma.user.findMany({
|
||||||
where: {
|
where: {
|
||||||
id: data.categoryId,
|
masterUserRoleId: "2",
|
||||||
|
NOT: { id: findComment?.authorId as any },
|
||||||
},
|
},
|
||||||
|
select: { id: true },
|
||||||
});
|
});
|
||||||
|
|
||||||
const msg = `Report Komentar: "${content?.komentar}" dengan kategori \n\n\n${reportList?.title} : \n\n${reportList?.deskripsi}`;
|
if (categoryId) {
|
||||||
const res = await fetch(
|
const createdReport = await prisma.forum_ReportKomentar.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_ReportKomentar.create({
|
|
||||||
data: {
|
data: {
|
||||||
forum_KomentarId: id,
|
forum_KomentarId: id,
|
||||||
userId: data.authorId,
|
userId: reportedUserId,
|
||||||
forumMaster_KategoriReportId: data.categoryId as any,
|
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 komentar, ${findComment?.komentar}` as NotificationMobileBodyType,
|
||||||
|
type: "announcement",
|
||||||
|
kategoriApp: "FORUM",
|
||||||
|
deepLink: routeAdminMobile.forumPreviewReportComment,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
fixData = createdReport;
|
||||||
} else {
|
} else {
|
||||||
fixData = await prisma.forum_ReportKomentar.create({
|
const createdReport = await prisma.forum_ReportKomentar.create({
|
||||||
data: {
|
data: {
|
||||||
forum_KomentarId: id,
|
forum_KomentarId: 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 komentar, ${findComment?.komentar}` as NotificationMobileBodyType,
|
||||||
|
type: "announcement",
|
||||||
|
kategoriApp: "FORUM",
|
||||||
|
deepLink: routeAdminMobile.forumPreviewReportComment,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
fixData = createdReport;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fixData) {
|
if (!fixData) {
|
||||||
|
|||||||
@@ -1,17 +1,15 @@
|
|||||||
import { NextResponse } from "next/server";
|
|
||||||
import prisma from "@/lib/prisma";
|
|
||||||
import {
|
import {
|
||||||
sendNotificationMobileToManyUser,
|
sendNotificationMobileToManyUser
|
||||||
sendNotificationMobileToOneUser,
|
|
||||||
} from "@/lib/mobile/notification/send-notification";
|
} from "@/lib/mobile/notification/send-notification";
|
||||||
|
import {
|
||||||
|
routeAdminMobile
|
||||||
|
} from "@/lib/mobile/route-page-mobile";
|
||||||
|
import prisma from "@/lib/prisma";
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
import {
|
import {
|
||||||
NotificationMobileBodyType,
|
NotificationMobileBodyType,
|
||||||
NotificationMobileTitleType,
|
NotificationMobileTitleType,
|
||||||
} from "../../../../../../../types/type-mobile-notification";
|
} from "../../../../../../../types/type-mobile-notification";
|
||||||
import {
|
|
||||||
routeAdminMobile,
|
|
||||||
routeUserMobile,
|
|
||||||
} from "@/lib/mobile/route-page-mobile";
|
|
||||||
|
|
||||||
export { POST };
|
export { POST };
|
||||||
|
|
||||||
@@ -21,9 +19,6 @@ async function POST(request: Request, { params }: { params: { id: string } }) {
|
|||||||
const { data } = await request.json();
|
const { data } = await request.json();
|
||||||
const { authorId: reportedUserId, categoryId, description } = data;
|
const { authorId: reportedUserId, categoryId, description } = data;
|
||||||
|
|
||||||
console.log("[DATA]", data);
|
|
||||||
console.log("[ID]", id);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Postingan yang akan di report
|
// Postingan yang akan di report
|
||||||
const findPosting = await prisma.forum_Posting.findUnique({
|
const findPosting = await prisma.forum_Posting.findUnique({
|
||||||
@@ -111,39 +106,3 @@ 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,
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ const routeAdminMobile = {
|
|||||||
|
|
||||||
// FORUM
|
// FORUM
|
||||||
forumPreviewReportPosting: `/admin/forum/report-posting`,
|
forumPreviewReportPosting: `/admin/forum/report-posting`,
|
||||||
|
forumPreviewReportComment: `/admin/forum/report-comment`,
|
||||||
};
|
};
|
||||||
|
|
||||||
const routeUserMobile = {
|
const routeUserMobile = {
|
||||||
@@ -41,4 +42,5 @@ const routeUserMobile = {
|
|||||||
forumBeranda: `/forum`,
|
forumBeranda: `/forum`,
|
||||||
forumDetail: ({ id }: { id: string }) => `/forum/${id}`,
|
forumDetail: ({ id }: { id: string }) => `/forum/${id}`,
|
||||||
forumPreviewReportPosting: ({ id }: { id: string }) => `/forum/${id}/preview-report-posting`,
|
forumPreviewReportPosting: ({ id }: { id: string }) => `/forum/${id}/preview-report-posting`,
|
||||||
|
forumPreviewReportComment: ({ id }: { id: string }) => `/forum/${id}/preview-report-comment`,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -23,6 +23,6 @@
|
|||||||
"@/*": ["./src/*"]
|
"@/*": ["./src/*"]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts", "src/app_modules/investasi/proses_transaksi/view.jsx", "src/app/api/investasi/midtrans/[id]/route.ts", "src/app_modules/job/create/TextEdit.tsx", "src/app/api/mobile/forum/[id]/report-comment/route.ts"],
|
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts", "src/app_modules/investasi/proses_transaksi/view.jsx", "src/app/api/investasi/midtrans/[id]/route.ts", "src/app_modules/job/create/TextEdit.tsx", "src/app/api/mobile/forum/[id]/report-comment-del-soon/route.ts"],
|
||||||
"exclude": ["node_modules"]
|
"exclude": ["node_modules"]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user