Update Versi 1.5.27 #32
75
src/app/api/mobile/admin/forum/[id]/comment/route.ts
Normal file
75
src/app/api/mobile/admin/forum/[id]/comment/route.ts
Normal file
@@ -0,0 +1,75 @@
|
||||
|
||||
import _ from "lodash";
|
||||
import { NextResponse } from "next/server";
|
||||
import prisma from "@/lib/prisma";
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: { id: string } }
|
||||
) {
|
||||
const { id } = params;
|
||||
const { searchParams } = new URL(request.url);
|
||||
const search = searchParams.get("search");
|
||||
const page = searchParams.get("page");
|
||||
const takeData = 10;
|
||||
const skipData = Number(page) * takeData - takeData;
|
||||
const category = searchParams.get("category");
|
||||
let fixData;
|
||||
try {
|
||||
if (category === "get-all") {
|
||||
fixData = await prisma.forum_Komentar.findMany({
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
where: {
|
||||
forum_PostingId: id,
|
||||
isActive: true,
|
||||
komentar: {
|
||||
contains: search ?? "",
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
include: {
|
||||
Forum_ReportKomentar: true,
|
||||
Author: {
|
||||
select: {
|
||||
username: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
} else if (category === "get-one") {
|
||||
fixData = await prisma.forum_Komentar.findUnique({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
include: {
|
||||
Forum_ReportKomentar: true,
|
||||
Author: {
|
||||
select: {
|
||||
username: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: "Success get detail comment",
|
||||
data: fixData,
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
} catch (error) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Error get detail data comment",
|
||||
reason: (error as Error).message,
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
78
src/app/api/mobile/admin/forum/[id]/route.ts
Normal file
78
src/app/api/mobile/admin/forum/[id]/route.ts
Normal file
@@ -0,0 +1,78 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import prisma from "@/lib/prisma";
|
||||
import _ from "lodash";
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: { id: string } }
|
||||
) {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const search = searchParams.get("search");
|
||||
const page = searchParams.get("page");
|
||||
const takeData = 10;
|
||||
const skipData = Number(page) * takeData - takeData;
|
||||
|
||||
const { id } = params;
|
||||
try {
|
||||
|
||||
const data = await prisma.forum_Posting.findFirst({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
diskusi: true,
|
||||
ForumMaster_StatusPosting: {
|
||||
select: {
|
||||
id: true,
|
||||
status: true,
|
||||
},
|
||||
},
|
||||
authorId: true,
|
||||
Author: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
Profile: {
|
||||
select: {
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Forum_Komentar: {
|
||||
where: {
|
||||
isActive: true,
|
||||
},
|
||||
},
|
||||
Forum_ReportPosting: {
|
||||
where: {
|
||||
isActive: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const result = {
|
||||
..._.omit(data, "Forum_Komentar", "Forum_ReportPosting"),
|
||||
JumlahKomentar: data?.Forum_Komentar.length,
|
||||
JumlahReportPosting: data?.Forum_ReportPosting.length,
|
||||
};
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: "Success get data",
|
||||
data: result,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error get data forum", error);
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Error get data forum",
|
||||
reason: (error as Error).message,
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
108
src/app/api/mobile/admin/forum/route.ts
Normal file
108
src/app/api/mobile/admin/forum/route.ts
Normal file
@@ -0,0 +1,108 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { prisma } from "@/lib";
|
||||
|
||||
export { GET };
|
||||
|
||||
async function GET(request: Request, { params }: { params: { name: string } }) {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const category = searchParams.get("category");
|
||||
const search = searchParams.get("search");
|
||||
|
||||
|
||||
let fixData;
|
||||
try {
|
||||
if (category === "dashboard") {
|
||||
const posting = await prisma.forum_Posting.count({
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
where: {
|
||||
isActive: true,
|
||||
},
|
||||
});
|
||||
|
||||
const reportPosting = await prisma.forum_ReportPosting.count({
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
where: {
|
||||
Forum_Posting: {
|
||||
isActive: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const reportComment = await prisma.forum_ReportKomentar.count({
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
where: {
|
||||
Forum_Komentar: {
|
||||
isActive: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
fixData = {
|
||||
posting,
|
||||
reportPosting,
|
||||
reportComment,
|
||||
};
|
||||
} else if (category === "posting") {
|
||||
fixData = await prisma.forum_Posting.findMany({
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
where: {
|
||||
isActive: true,
|
||||
diskusi: {
|
||||
contains: search || "",
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
diskusi: true,
|
||||
isActive: true,
|
||||
Author: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
Profile: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
} else if (category === "report_posting") {
|
||||
} else if (category === "report_comment") {
|
||||
} else {
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Invalid category",
|
||||
reason: "Invalid category",
|
||||
},
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: `Success get data forum ${category}`,
|
||||
data: fixData,
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
} catch (error) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: `Error get data forum ${category}`,
|
||||
reason: (error as Error).message,
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -10,9 +10,6 @@ async function GET(request: Request, { params }: { params: { name: string } }) {
|
||||
const search = searchParams.get("search");
|
||||
let fixData;
|
||||
|
||||
console.log("[CAT]", category);
|
||||
|
||||
|
||||
try {
|
||||
if (category === "dashboard") {
|
||||
const publish = await prisma.job.count({
|
||||
|
||||
Reference in New Issue
Block a user