From b3dc38046e06d48308c59d3d801842e74039ca6a Mon Sep 17 00:00:00 2001 From: nabillah Date: Wed, 15 Oct 2025 17:36:38 +0800 Subject: [PATCH] Mobile API: Collaboration Add: src/app/api/mobile/admin/collaboration/ ### No Issue --- .../mobile/admin/collaboration/[id]/route.ts | 76 +++++++ .../api/mobile/admin/collaboration/route.ts | 202 ++++++++++++++++++ 2 files changed, 278 insertions(+) create mode 100644 src/app/api/mobile/admin/collaboration/[id]/route.ts create mode 100644 src/app/api/mobile/admin/collaboration/route.ts diff --git a/src/app/api/mobile/admin/collaboration/[id]/route.ts b/src/app/api/mobile/admin/collaboration/[id]/route.ts new file mode 100644 index 00000000..7f1f7337 --- /dev/null +++ b/src/app/api/mobile/admin/collaboration/[id]/route.ts @@ -0,0 +1,76 @@ +import { NextResponse } from "next/server"; +import prisma from "@/lib/prisma"; + +export { GET }; + +async function GET(request: Request, { params }: { params: { id: string } }) { + const { id } = params; + const { searchParams } = new URL(request.url); + const category = searchParams.get("category"); + + let fixData; + try { + if (category === "publish") { + fixData = await prisma.projectCollaboration.findUnique({ + where: { + id: id, + }, + select: { + id: true, + isActive: true, + title: true, + lokasi: true, + purpose: true, + benefit: true, + createdAt: true, + report: true, + Author: { + select: { + id: true, + username: true, + }, + }, + ProjectCollaborationMaster_Industri: true, + ProjectCollaboration_Partisipasi: { + where: { + User: { + active: true, + }, + }, + select: { + id: true, + User: { + select: { + id: true, + Profile: { + select: { + name: true, + }, + }, + }, + }, + }, + }, + }, + }); + } + + return NextResponse.json( + { + success: true, + message: "Success get data collaboration", + data: fixData, + }, + { status: 200 } + ); + } catch (error) { + return NextResponse.json( + { + success: false, + message: "Error get data collaboration", + reason: (error as Error).message, + }, + { status: 500 } + ); + } +} diff --git a/src/app/api/mobile/admin/collaboration/route.ts b/src/app/api/mobile/admin/collaboration/route.ts new file mode 100644 index 00000000..fcf7a5f5 --- /dev/null +++ b/src/app/api/mobile/admin/collaboration/route.ts @@ -0,0 +1,202 @@ +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"); + let fixData; + + console.log(["CATEGORY", category]); + + try { + if (category === "dashboard") { + const publish = await prisma.projectCollaboration.count({ + where: { + isActive: true, + isReject: false, + Author: { + active: true, + }, + }, + }); + + const reject = await prisma.projectCollaboration.count({ + where: { + isActive: false, + isReject: true, + Author: { + active: true, + }, + }, + }); + + const group = await prisma.projectCollaboration_RoomChat.count({ + where: { + isActive: true, + }, + }); + + fixData = { + publish: publish, + reject: reject, + group: group, + }; + } else if (category === "publish") { + fixData = await prisma.projectCollaboration.findMany({ + orderBy: { + createdAt: "desc", + }, + where: { + isActive: true, + isReject: false, + Author: { + active: true, + }, + }, + select: { + id: true, + createdAt: true, + isActive: true, + title: true, + Author: { + select: { + id: true, + username: true, + Profile: true, + }, + }, + projectCollaborationMaster_IndustriId: true, + ProjectCollaborationMaster_Industri: true, + ProjectCollaboration_Partisipasi: { + where: { + User: { + active: true, + }, + }, + // select: { + // User: { + // select: { + // id: true, + // username: true, + // Profile: true, + // }, + // }, + // }, + }, + }, + }); + } else if (category === "reject") { + fixData = await prisma.projectCollaboration.findMany({ + orderBy: { + createdAt: "desc", + }, + where: { + isActive: false, + isReject: true, + Author: { + active: true, + }, + }, + select: { + id: true, + createdAt: true, + isActive: true, + title: true, + Author: { + select: { + id: true, + username: true, + Profile: true, + }, + }, + projectCollaborationMaster_IndustriId: true, + ProjectCollaborationMaster_Industri: true, + ProjectCollaboration_Partisipasi: { + where: { + User: { + active: true, + }, + }, + // select: { + // User: { + // select: { + // id: true, + // username: true, + // Profile: true, + // }, + // }, + // }, + }, + }, + }); + } else if (category === "group") { + fixData = await prisma.projectCollaboration_RoomChat.findMany({ + orderBy: { + createdAt: "desc", + }, + where: { + isActive: true, + }, + select: { + id: true, + createdAt: true, + isActive: true, + name: true, + ProjectCollaboration_AnggotaRoomChat: { + select: { + User: { + select: { + id: true, + Profile: true, + }, + }, + }, + }, + ProjectCollaboration: { + select: { + id: true, + isActive: true, + title: true, + lokasi: true, + purpose: true, + benefit: true, + createdAt: true, + report: true, + Author: { + select: { + id: true, + Profile: { + select: { + name: true, + }, + }, + }, + }, + ProjectCollaborationMaster_Industri: true, + }, + }, + }, + }); + } + + return NextResponse.json( + { + success: true, + message: "Success get data collaboration", + data: fixData, + }, + { status: 200 } + ); + } catch (error) { + return NextResponse.json( + { + success: false, + message: "Error get data collaboration", + reason: (error as Error).message, + }, + { status: 500 } + ); + } +}