upd: project dan task

Deskripsi:
- tambah project
- perbaiki task

No Issues
This commit is contained in:
amel
2024-08-23 18:10:11 +08:00
parent df2f61e833
commit 5b05edaf38
14 changed files with 163 additions and 115 deletions

View File

@@ -12,6 +12,8 @@ export async function DELETE(request: Request, context: { params: { id: string }
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
}
const { id } = context.params;
const { idProject } = (await request.json());
const data = await prisma.projectTask.count({
where: {
id: id,
@@ -37,6 +39,35 @@ export async function DELETE(request: Request, context: { params: { id: string }
},
});
const dataTask = await prisma.projectTask.findMany({
where: {
isActive: true,
idProject: idProject,
}
})
const semua = dataTask.length
const selesai = dataTask.filter((item) => item.status == 1).length
const prosess = Math.ceil((selesai / semua) * 100)
let statusProject = 1
if (prosess == 100) {
statusProject = 2
} else if (prosess == 0) {
statusProject = 0
}
const updProject = await prisma.project.update({
where: {
id: idProject
},
data: {
status: statusProject
}
})
return NextResponse.json(
{
success: true,
@@ -87,6 +118,8 @@ export async function PUT(request: Request, context: { params: { id: string } })
}
})
// const cek progress
const dataTask = await prisma.projectTask.findMany({
where: {
isActive: true,