rev: hapus kegiatan

Deskripsi:
- hapus data pada saat status batal pada fitur kegiatan dan tugas divisi

No Issues
This commit is contained in:
amel
2025-02-04 17:19:17 +08:00
parent bcd9e98518
commit 6836ea9f09
8 changed files with 262 additions and 48 deletions

View File

@@ -0,0 +1,48 @@
import { prisma } from "@/module/_global";
import { funGetUserByCookies } from "@/module/auth";
import { createLogUser } from "@/module/user";
import { NextResponse } from "next/server";
// PEMBATALAN TASK DIVISI
export async function DELETE(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 data = await prisma.divisionProject.count({
where: {
id: id,
},
});
if (data == 0) {
return NextResponse.json(
{
success: false,
message: "Penghapusan tugas gagal, data tugas tidak ditemukan",
},
{ status: 404 }
);
}
const update = await prisma.divisionProject.update({
where: {
id
},
data: {
isActive: false,
}
});
// create log user
const log = await createLogUser({ act: 'DELETE', desc: 'User menghapus tugas divisi', table: 'divisionProject', data: id })
return NextResponse.json({ success: true, message: "Tugas berhasil dihapuskan", }, { status: 200 });
} catch (error) {
console.error(error);
return NextResponse.json({ success: false, message: "Gagal menghapus tugas, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
}
}