Mobile: API Collaboration
Add: - api/mobile/collaboration/[id]/group Fix: - api/mobile/collaboration/route - api/mobile/collaboration/[id]/route ### No Isuue
This commit is contained in:
69
src/app/api/mobile/collaboration/[id]/group/route.ts
Normal file
69
src/app/api/mobile/collaboration/[id]/group/route.ts
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
import prisma from "@/lib/prisma";
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
|
||||||
|
export { GET };
|
||||||
|
|
||||||
|
async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||||
|
let fixData;
|
||||||
|
const { id } = params;
|
||||||
|
|
||||||
|
try {
|
||||||
|
fixData = await prisma.projectCollaboration_RoomChat.findFirst({
|
||||||
|
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,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
ProjectCollaboration_AnggotaRoomChat: {
|
||||||
|
select: {
|
||||||
|
User: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
username: true,
|
||||||
|
Profile: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
name: true,
|
||||||
|
imageId: 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 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,8 @@
|
|||||||
import { prisma } from "@/lib";
|
import { prisma } from "@/lib";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
|
|
||||||
export async function GET(
|
export { GET, POST, PUT };
|
||||||
request: Request,
|
async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||||
{ params }: { params: { id: string } }
|
|
||||||
) {
|
|
||||||
let fixData;
|
let fixData;
|
||||||
const { id } = params;
|
const { id } = params;
|
||||||
|
|
||||||
@@ -21,6 +19,7 @@ export async function GET(
|
|||||||
purpose: true,
|
purpose: true,
|
||||||
benefit: true,
|
benefit: true,
|
||||||
createdAt: true,
|
createdAt: true,
|
||||||
|
projectCollaborationMaster_IndustriId: true,
|
||||||
Author: {
|
Author: {
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
@@ -67,3 +66,158 @@ export async function GET(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Buat grup
|
||||||
|
async function POST(request: Request, { params }: { params: { id: string } }) {
|
||||||
|
const { id } = params;
|
||||||
|
const { data } = await request.json();
|
||||||
|
|
||||||
|
// NEED : authorId, listSelected, nameGroup
|
||||||
|
|
||||||
|
console.log("[ID]", id);
|
||||||
|
console.log("[DATA]", data);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const createRoom = await prisma.projectCollaboration_RoomChat.create({
|
||||||
|
data: {
|
||||||
|
name: data.nameGroup,
|
||||||
|
userId: data.authorId,
|
||||||
|
projectCollaborationId: id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!createRoom) {
|
||||||
|
return NextResponse.json({
|
||||||
|
status: 400,
|
||||||
|
success: false,
|
||||||
|
message: "Gagal Membuat Room",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let v of data.listSelect) {
|
||||||
|
console.log("[LIST SELECTED]", v);
|
||||||
|
const createAnggota =
|
||||||
|
await prisma.projectCollaboration_AnggotaRoomChat.create({
|
||||||
|
data: {
|
||||||
|
userId: v,
|
||||||
|
projectCollaboration_RoomChatId: createRoom.id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!createAnggota)
|
||||||
|
return NextResponse.json({
|
||||||
|
status: 400,
|
||||||
|
success: false,
|
||||||
|
message: "Gagal Menambah Anggota",
|
||||||
|
});
|
||||||
|
|
||||||
|
// const createdNotifikasi = await prisma.notifikasi.create({
|
||||||
|
// data: {
|
||||||
|
// userId: v,
|
||||||
|
// appId: createRoom.id,
|
||||||
|
// status: "Collaboration Group",
|
||||||
|
// title: "Grup Kolaborasi Baru",
|
||||||
|
// pesan: createRoom.name,
|
||||||
|
// kategoriApp: "COLLABORATION",
|
||||||
|
// userRoleId: "1",
|
||||||
|
// },
|
||||||
|
// });
|
||||||
|
// if (!createdNotifikasi)
|
||||||
|
// return { status: 400, message: "Gagal mengirim notifikasi" };
|
||||||
|
}
|
||||||
|
|
||||||
|
const createForAuthor =
|
||||||
|
await prisma.projectCollaboration_AnggotaRoomChat.create({
|
||||||
|
data: {
|
||||||
|
userId: data.authorId,
|
||||||
|
projectCollaboration_RoomChatId: createRoom.id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!createForAuthor)
|
||||||
|
return NextResponse.json({
|
||||||
|
status: 400,
|
||||||
|
success: false,
|
||||||
|
message: "Gagal Menambahkan Author",
|
||||||
|
});
|
||||||
|
|
||||||
|
const hideProyek = await prisma.projectCollaboration.update({
|
||||||
|
where: {
|
||||||
|
id: id,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
isActive: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!hideProyek)
|
||||||
|
return NextResponse.json({
|
||||||
|
status: 400,
|
||||||
|
success: false,
|
||||||
|
message: "Gagal Menyimpan Proyek",
|
||||||
|
});
|
||||||
|
|
||||||
|
return NextResponse.json({
|
||||||
|
status: 201,
|
||||||
|
success: true,
|
||||||
|
message: "Berhasil Membuat Room",
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.log("[ERROR]", error);
|
||||||
|
return NextResponse.json(
|
||||||
|
{
|
||||||
|
success: false,
|
||||||
|
message: "Gagal Membuat Room",
|
||||||
|
reason: (error as Error).message || error,
|
||||||
|
},
|
||||||
|
{ status: 500 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function PUT(request: Request, { params }: { params: { id: string } }) {
|
||||||
|
const { id } = params;
|
||||||
|
const { data } = await request.json();
|
||||||
|
|
||||||
|
console.log("[ID]", id);
|
||||||
|
console.log("[DATA]", data);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const updt = await prisma.projectCollaboration.update({
|
||||||
|
where: {
|
||||||
|
id: id,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
title: data.title,
|
||||||
|
lokasi: data.lokasi,
|
||||||
|
purpose: data.purpose,
|
||||||
|
benefit: data.benefit,
|
||||||
|
projectCollaborationMaster_IndustriId:
|
||||||
|
data.projectCollaborationMaster_IndustriId as any,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!updt)
|
||||||
|
return NextResponse.json({
|
||||||
|
status: 400,
|
||||||
|
success: false,
|
||||||
|
message: "Update gagal",
|
||||||
|
});
|
||||||
|
|
||||||
|
return NextResponse.json({
|
||||||
|
status: 200,
|
||||||
|
success: true,
|
||||||
|
message: "Update berhasil",
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.log("[ERROR]", error);
|
||||||
|
return NextResponse.json(
|
||||||
|
{
|
||||||
|
success: false,
|
||||||
|
message: "Update data error",
|
||||||
|
reason: (error as Error).message || error,
|
||||||
|
},
|
||||||
|
{ status: 500 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -40,43 +40,142 @@ async function POST(request: Request) {
|
|||||||
|
|
||||||
async function GET(request: Request) {
|
async function GET(request: Request) {
|
||||||
let fixData;
|
let fixData;
|
||||||
|
const { searchParams } = new URL(request.url);
|
||||||
|
const category = searchParams.get("category");
|
||||||
|
const authorId = searchParams.get("authorId");
|
||||||
|
|
||||||
|
console.log("[CATEGORY]", category);
|
||||||
|
console.log("[AUTHOR_ID]", authorId);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fixData = await prisma.projectCollaboration.findMany({
|
if (category === "beranda") {
|
||||||
orderBy: {
|
fixData = await prisma.projectCollaboration.findMany({
|
||||||
createdAt: "desc",
|
orderBy: {
|
||||||
},
|
createdAt: "desc",
|
||||||
where: {
|
},
|
||||||
projectCollaborationMaster_StatusId: 1,
|
where: {
|
||||||
isActive: true,
|
projectCollaborationMaster_StatusId: 1,
|
||||||
},
|
isActive: true,
|
||||||
select: {
|
},
|
||||||
id: true,
|
select: {
|
||||||
isActive: true,
|
id: true,
|
||||||
title: true,
|
isActive: true,
|
||||||
lokasi: true,
|
title: true,
|
||||||
purpose: true,
|
lokasi: true,
|
||||||
benefit: true,
|
purpose: true,
|
||||||
Author: {
|
benefit: true,
|
||||||
select: {
|
Author: {
|
||||||
id: true,
|
select: {
|
||||||
username: true,
|
id: true,
|
||||||
Profile: {
|
username: true,
|
||||||
select: {
|
Profile: {
|
||||||
id: true,
|
select: {
|
||||||
name: true,
|
id: true,
|
||||||
imageId: true,
|
name: true,
|
||||||
|
imageId: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
ProjectCollaborationMaster_Industri: true,
|
||||||
|
ProjectCollaboration_Partisipasi: {
|
||||||
|
where: {
|
||||||
|
isActive: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} else if (category === "participant") {
|
||||||
|
fixData = await prisma.projectCollaboration_Partisipasi.findMany({
|
||||||
|
orderBy: {
|
||||||
|
createdAt: "desc",
|
||||||
|
},
|
||||||
|
where: {
|
||||||
|
userId: authorId,
|
||||||
|
isActive: true,
|
||||||
|
AND: {
|
||||||
|
ProjectCollaboration: {
|
||||||
|
isActive: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
isActive: true,
|
||||||
|
ProjectCollaboration: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
isActive: true,
|
||||||
|
title: true,
|
||||||
|
lokasi: true,
|
||||||
|
purpose: true,
|
||||||
|
benefit: true,
|
||||||
|
Author: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
Profile: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
ProjectCollaborationMaster_Industri: true,
|
||||||
|
ProjectCollaboration_Partisipasi: {
|
||||||
|
where: {
|
||||||
|
isActive: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
ProjectCollaborationMaster_Industri: true,
|
});
|
||||||
ProjectCollaboration_Partisipasi: {
|
} else if (category === "my-project") {
|
||||||
where: {
|
fixData = await prisma.projectCollaboration.findMany({
|
||||||
isActive: true,
|
orderBy: { createdAt: "desc" },
|
||||||
|
where: { userId: authorId, isActive: true },
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
isActive: true,
|
||||||
|
title: true,
|
||||||
|
lokasi: true,
|
||||||
|
purpose: true,
|
||||||
|
benefit: true,
|
||||||
|
// jumlah_partisipan: true,
|
||||||
|
Author: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
Profile: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
ProjectCollaborationMaster_Industri: true,
|
||||||
|
ProjectCollaboration_Partisipasi: {
|
||||||
|
where: {
|
||||||
|
isActive: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
});
|
||||||
});
|
} else if (category === "group") {
|
||||||
|
fixData = await prisma.projectCollaboration_AnggotaRoomChat.findMany({
|
||||||
|
orderBy: {
|
||||||
|
createdAt: "desc",
|
||||||
|
},
|
||||||
|
where: {
|
||||||
|
userId: authorId as any,
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
ProjectCollaboration_RoomChat: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
name: true,
|
||||||
|
isActive: true,
|
||||||
|
ProjectCollaboration_AnggotaRoomChat: {
|
||||||
|
select: {
|
||||||
|
User: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user