feat : update project

This commit is contained in:
lukman
2024-08-22 15:22:29 +08:00
parent 0c2694e9dc
commit 7c78d97427
26 changed files with 1526 additions and 131 deletions

View File

@@ -61,7 +61,7 @@ export async function DELETE(request: Request, context: { params: { id: string }
const { id } = context.params
const { idUser } = (await request.json());
const data = await prisma.divisionProject.count({
const data = await prisma.project.count({
where: {
id: id,
},
@@ -91,4 +91,94 @@ export async function DELETE(request: Request, context: { params: { id: string }
console.error(error);
return NextResponse.json({ success: false, message: "Gagal mengeluarkan anggota project, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
}
}
//GET MEMBER ALL USER ID GROUP
export async function GET(request: Request, context: { params: { id: string } }) {
try {
const user = await funGetUserByCookies()
if (user.id == undefined) {
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
}
const { id } = context.params
const groupId = user.idGroup
const userId = user.id
const data = await prisma.project.findUnique({
where: {
id: String(id),
isActive: true
}
})
if (data == null) {
return NextResponse.json(
{
success: false,
message: "Gagal, data tugas tidak ditemukan",
},
{ status: 404 }
);
}
// const member = await prisma.projectMember.findMany({
// where: {
// idProject: String(id),
// isActive: true
// },
// select: {
// id: true,
// isLeader: true,
// idUser: true,
// User: {
// select: {
// name: true
// }
// }
// },
// orderBy: {
// isLeader: 'desc',
// }
// })
// const fixMember = member.map((v: any) => ({
// ..._.omit(v, ["User"]),
// name: v.User.name
// }))
const member = await prisma.user.findMany({
where: {
idGroup: String(groupId),
id: {
not: String(userId)
},
isActive: true
},
select: {
id: true,
name: true,
email: true,
}
})
const fixMember = member.map((v: any) => ({
idUser: v.id,
name: v.name,
email: v.email,
}))
const dataFix = {
project: data,
member: fixMember
}
return NextResponse.json({ success: true, message: "Berhasil mendapatkan project", data: dataFix, }, { status: 200 });
} catch (error) {
console.error(error);
return NextResponse.json({ success: false, message: "Gagal mendapatkan project, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
}
}