diff --git a/src/app/api/mobile/project/[id]/lainnya/route.ts b/src/app/api/mobile/project/[id]/lainnya/route.ts index d6a8260..48de186 100644 --- a/src/app/api/mobile/project/[id]/lainnya/route.ts +++ b/src/app/api/mobile/project/[id]/lainnya/route.ts @@ -47,4 +47,51 @@ export async function DELETE(request: Request, context: { params: { id: string } console.error(error); return NextResponse.json({ success: false, message: "Gagal menghapus kegiatan, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } +} + +// EDIT PROJECT REPORT +export async function PUT(request: Request, context: { params: { id: string } }) { + try { + const { id } = context.params + const { report, user } = await request.json() + + const userMobile = await funGetUserById({ id: String(user) }) + + if (userMobile.id == "null" || userMobile.id == undefined || userMobile.id == "") { + return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 200 }); + } + + const data = await prisma.project.count({ + where: { + id: id + } + }) + + if (data == 0) { + return NextResponse.json( + { + success: false, message: "Gagal mendapatkan kegiatan, data tidak ditemukan", + }, + { status: 200 } + ); + } + + const dataCreate = await prisma.project.update({ + where: { + id + }, + data: { + report: report + } + }) + + // create log user + const log = await createLogUserMobile({ act: 'UPDATE', desc: 'User mengupdate laporan kegiatan', table: 'project', data: String(id), user: userMobile.id }) + + return NextResponse.json({ success: true, message: "Laporan kegiatan berhasil diupdate" }, { status: 200 }); + + } catch (error) { + console.error(error); + return NextResponse.json({ success: false, message: "Gagal mengupdate kegiatan, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); + } } \ No newline at end of file diff --git a/src/app/api/mobile/task/[id]/lainnya/route.ts b/src/app/api/mobile/task/[id]/lainnya/route.ts index 4dc98e5..ef33d75 100644 --- a/src/app/api/mobile/task/[id]/lainnya/route.ts +++ b/src/app/api/mobile/task/[id]/lainnya/route.ts @@ -46,4 +46,51 @@ export async function DELETE(request: Request, context: { params: { id: string } console.error(error); return NextResponse.json({ success: false, message: "Gagal menghapus tugas, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } +} + +// EDIT TASK REPORT +export async function PUT(request: Request, context: { params: { id: string } }) { + try { + const { id } = context.params + const { report, user } = await request.json() + + const userMobile = await funGetUserById({ id: String(user) }) + if (userMobile.id == "null" || userMobile.id == undefined || userMobile.id == "") { + return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 200 }); + } + + + const data = await prisma.divisionProject.count({ + where: { + id: id + } + }) + + if (data == 0) { + return NextResponse.json( + { + success: false, message: "Gagal mendapatkan kegiatan, data tidak ditemukan", + }, + { status: 200 } + ); + } + + const dataCreate = await prisma.divisionProject.update({ + where: { + id + }, + data: { + report: report + } + }) + + // create log user + const log = await createLogUserMobile({ act: 'UPDATE', desc: 'User mengupdate laporan tugas divisi', table: 'divisionProject', data: String(id), user: userMobile.id }) + + return NextResponse.json({ success: true, message: "Laporan tugas divisi berhasil diupdate" }, { status: 200 }); + + } catch (error) { + console.error(error); + return NextResponse.json({ success: false, message: "Gagal mengupdate laporan tugas divisi, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); + } } \ No newline at end of file