Mobile: Api Collaboration

Add:
- /mobile/collaboration/

Fix:
- mobile/voting: POST Method

### No Issue
This commit is contained in:
2025-09-22 17:41:30 +08:00
parent 26723499b4
commit 28ce7579cd
5 changed files with 328 additions and 2 deletions

View File

@@ -0,0 +1,123 @@
import { NextResponse } from "next/server";
import prisma from "@/lib/prisma";
export async function POST(
request: Request,
{ params }: { params: { id: string } }
) {
const { id } = params;
const { data } = await request.json();
console.log("[id]", id);
console.log("[data]", data);
try {
const create = await prisma.projectCollaboration_Partisipasi.create({
data: {
projectCollaborationId: id,
userId: data.authorId,
deskripsi_diri: data.description,
},
select: {
ProjectCollaboration: {
select: {
id: true,
title: true,
userId: true,
},
},
},
});
return NextResponse.json(
{
success: true,
message: "Berhasil menambahkan partisipan",
// data: create,
},
{ status: 201 }
);
} catch (error) {
return NextResponse.json(
{
success: false,
message: "Error menambahkan partisipan",
reason: (error as Error).message,
},
{ status: 500 }
);
}
}
export async function GET(
request: Request,
{ params }: { params: { id: string } }
) {
let fixData;
const { id } = params;
const { searchParams } = new URL(request.url);
const authorId = searchParams.get("authorId");
const category = searchParams.get("category");
try {
if (category === "list") {
const data = await prisma.projectCollaboration_Partisipasi.findMany({
where: {
projectCollaborationId: id,
},
select: {
id: true,
deskripsi_diri: true,
User: {
select: {
id: true,
username: true,
Profile: {
select: {
id: true,
name: true,
imageId: true,
},
},
},
},
},
});
fixData = data;
} else if (category === "check-participant") {
const cek = await prisma.projectCollaboration_Partisipasi.count({
where: {
projectCollaborationId: id,
userId: authorId,
},
});
console.log("[CEK]", cek);
if (cek === 0) {
fixData = false;
} else {
fixData = true;
}
}
return NextResponse.json(
{
success: true,
message: "Berhasil mendapatkan data partisipan",
data: fixData,
},
{ status: 200 }
);
} catch (error) {
return NextResponse.json(
{
success: false,
message: "Error mendapatkan data partisipan",
reason: (error as Error).message,
},
{ status: 500 }
);
}
}

View File

@@ -0,0 +1,69 @@
import { prisma } from "@/lib";
import { NextResponse } from "next/server";
export async function GET(
request: Request,
{ params }: { params: { id: string } }
) {
let fixData;
const { id } = params;
try {
fixData = await prisma.projectCollaboration.findFirst({
where: {
id: id,
},
select: {
id: true,
isActive: true,
title: true,
lokasi: true,
purpose: true,
benefit: true,
createdAt: true,
Author: {
select: {
id: true,
username: true,
Profile: {
select: {
id: true,
name: true,
imageId: true,
},
},
},
},
ProjectCollaborationMaster_Industri: {
select: {
name: true,
},
},
ProjectCollaboration_Partisipasi: {
where: {
isActive: true,
},
},
},
});
return NextResponse.json(
{
success: true,
message: "Berhasil Mendapatkan Data",
data: fixData,
},
{ status: 200 }
);
} catch (error) {
console.log("[ERROR]", error);
return NextResponse.json(
{
success: false,
message: "Gagal Mendapatkan Data",
reason: (error as Error).message || error,
},
{ status: 500 }
);
}
}

View File

@@ -0,0 +1,100 @@
import _ from "lodash";
import { NextResponse } from "next/server";
import prisma from "@/lib/prisma";
export { POST, GET };
async function POST(request: Request) {
const { data } = await request.json();
console.log("[DATA]", data);
try {
const create = await prisma.projectCollaboration.create({
data: {
title: data?.title || "",
lokasi: data?.lokasi || "",
purpose: data?.purpose || "",
benefit: data?.benefit || "",
projectCollaborationMaster_IndustriId:
data?.projectCollaborationMaster_IndustriId || "",
userId: data?.userId || "",
},
});
return NextResponse.json({
success: true,
message: "Berhasil Membuat Proyek",
});
} catch (error) {
console.log("[ERROR]", error);
return NextResponse.json(
{
success: false,
message: "Gagal Membuat Proyek",
reason: (error as Error).message || error,
},
{ status: 500 }
);
}
}
async function GET(request: Request) {
let fixData;
try {
fixData = await prisma.projectCollaboration.findMany({
orderBy: {
createdAt: "desc",
},
where: {
projectCollaborationMaster_StatusId: 1,
isActive: true,
},
select: {
id: true,
isActive: true,
title: true,
lokasi: true,
purpose: true,
benefit: true,
Author: {
select: {
id: true,
username: true,
Profile: {
select: {
id: true,
name: true,
imageId: true,
},
},
},
},
ProjectCollaborationMaster_Industri: true,
ProjectCollaboration_Partisipasi: {
where: {
isActive: true,
},
},
},
});
return NextResponse.json(
{
success: true,
message: "Berhasil Mendapatkan Data",
data: fixData,
},
{ status: 200 }
);
} catch (error) {
console.log("[ERROR]", error);
return NextResponse.json(
{
success: false,
message: "Gagal Mendapatkan Data",
reason: (error as Error).message || error,
},
{ status: 500 }
);
}
}

View File

@@ -0,0 +1,26 @@
import { NextResponse } from "next/server";
import { prisma } from "@/lib";
export { GET };
async function GET(request: Request) {
try {
const data = await prisma.projectCollaborationMaster_Industri.findMany({
orderBy: {
id: "asc",
},
});
return NextResponse.json(
{ success: true, message: "Berhasil mendapatkan data", data: data },
{ status: 200 }
);
} catch (error) {
console.log("[ERROR]", error);
return NextResponse.json(
{ success: false, message: "Gagal mendapatkan data" },
{ status: 500 }
);
}
}

View File

@@ -18,7 +18,11 @@ async function POST(request: Request) {
},
});
if (!create) return { status: 400, message: "Gagal Membuat Vote" };
if (!create)
return NextResponse.json({
status: 400,
message: "Gagal Membuat Vote",
});
for (let v of data.listVote) {
const val = v.value;
@@ -30,7 +34,11 @@ async function POST(request: Request) {
},
});
if (!namaVote) return { status: 400, message: "Gagal Membuat List" };
if (!namaVote)
return NextResponse.json({
status: 400,
message: "Gagal Membuat List",
});
}
return NextResponse.json(