Merge pull request 'Mobil API Collaboration' (#21) from mobile/23-sep-25 into staging
Reviewed-on: bip/hipmi#21
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
|
||||
|
||||
## [1.4.41](https://wibugit.wibudev.com/bip/hipmi/compare/v1.4.40...v1.4.41) (2025-09-23)
|
||||
|
||||
## [1.4.40](https://wibugit.wibudev.com/bip/hipmi/compare/v1.4.39...v1.4.40) (2025-09-22)
|
||||
|
||||
## [1.4.39](https://wibugit.wibudev.com/bip/hipmi/compare/v1.4.38...v1.4.39) (2025-09-19)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hipmi",
|
||||
"version": "1.4.40",
|
||||
"version": "1.4.41",
|
||||
"private": true,
|
||||
"prisma": {
|
||||
"seed": "bun prisma/seed.ts"
|
||||
|
||||
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 { NextResponse } from "next/server";
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: { id: string } }
|
||||
) {
|
||||
export { GET, POST, PUT };
|
||||
async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||
let fixData;
|
||||
const { id } = params;
|
||||
|
||||
@@ -21,6 +19,7 @@ export async function GET(
|
||||
purpose: true,
|
||||
benefit: true,
|
||||
createdAt: true,
|
||||
projectCollaborationMaster_IndustriId: true,
|
||||
Author: {
|
||||
select: {
|
||||
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) {
|
||||
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 {
|
||||
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,
|
||||
if (category === "beranda") {
|
||||
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,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
} 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: {
|
||||
where: {
|
||||
isActive: true,
|
||||
});
|
||||
} else if (category === "my-project") {
|
||||
fixData = await prisma.projectCollaboration.findMany({
|
||||
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(
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user