Penambahan fitur open blockir #17

Merged
bagasbanuna merged 1 commits from apple-reject/28-nov-25 into staging 2025-11-28 10:49:04 +08:00
2 changed files with 147 additions and 1 deletions

View File

@@ -0,0 +1,78 @@
import { NextResponse } from "next/server";
import prisma from "@/lib/prisma";
export { GET, DELETE };
async function GET(request: Request, { params }: { params: { id: string } }) {
const { id } = params;
console.log("[ID] >>", id);
try {
const data = await prisma.blockedUser.findUnique({
where: {
id: id,
},
select: {
blocked: {
select: {
id: true,
username: true,
Profile: {
select: {
id: true,
imageId: true,
},
},
},
},
menuFeature: {
select: {
name: true,
value: true,
},
},
},
});
return NextResponse.json({
status: 200,
success: true,
message: "success",
data: data,
});
} catch (error) {
console.log("[ERROR GET BLOCK USER] >>", error);
return NextResponse.json({
status: 500,
success: false,
message: "error",
reason: (error as Error).message || error,
});
}
}
async function DELETE(request: Request, { params }: { params: { id: string } }) {
const { id } = params;
console.log("[ID] >>", id);
try {
const data = await prisma.blockedUser.delete({
where: {
id: id,
},
});
return NextResponse.json({
status: 200,
success: true,
message: "success",
data: data,
});
} catch (error) {
console.log("[ERROR DELETE BLOCK USER] >>", error);
return NextResponse.json({
status: 500,
success: false,
message: "error",
reason: (error as Error).message || error,
});
}
}

View File

@@ -2,7 +2,7 @@ import _ from "lodash";
import { NextResponse } from "next/server";
import prisma from "@/lib/prisma";
export { POST };
export { POST, GET };
async function POST(request: Request) {
const { data } = await request.json();
@@ -45,3 +45,71 @@ async function POST(request: Request) {
});
}
}
async function GET(request: Request) {
const { searchParams } = new URL(request.url);
const id = searchParams.get("id");
const page = Number(searchParams.get("page"));
const search = searchParams.get("search");
const takeData = 10;
const skipData = page * takeData - takeData;
// console.log("[BLOCKED ID]", id);
// console.log("[PAGE]", page);
// console.log("[TAKE DATA]", takeData);
// console.log("[SKIP DATA]", skipData);
// console.log("[SEARCH]", search);
try {
const data = await prisma.blockedUser.findMany({
take: page ? takeData : undefined,
skip: page ? skipData : undefined,
where: {
blockerId: id as any,
menuFeature: {
id: {
contains: search || "",
mode: "insensitive",
},
},
},
select: {
id: true,
blocked: {
select: {
id: true,
username: true,
Profile: {
select: {
id: true,
imageId: true,
},
},
},
},
menuFeature: {
select: {
name: true,
value: true,
},
},
},
});
return NextResponse.json({
status: 200,
success: true,
message: "success",
data: data,
});
} catch (error) {
console.log("[ERROR GET BLOCK USER] >>", error);
return NextResponse.json({
status: 500,
success: false,
message: "error",
reason: (error as Error).message || error,
});
}
}