Mobile API: Collaboration

Fix:
 - /api/mobile/admin/collaboration/[id]/route.ts
 - /api/mobile/admin/collaboration/route.ts

### No Issue
This commit is contained in:
nabillah
2025-10-16 14:51:53 +08:00
parent 3397ebd09f
commit d0fa33badc
2 changed files with 82 additions and 4 deletions

View File

@@ -1,7 +1,7 @@
import { NextResponse } from "next/server";
import prisma from "@/lib/prisma";
export { GET };
export { GET, PUT };
async function GET(request: Request, { params }: { params: { id: string } }) {
const { id } = params;
@@ -10,7 +10,7 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
let fixData;
try {
if (category === "publish") {
if (category === "publish" || category === "reject") {
fixData = await prisma.projectCollaboration.findUnique({
where: {
id: id,
@@ -53,6 +53,45 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
},
},
});
} else if (category === "group") {
fixData = await prisma.projectCollaboration_RoomChat.findUnique({
where: {
id: id,
},
select: {
id: true,
name: true,
ProjectCollaboration: {
select: {
id: true,
isActive: true,
title: true,
lokasi: true,
purpose: true,
benefit: true,
createdAt: true,
ProjectCollaborationMaster_Industri: true,
Author: true,
},
},
ProjectCollaboration_AnggotaRoomChat: {
select: {
User: {
select: {
username: true,
id: true,
Profile: {
select: {
id: true,
name: true,
},
},
},
},
},
},
},
});
}
return NextResponse.json(
@@ -74,3 +113,44 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
);
}
}
async function PUT(request: Request, { params }: { params: { id: string } }) {
const { id } = params;
const { data } = await request.json();
// const {searchParams} = new URL(request.url);
// const status = searchParams.get("status");
try {
const projectUpdate = await prisma.projectCollaboration.update({
where: {
id: id,
},
data: {
isActive: false,
isReject: true,
report: data,
},
select: {
userId: true,
},
});
return NextResponse.json(
{
success: true,
message: "Success update data collaboration",
// data: projectUpdate,
},
{ status: 200 }
);
} catch (error) {
return NextResponse.json(
{
success: false,
message: "Error update data collaboration",
reason: (error as Error).message,
},
{ status: 500 }
);
}
}

View File

@@ -8,8 +8,6 @@ async function GET(request: Request, { params }: { params: { name: string } }) {
const category = searchParams.get("category");
let fixData;
console.log(["CATEGORY", category]);
try {
if (category === "dashboard") {
const publish = await prisma.projectCollaboration.count({