Merge pull request 'Mobile API: Forum' (#23) from mobile/26-sep-25 into staging
Reviewed-on: bip/hipmi#23
This commit is contained in:
149
src/app/api/mobile/forum/[id]/comment/route.ts
Normal file
149
src/app/api/mobile/forum/[id]/comment/route.ts
Normal file
@@ -0,0 +1,149 @@
|
|||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import prisma from "@/lib/prisma";
|
||||||
|
|
||||||
|
export { POST, GET, DELETE };
|
||||||
|
|
||||||
|
async function POST(request: Request, { params }: { params: { id: string } }) {
|
||||||
|
const { id } = params;
|
||||||
|
const { data } = await request.json();
|
||||||
|
|
||||||
|
console.log("[ID COMMENT]", id);
|
||||||
|
console.log("[DATA COMMENT]", data);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const createComment = await prisma.forum_Komentar.create({
|
||||||
|
data: {
|
||||||
|
forum_PostingId: id,
|
||||||
|
komentar: data.comment,
|
||||||
|
authorId: data.authorId,
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
isActive: true,
|
||||||
|
komentar: true,
|
||||||
|
createdAt: true,
|
||||||
|
authorId: true,
|
||||||
|
Author: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
username: true,
|
||||||
|
Profile: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
imageId: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!createComment) {
|
||||||
|
return NextResponse.json({
|
||||||
|
status: 400,
|
||||||
|
success: false,
|
||||||
|
message: "Gagal update data",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return NextResponse.json({
|
||||||
|
status: 200,
|
||||||
|
success: true,
|
||||||
|
message: "Berhasil update data",
|
||||||
|
data: createComment,
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.log("[ERROR COMMENT]", error);
|
||||||
|
return NextResponse.json({
|
||||||
|
status: 500,
|
||||||
|
success: false,
|
||||||
|
message: "Gagal update data",
|
||||||
|
reason: (error as Error).message || error,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||||
|
const { id } = params;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const data = await prisma.forum_Komentar.findMany({
|
||||||
|
orderBy: {
|
||||||
|
createdAt: "desc",
|
||||||
|
},
|
||||||
|
where: {
|
||||||
|
forum_PostingId: id,
|
||||||
|
isActive: true,
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
isActive: true,
|
||||||
|
komentar: true,
|
||||||
|
createdAt: true,
|
||||||
|
authorId: true,
|
||||||
|
Author: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
username: true,
|
||||||
|
Profile: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
imageId: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return NextResponse.json({
|
||||||
|
status: 200,
|
||||||
|
success: true,
|
||||||
|
message: "Berhasil mendapatkan data",
|
||||||
|
data: data,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.log("[ERROR COMMENT]", error);
|
||||||
|
return NextResponse.json({
|
||||||
|
status: 500,
|
||||||
|
success: false,
|
||||||
|
message: "Gagal mendapatkan data",
|
||||||
|
reason: (error as Error).message || error,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function DELETE(request: Request, { params }: { params: { id: string } }) {
|
||||||
|
const { id } = params;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const deleteComment = await prisma.forum_Komentar.delete({
|
||||||
|
where: {
|
||||||
|
id: id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!deleteComment) {
|
||||||
|
return NextResponse.json({
|
||||||
|
status: 400,
|
||||||
|
success: false,
|
||||||
|
message: "Gagal hapus komentar",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return NextResponse.json({
|
||||||
|
status: 200,
|
||||||
|
success: true,
|
||||||
|
message: "Berhasil hapus komentar",
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.log("[ERROR COMMENT]", error);
|
||||||
|
return NextResponse.json({
|
||||||
|
status: 500,
|
||||||
|
success: false,
|
||||||
|
message: "Gagal hapus komentar",
|
||||||
|
reason: (error as Error).message || error,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
61
src/app/api/mobile/forum/[id]/report-comment/route.ts
Normal file
61
src/app/api/mobile/forum/[id]/report-comment/route.ts
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import prisma from "@/lib/prisma";
|
||||||
|
|
||||||
|
export { POST };
|
||||||
|
|
||||||
|
async function POST(request: Request, { params }: { params: { id: string } }) {
|
||||||
|
let fixData;
|
||||||
|
const { id } = params;
|
||||||
|
const { data } = await request.json();
|
||||||
|
console.log("[DATA]", data);
|
||||||
|
console.log("[ID]", id);
|
||||||
|
|
||||||
|
try {
|
||||||
|
fixData = await prisma.forum_ReportKomentar.create({
|
||||||
|
data: {
|
||||||
|
forum_KomentarId: id,
|
||||||
|
userId: data.authorId,
|
||||||
|
forumMaster_KategoriReportId: data.categoryId as any,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
// if (data.categoryId) {
|
||||||
|
// fixData = await prisma.forum_ReportKomentar.create({
|
||||||
|
// data: {
|
||||||
|
// forum_KomentarId: id,
|
||||||
|
// userId: data.authorId,
|
||||||
|
// forumMaster_KategoriReportId: data.categoryId as any,
|
||||||
|
// },
|
||||||
|
// });
|
||||||
|
// } else {
|
||||||
|
// fixData = await prisma.forum_ReportKomentar.create({
|
||||||
|
// data: {
|
||||||
|
// forum_KomentarId: id,
|
||||||
|
// userId: data.authorId,
|
||||||
|
// deskripsi: data.description,
|
||||||
|
// },
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (!fixData) {
|
||||||
|
// return NextResponse.json({
|
||||||
|
// status: 400,
|
||||||
|
// success: false,
|
||||||
|
// message: "Gagal membuat report komentar",
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
|
||||||
|
return NextResponse.json({
|
||||||
|
status: 201,
|
||||||
|
success: true,
|
||||||
|
message: "Berhasil membuat report komentar",
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.log("[ERROR]", error);
|
||||||
|
return NextResponse.json({
|
||||||
|
status: 500,
|
||||||
|
success: false,
|
||||||
|
message: "Gagal membuat report komentar",
|
||||||
|
reason: (error as Error).message,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
54
src/app/api/mobile/forum/[id]/report-commentar/route.ts
Normal file
54
src/app/api/mobile/forum/[id]/report-commentar/route.ts
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
import { prisma } from "@/lib";
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
|
||||||
|
export { POST };
|
||||||
|
|
||||||
|
async function POST(request: Request, { params }: { params: { id: string } }) {
|
||||||
|
let fixData;
|
||||||
|
const { id } = params;
|
||||||
|
const { data } = await request.json();
|
||||||
|
console.log("[DATA]", data);
|
||||||
|
console.log("[ID]", id);
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (data.categoryId) {
|
||||||
|
fixData = await prisma.forum_ReportKomentar.create({
|
||||||
|
data: {
|
||||||
|
forum_KomentarId: id,
|
||||||
|
userId: data.authorId,
|
||||||
|
forumMaster_KategoriReportId: data.categoryId as any,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
fixData = await prisma.forum_ReportKomentar.create({
|
||||||
|
data: {
|
||||||
|
forum_KomentarId: id,
|
||||||
|
userId: data.authorId,
|
||||||
|
deskripsi: data.description,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fixData) {
|
||||||
|
return NextResponse.json({
|
||||||
|
status: 400,
|
||||||
|
success: false,
|
||||||
|
message: "Gagal membuat report komentar",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return NextResponse.json({
|
||||||
|
status: 201,
|
||||||
|
success: true,
|
||||||
|
message: "Berhasil membuat report komentar",
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.log("[ERROR]", error);
|
||||||
|
return NextResponse.json({
|
||||||
|
status: 500,
|
||||||
|
success: false,
|
||||||
|
message: "Gagal membuat report komentar",
|
||||||
|
reason: (error as Error).message,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
54
src/app/api/mobile/forum/[id]/report-posting/route.ts
Normal file
54
src/app/api/mobile/forum/[id]/report-posting/route.ts
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import prisma from "@/lib/prisma";
|
||||||
|
|
||||||
|
export { POST };
|
||||||
|
|
||||||
|
async function POST(request: Request, { params }: { params: { id: string } }) {
|
||||||
|
let fixData;
|
||||||
|
const { id } = params;
|
||||||
|
const { data } = await request.json();
|
||||||
|
console.log("[DATA]", data);
|
||||||
|
console.log("[ID]", id);
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (data.categoryId) {
|
||||||
|
fixData = await prisma.forum_ReportPosting.create({
|
||||||
|
data: {
|
||||||
|
forum_PostingId: id,
|
||||||
|
userId: data.authorId,
|
||||||
|
forumMaster_KategoriReportId: data.categoryId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
fixData = await prisma.forum_ReportPosting.create({
|
||||||
|
data: {
|
||||||
|
forum_PostingId: id,
|
||||||
|
userId: data.authorId,
|
||||||
|
deskripsi: data.description,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fixData) {
|
||||||
|
return NextResponse.json({
|
||||||
|
status: 400,
|
||||||
|
success: false,
|
||||||
|
message: "Gagal membuat report posting",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return NextResponse.json({
|
||||||
|
status: 201,
|
||||||
|
success: true,
|
||||||
|
message: "Berhasil membuat report posting",
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.log("[ERROR]", error);
|
||||||
|
return NextResponse.json({
|
||||||
|
status: 500,
|
||||||
|
success: false,
|
||||||
|
message: "Gagal membuat report posting",
|
||||||
|
reason: (error as Error).message,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +1,188 @@
|
|||||||
export { GET };
|
import prisma from "@/lib/prisma";
|
||||||
|
import _ from "lodash";
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
|
||||||
async function GET(request: Request) {
|
export { GET, PUT, DELETE, POST };
|
||||||
try {
|
|
||||||
|
async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||||
|
const { id } = params;
|
||||||
} catch (error) {
|
|
||||||
|
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,
|
||||||
|
Profile: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Forum_Komentar: {
|
||||||
|
where: {
|
||||||
|
isActive: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
ForumMaster_StatusPosting: true,
|
||||||
|
forumMaster_StatusPostingId: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const count = data?.Forum_Komentar?.length ?? 0;
|
||||||
|
|
||||||
|
const newData = {
|
||||||
|
..._.omit(data, ["Forum_Komentar"]),
|
||||||
|
count,
|
||||||
|
};
|
||||||
|
|
||||||
|
return NextResponse.json({
|
||||||
|
success: true,
|
||||||
|
message: "Berhasil mendapatkan data",
|
||||||
|
data: newData,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.log("[ERROR FORUM]", error);
|
||||||
|
return NextResponse.json({
|
||||||
|
success: false,
|
||||||
|
message: "Gagal mendapatkan data",
|
||||||
|
reason: (error as Error).message || error,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function PUT(request: Request, { params }: { params: { id: string } }) {
|
||||||
|
const { id } = params;
|
||||||
|
const { data } = await request.json();
|
||||||
|
|
||||||
|
console.log("[DATA]", data);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const update = await prisma.forum_Posting.update({
|
||||||
|
where: {
|
||||||
|
id: id,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
diskusi: data,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!update) {
|
||||||
|
return NextResponse.json({
|
||||||
|
status: 400,
|
||||||
|
success: false,
|
||||||
|
message: "Gagal update data",
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return NextResponse.json({
|
||||||
|
status: 200,
|
||||||
|
success: true,
|
||||||
|
message: "Berhasil update data",
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.log("[ERROR FORUM]", error);
|
||||||
|
return NextResponse.json({
|
||||||
|
status: 500,
|
||||||
|
success: false,
|
||||||
|
message: "Gagal update data",
|
||||||
|
reason: (error as Error).message || error,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function DELETE(
|
||||||
|
request: Request,
|
||||||
|
{ params }: { params: { id: string } }
|
||||||
|
) {
|
||||||
|
const { id } = params;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const dlt = await prisma.forum_Posting.delete({
|
||||||
|
where: {
|
||||||
|
id: id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!dlt) {
|
||||||
|
return NextResponse.json({
|
||||||
|
status: 400,
|
||||||
|
success: false,
|
||||||
|
message: "Gagal hapus data",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return NextResponse.json({
|
||||||
|
status: 200,
|
||||||
|
success: true,
|
||||||
|
message: "Berhasil hapus data",
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.log("[ERROR FORUM]", error);
|
||||||
|
return NextResponse.json({
|
||||||
|
status: 500,
|
||||||
|
success: false,
|
||||||
|
message: "Error hapus data",
|
||||||
|
reason: (error as Error).message || error,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update Status
|
||||||
|
async function POST(request: Request, { params }: { params: { id: string } }) {
|
||||||
|
const { id } = params;
|
||||||
|
const { data } = await request.json();
|
||||||
|
|
||||||
|
console.log("[DATA]", data);
|
||||||
|
|
||||||
|
const status = await prisma.forumMaster_StatusPosting.findFirst({
|
||||||
|
where: {
|
||||||
|
status: data,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log("[STATUS]", status);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const update = await prisma.forum_Posting.update({
|
||||||
|
where: {
|
||||||
|
id: id,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
forumMaster_StatusPostingId: status?.id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!update) {
|
||||||
|
return NextResponse.json({
|
||||||
|
status: 400,
|
||||||
|
success: false,
|
||||||
|
message: "Gagal update data",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const fixData = status?.status;
|
||||||
|
|
||||||
|
return NextResponse.json({
|
||||||
|
status: 200,
|
||||||
|
success: true,
|
||||||
|
message: "Berhasil update data",
|
||||||
|
data: fixData,
|
||||||
|
});
|
||||||
|
|
||||||
}
|
} catch (error) {
|
||||||
|
console.log("[ERROR FORUM]", error);
|
||||||
|
return NextResponse.json({
|
||||||
|
status: 500,
|
||||||
|
success: false,
|
||||||
|
message: "Gagal update data",
|
||||||
|
reason: (error as Error).message || error,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
import _ from "lodash";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
|
import prisma from "@/lib/prisma";
|
||||||
|
|
||||||
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();
|
||||||
@@ -31,60 +33,127 @@ async function POST(request: Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function GET(request: Request) {
|
async function GET(request: Request) {
|
||||||
|
let fixData;
|
||||||
const { searchParams } = new URL(request.url);
|
const { searchParams } = new URL(request.url);
|
||||||
|
const authorId = searchParams.get("authorId");
|
||||||
const search = searchParams.get("search");
|
const search = searchParams.get("search");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const data = await prisma.forum_Posting.findMany({
|
if (authorId) {
|
||||||
orderBy: {
|
const data = await prisma.forum_Posting.findMany({
|
||||||
createdAt: "desc",
|
orderBy: {
|
||||||
},
|
createdAt: "desc",
|
||||||
where: {
|
},
|
||||||
isActive: true,
|
where: {
|
||||||
diskusi: {
|
isActive: true,
|
||||||
mode: "insensitive",
|
authorId: authorId,
|
||||||
contains: search || "",
|
},
|
||||||
},
|
select: {
|
||||||
},
|
id: true,
|
||||||
select: {
|
diskusi: true,
|
||||||
id: true,
|
createdAt: true,
|
||||||
diskusi: true,
|
isActive: true,
|
||||||
createdAt: true,
|
authorId: true,
|
||||||
isActive: true,
|
Author: {
|
||||||
authorId: true,
|
select: {
|
||||||
Author: {
|
id: true,
|
||||||
select: {
|
username: true,
|
||||||
id: true,
|
Profile: {
|
||||||
username: true,
|
select: {
|
||||||
Profile: {
|
id: true,
|
||||||
select: {
|
name: true,
|
||||||
id: true,
|
imageId: true,
|
||||||
name: true,
|
},
|
||||||
imageId: true,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Forum_Komentar: {
|
||||||
|
where: {
|
||||||
|
isActive: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
ForumMaster_StatusPosting: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
status: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
forumMaster_StatusPostingId: true,
|
||||||
},
|
},
|
||||||
Forum_Komentar: {
|
});
|
||||||
where: {
|
|
||||||
isActive: true,
|
const newData = data.map((item) => {
|
||||||
|
const count = item.Forum_Komentar?.length ?? 0;
|
||||||
|
return {
|
||||||
|
..._.omit(item, ["Forum_Komentar"]),
|
||||||
|
count,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
fixData = newData;
|
||||||
|
} else {
|
||||||
|
const data = await prisma.forum_Posting.findMany({
|
||||||
|
orderBy: {
|
||||||
|
createdAt: "desc",
|
||||||
|
},
|
||||||
|
where: {
|
||||||
|
isActive: true,
|
||||||
|
diskusi: {
|
||||||
|
mode: "insensitive",
|
||||||
|
contains: search || "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
ForumMaster_StatusPosting: {
|
select: {
|
||||||
select: {
|
id: true,
|
||||||
id: true,
|
diskusi: true,
|
||||||
status: true,
|
createdAt: true,
|
||||||
|
isActive: true,
|
||||||
|
authorId: true,
|
||||||
|
Author: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
username: true,
|
||||||
|
Profile: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
name: true,
|
||||||
|
imageId: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
Forum_Komentar: {
|
||||||
|
where: {
|
||||||
|
isActive: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
ForumMaster_StatusPosting: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
status: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
forumMaster_StatusPostingId: true,
|
||||||
},
|
},
|
||||||
forumMaster_StatusPostingId: true,
|
});
|
||||||
},
|
|
||||||
});
|
const newData = data.map((item) => {
|
||||||
|
const count = item.Forum_Komentar?.length ?? 0;
|
||||||
|
return {
|
||||||
|
..._.omit(item, ["Forum_Komentar"]),
|
||||||
|
count,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
fixData = newData;
|
||||||
|
}
|
||||||
|
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
success: true,
|
success: true,
|
||||||
message: "Berhasil mendapatkan data",
|
message: "Berhasil mendapatkan data",
|
||||||
data: data,
|
data: fixData,
|
||||||
});
|
});
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log("[ERROR]", error);
|
console.log("[ERROR]", error);
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
|
|||||||
28
src/app/api/mobile/master/forum-report/route.ts
Normal file
28
src/app/api/mobile/master/forum-report/route.ts
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import prisma from "@/lib/prisma";
|
||||||
|
|
||||||
|
export async function GET(request: Request) {
|
||||||
|
try {
|
||||||
|
const data = await prisma.forumMaster_KategoriReport.findMany({
|
||||||
|
orderBy: {
|
||||||
|
createdAt: "asc",
|
||||||
|
},
|
||||||
|
where: {
|
||||||
|
isActive: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return NextResponse.json({
|
||||||
|
success: true,
|
||||||
|
message: "Berhasil mendapatkan data",
|
||||||
|
data: data,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.log("[ERROR]", error);
|
||||||
|
return NextResponse.json({
|
||||||
|
success: false,
|
||||||
|
message: "Gagal mendapatkan data",
|
||||||
|
reason: (error as Error).message,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,7 +9,7 @@ import { useShallowEffect } from "@mantine/hooks";
|
|||||||
import { Comp_V3_SetInnerHTMLWithStiker } from "@/app_modules/_global/component/new/comp_V3_set_html_with_stiker";
|
import { Comp_V3_SetInnerHTMLWithStiker } from "@/app_modules/_global/component/new/comp_V3_set_html_with_stiker";
|
||||||
import { MainColor } from "@/app_modules/_global/color";
|
import { MainColor } from "@/app_modules/_global/color";
|
||||||
|
|
||||||
export default function ComponentForum_DetailForumView({
|
export default function ComponentForum_DetailForumView({
|
||||||
data,
|
data,
|
||||||
totalKomentar,
|
totalKomentar,
|
||||||
userLoginId,
|
userLoginId,
|
||||||
|
|||||||
Reference in New Issue
Block a user