Merge pull request 'mobile-notification report comment' (#43) from mobile-notification/19-jan-26 into staging
Reviewed-on: http://wibugit.wibudev.com/wibu/hipmi/pulls/43
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 }
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -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,14 +84,23 @@ 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 POSTING", data);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const data = await prisma.forum_Posting.update({
|
const deactivePosting = await prisma.forum_Posting.update({
|
||||||
where: {
|
where: {
|
||||||
id: id,
|
id: id,
|
||||||
},
|
},
|
||||||
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,12 +112,25 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("[DEACTIVATE COMMENT]", deactivateComment);
|
// SEND NOTIFICATION
|
||||||
|
await sendNotificationMobileToOneUser({
|
||||||
|
recipientId: deactivePosting?.authorId as string,
|
||||||
|
senderId: senderId,
|
||||||
|
payload: {
|
||||||
|
title: "Penghapusan Postingan" as NotificationMobileTitleType,
|
||||||
|
body: `Postingan anda telah dilaporkan: ${deactivePosting?.diskusi}` as NotificationMobileBodyType,
|
||||||
|
type: "announcement",
|
||||||
|
kategoriApp: "FORUM",
|
||||||
|
deepLink: routeUserMobile.forumPreviewReportPosting({ id: id }),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
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 }
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
@@ -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,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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,5 +1,15 @@
|
|||||||
import { NextResponse } from "next/server";
|
import {
|
||||||
|
sendNotificationMobileToManyUser
|
||||||
|
} from "@/lib/mobile/notification/send-notification";
|
||||||
|
import {
|
||||||
|
routeAdminMobile
|
||||||
|
} from "@/lib/mobile/route-page-mobile";
|
||||||
import prisma from "@/lib/prisma";
|
import prisma from "@/lib/prisma";
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import {
|
||||||
|
NotificationMobileBodyType,
|
||||||
|
NotificationMobileTitleType,
|
||||||
|
} from "../../../../../../../types/type-mobile-notification";
|
||||||
|
|
||||||
export { POST };
|
export { POST };
|
||||||
|
|
||||||
@@ -7,38 +17,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_Posting.findUnique({
|
// Postingan yang akan di report
|
||||||
where: {
|
const findPosting = await prisma.forum_Posting.findUnique({
|
||||||
id: id,
|
where: { id: id },
|
||||||
},
|
select: { authorId: true, diskusi: true },
|
||||||
});
|
});
|
||||||
|
|
||||||
const msg = `Report Postingan: "${content?.diskusi}"`;
|
// List admin untuk dikirim notifikasi
|
||||||
const res = await fetch(
|
const adminUsers = await prisma.user.findMany({
|
||||||
`https://cld-dkr-prod-wajs-server.wibudev.com/api/wa/code?nom=6282340374412&text=${msg}`,
|
where: {
|
||||||
{ cache: "no-cache" }
|
masterUserRoleId: "2",
|
||||||
);
|
NOT: { id: findPosting?.authorId as any },
|
||||||
|
},
|
||||||
|
select: { id: true },
|
||||||
|
});
|
||||||
|
|
||||||
if (data.categoryId) {
|
if (categoryId) {
|
||||||
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,
|
||||||
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) {
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
@@ -15,6 +15,10 @@ 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`,
|
||||||
|
forumPreviewReportComment: `/admin/forum/report-comment`,
|
||||||
};
|
};
|
||||||
|
|
||||||
const routeUserMobile = {
|
const routeUserMobile = {
|
||||||
@@ -33,4 +37,10 @@ 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`,
|
||||||
|
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